Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
benisgold committed Nov 15, 2024
1 parent bede077 commit 7dbe664
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/raps/actions/crosschainSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const crosschainSwap = async ({
gasFeeParamsBySpeed,
}: ActionProps<'crosschainSwap'>): Promise<RapActionResult> => {
const { quote, chainId, requiresApprove } = parameters;
throw new RainbowError('[raps/crosschainSwap]: error executeCrosschainSwap');

let gasParamsToUse = gasParams;
if (currentRap.actions.length - 1 > index) {
gasParamsToUse = overrideWithFastSpeedIfNeeded({
Expand Down
2 changes: 1 addition & 1 deletion src/screens/claimables/shared/components/ClaimPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IS_IOS } from '@/env';
import { safeAreaInsetValues } from '@/utils';
import React from 'react';
import { ClaimPanelHeader } from './ClaimPanelHeader';
import { ClaimStatus } from '../../transaction/types';
import { ClaimStatus } from '../../shared/types';

export function ClaimPanel({ children, claimStatus, iconUrl }: { children: React.ReactNode; claimStatus: ClaimStatus; iconUrl: string }) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FasterImageView } from '@candlefinance/faster-image';
import React, { useMemo } from 'react';
import * as i18n from '@/languages';
import { TextColor } from '@/design-system/color/palettes';
import { ClaimStatus } from '../../transaction/types';
import { ClaimStatus } from '../../shared/types';

export function ClaimPanelHeader({ claimStatus, iconUrl }: { claimStatus: ClaimStatus; iconUrl: string }) {
const panelTitle = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export type ClaimStatus =
| 'notReady' // preparing the data necessary to claim
| 'ready' // ready to claim state
| 'claiming' // user has pressed the claim button
| 'pending' // claim has been submitted but we don't have a tx hash
| 'success' // claim has been submitted and we have a tx hash
| 'error'; // claim has failed
| 'recoverableError' // claim or auth has failed, can try again
| 'unrecoverableError'; // swap has failed, unrecoverable error
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function SponsoredClaimableFlow() {
case 'pending':
case 'success':
return i18n.t(i18n.l.button.done);
case 'error':
case 'recoverableError':
default:
return i18n.t(i18n.l.points.points.try_again);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { createContext, Dispatch, SetStateAction, useContext, useState } from 'react';
import { ClaimStatus } from '../types';
import { Claimable, ClaimResponse, SponsoredClaimable } from '@/resources/addys/claimables/types';
import { logger, RainbowError } from '@/logger';
import { useAccountSettings } from '@/hooks';
Expand All @@ -9,6 +8,7 @@ import { queryClient } from '@/react-query';
import { ADDYS_BASE_URL, addysHttp, claimablesQueryKey } from '@/resources/addys/claimables/query';
import { useMutation } from '@tanstack/react-query';
import { loadWallet } from '@/model/wallet';
import { ClaimStatus } from '../../shared/types';

type SponsoredClaimableContextType = {
claimStatus: ClaimStatus;
Expand Down Expand Up @@ -48,7 +48,7 @@ export function SponsoredClaimableContextProvider({ claimable, children }: { cla
if (!wallet) {
// Biometrics auth failure (retry possible)
haptics.notificationError();
setClaimStatus('error');
setClaimStatus('recoverableError');
return;
}

Expand All @@ -60,7 +60,7 @@ export function SponsoredClaimableContextProvider({ claimable, children }: { cla
response = await addysHttp.get(path);
} catch (e) {
haptics.notificationError();
setClaimStatus('error');
setClaimStatus('recoverableError');
logger.error(new RainbowError('[ClaimSponsoredClaimable]: failed to execute sponsored claim api call'));
return;
}
Expand All @@ -69,15 +69,15 @@ export function SponsoredClaimableContextProvider({ claimable, children }: { cla
response = await addysHttp.post(path);
} catch (e) {
haptics.notificationError();
setClaimStatus('error');
setClaimStatus('recoverableError');
logger.error(new RainbowError('[ClaimSponsoredClaimable]: failed to execute sponsored claim api call'));
return;
}
}

if (!response.data.payload.success) {
haptics.notificationError();
setClaimStatus('error');
setClaimStatus('recoverableError');
logger.error(new RainbowError('[ClaimSponsoredClaimable]: sponsored claim api call returned unsuccessful response'));
} else {
haptics.notificationSuccess();
Expand All @@ -94,15 +94,15 @@ export function SponsoredClaimableContextProvider({ claimable, children }: { cla
},
onError: e => {
haptics.notificationError();
setClaimStatus('error');
setClaimStatus('recoverableError');
logger.error(new RainbowError('[ClaimingSponsoredClaimable]: Failed to claim claimable due to unhandled error'), {
message: (e as Error)?.message,
});
},
onSuccess: () => {
if (claimStatus === 'claiming') {
haptics.notificationError();
setClaimStatus('error');
setClaimStatus('recoverableError');
logger.error(
new RainbowError('[ClaimingSponsoredClaimable]: claim function completed but never resolved status to success or error state')
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Dispatch, SetStateAction, createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
import { ChainId } from '@/chains/types';
import { ClaimStatus, TokenToReceive, TransactionClaimableTxPayload } from '../types';
import { TokenToReceive, TransactionClaimableTxPayload } from '../types';
import { CrosschainQuote, ETH_ADDRESS, getCrosschainQuote, getQuote, Quote, QuoteParams } from '@rainbow-me/swaps';
import { Claimable, TransactionClaimable } from '@/resources/addys/claimables/types';
import { logger, RainbowError } from '@/logger';
Expand All @@ -10,6 +10,12 @@ import {
convertAmountToRawAmount,
convertRawAmountToBalance,
convertAmountToBalanceDisplay,
convertRawAmountToDecimalFormat,
multiply,
add,
divide,
formatNumber,
convertAmountToNativeDisplayWorklet,
} from '@/helpers/utilities';
import { useUserNativeNetworkAsset } from '@/resources/assets/useUserAsset';
import { GasSpeed } from '@/__swaps__/types/gas';
Expand All @@ -23,16 +29,6 @@ import { LegacyTransactionGasParamAmounts, TransactionGasParamAmounts } from '@/
import { getNextNonce } from '@/state/nonces';
import { estimateGasWithPadding, getProvider } from '@/handlers/web3';
import { calculateGasFeeWorklet } from '@/__swaps__/screens/Swap/providers/SyncSwapStateAndSharedValues';
import {
add,
convertAmountToNativeDisplayWorklet,
convertRawAmountToDecimalFormat,
divide,
formatNumber,
multiply,
} from '@/__swaps__/utils/numbers';
import { lessThanOrEqualToWorklet } from '@/__swaps__/safe-math/SafeMath';
import { weiToGwei } from '@/__swaps__/utils/ethereum';
import { formatUnits } from 'viem';
import { safeBigInt } from '@/__swaps__/screens/Swap/hooks/useEstimatedGasFee';
import { haptics } from '@/utils';
Expand All @@ -44,6 +40,9 @@ import { externalTokenQueryKey, fetchExternalToken, FormattedExternalAsset } fro
import { walletExecuteRap } from '@/raps/execute';
import { executeClaim } from '../claim';
import { ParsedSearchAsset } from '@/__swaps__/types/assets';
import { weiToGwei } from '@/parsers';
import { lessThanOrEqualToWorklet } from '@/safe-math/SafeMath';
import { ClaimStatus } from '../../shared/types';

interface OutputConfig {
token?: TokenToReceive;
Expand Down Expand Up @@ -126,6 +125,8 @@ export function TransactionClaimableContextProvider({
},
});

const outputTokenAddress = outputConfig.chainId ? outputConfig.token?.networks[outputConfig.chainId]?.address : undefined;

const requiresSwap = outputConfig.token?.symbol !== claimable.asset.symbol || outputConfig.chainId !== claimable.chainId;

const { data: tokenSearchData, isFetching: isFetchingOutputToken } = useTokenSearch(
Expand All @@ -134,17 +135,14 @@ export function TransactionClaimableContextProvider({
keys: ['address'],
list: 'verifiedAssets',
threshold: 'CASE_SENSITIVE_EQUAL',
query: outputConfig.chainId ? outputConfig.token?.networks[outputConfig.chainId]?.address : undefined,
query: outputTokenAddress,
},
{
enabled: requiresSwap,
select: data => {
return data.filter(
(asset: SearchAsset) =>
outputConfig.chainId &&
asset.address === outputConfig.token?.networks[outputConfig.chainId]?.address &&
asset.chainId === outputConfig.chainId &&
asset.symbol === outputConfig.token?.symbol
asset.address === outputTokenAddress && asset.chainId === outputConfig.chainId && asset.symbol === outputConfig.token?.symbol
);
},
}
Expand Down Expand Up @@ -180,7 +178,7 @@ export function TransactionClaimableContextProvider({
chainId: claimable.chainId,
fromAddress: accountAddress,
sellTokenAddress: claimable.asset.isNativeAsset ? ETH_ADDRESS : claimable.asset.address,
buyTokenAddress: tokenToClaim.isNativeAsset ? ETH_ADDRESS : tokenToClaim.networks[tokenToClaim.chainId]?.address, // thjis si thi problem
buyTokenAddress: tokenToClaim.isNativeAsset ? ETH_ADDRESS : (tokenToClaim.networks[tokenToClaim.chainId]?.address as string),
sellAmount: convertAmountToRawAmount(0.0001, claimable.asset.decimals),
slippage: 0.5,
refuel: false,
Expand All @@ -200,7 +198,7 @@ export function TransactionClaimableContextProvider({
}
setQuoteState({ quote: undefined, nativeValueDisplay: undefined, tokenAmountDisplay: undefined, status });
} else {
const buyAmount = convertRawAmountToDecimalFormat(quote.buyAmountMinusFees, tokenToClaim.decimals);
const buyAmount = convertRawAmountToDecimalFormat(quote.buyAmountMinusFees.toString(), tokenToClaim.decimals);
const buyAmountDisplay = convertAmountToBalanceDisplay(
buyAmount,
{ decimals: tokenToClaim.decimals, symbol: tokenToClaim.symbol },
Expand Down Expand Up @@ -410,7 +408,13 @@ export function TransactionClaimableContextProvider({

const { mutate: claim } = useMutation({
mutationFn: async () => {
if (!txState.txPayload || !outputConfig.token || !outputConfig.chainId || (requiresSwap && !quoteState.quote)) {
if (
!txState.txPayload ||
!outputConfig.token ||
!outputTokenAddress ||
!outputConfig.chainId ||
(requiresSwap && !quoteState.quote)
) {
haptics.notificationError();
setClaimStatus('recoverableError');
logger.error(new RainbowError('[TransactionClaimablePanel]: Failed to claim claimable due to missing tx payload'));
Expand All @@ -436,7 +440,7 @@ export function TransactionClaimableContextProvider({
externalTokenQueryKey({ address: accountAddress, chainId: outputConfig.chainId, currency: nativeCurrency })
) ??
(await fetchExternalToken({
address: outputConfig.token?.networks[outputConfig.chainId]?.address,
address: outputTokenAddress,
chainId: outputConfig.chainId,
currency: nativeCurrency,
}));
Expand Down
9 changes: 0 additions & 9 deletions src/screens/claimables/transaction/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import { ChainId } from '@/chains/types';
import { TransactionRequest } from '@ethersproject/providers';

export type ClaimStatus =
| 'notReady' // preparing the data necessary to claim
| 'ready' // ready to claim state
| 'claiming' // user has pressed the claim button
| 'pending' // claim has been submitted but we don't have a tx hash
| 'success' // claim has been submitted and we have a tx hash
| 'recoverableError' // claim or auth has failed, can try again
| 'unrecoverableError'; // swap has failed, unrecoverable error

// supports legacy and new gas types
export type TransactionClaimableTxPayload = TransactionRequest &
(
Expand Down

0 comments on commit 7dbe664

Please sign in to comment.