Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace App raps with BX #5608

Merged
merged 10 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/entities/gas.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { GasFeeLegacyParams } from '@/__swaps__/types/gas';

type Numberish = number | string;

export interface Fee {
Expand Down
2 changes: 1 addition & 1 deletion src/entities/transactions/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EthereumAddress } from '../wallet';
import { Network } from '@/helpers/networkTypes';
import { AddCashCurrencyAsset } from '@/references';
import { ChainId, SwapType } from '@rainbow-me/swaps';
import { SwapMetadata } from '@/raps/common';
import { SwapMetadata } from '@/raps/references';
import { UniqueAsset } from '../uniqueAssets';
import { ParsedAsset } from '@/resources/assets/types';
import { TransactionStatus, TransactionType } from '@/resources/transactions/types';
Expand Down
11 changes: 5 additions & 6 deletions src/handlers/ens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { debounce, isEmpty, sortBy } from 'lodash';
import { fetchENSAvatar, prefetchENSAvatar } from '../hooks/useENSAvatar';
import { prefetchENSCover } from '../hooks/useENSCover';
import { prefetchENSRecords } from '../hooks/useENSRecords';
import { ENSActionParameters, RapActionTypes } from '../raps/common';
import { ENSActionParameters, ENSRapActionType } from '@/raps/common';
import { getENSData, getNameFromLabelhash, saveENSData } from './localstorage/ens';
import { estimateGasWithPadding, getProviderForNetwork, TokenStandard } from './web3';
import { ENSRegistrationRecords, Records, UniqueAsset } from '@/entities';
Expand All @@ -26,7 +26,6 @@ import { prefetchENSAddress } from '@/resources/ens/ensAddressQuery';
import { ENS_MARQUEE_QUERY_KEY } from '@/resources/metadata/ensMarqueeQuery';
import { queryClient } from '@/react-query';
import { EnsMarqueeAccount } from '@/graphql/__generated__/metadata';
import { getEnsMarqueeFallback } from '@/components/ens-registration/IntroMarquee/IntroMarquee';
import { MimeType, handleNFTImages } from '@/utils/handleNFTImages';

const DUMMY_RECORDS = {
Expand Down Expand Up @@ -888,13 +887,13 @@ export const getTransactionTypeForRecords = (registrationRecords: ENSRegistratio
export const getRapActionTypeForTxType = (txType: ENSRegistrationTransactionType) => {
switch (txType) {
case ENSRegistrationTransactionType.MULTICALL:
return RapActionTypes.multicallENS;
return ENSRapActionType.multicallENS;
case ENSRegistrationTransactionType.SET_ADDR:
return RapActionTypes.setAddrENS;
return ENSRapActionType.setAddrENS;
case ENSRegistrationTransactionType.SET_TEXT:
return RapActionTypes.setTextENS;
return ENSRapActionType.setTextENS;
case ENSRegistrationTransactionType.SET_CONTENTHASH:
return RapActionTypes.setContenthashENS;
return ENSRapActionType.setContenthashENS;
default:
return null;
}
Expand Down
19 changes: 10 additions & 9 deletions src/hooks/useENSRegistrationActionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Image } from 'react-native-image-crop-picker';
import { useRecoilValue } from 'recoil';
import { avatarMetadataAtom } from '../components/ens-registration/RegistrationAvatar/RegistrationAvatar';
import { coverMetadataAtom } from '../components/ens-registration/RegistrationCover/RegistrationCover';
import { ENSActionParameters, RapActionTypes } from '../raps/common';
import { ENSActionParameters, ENSRapActionType } from '@/raps/common';
import usePendingTransactions from './usePendingTransactions';
import { useAccountSettings, useENSRegistration, useWalletENSAvatar, useWallets } from '.';
import { Records, RegistrationParameters } from '@/entities';
Expand All @@ -15,12 +15,13 @@ import { uploadImage } from '@/handlers/pinata';
import { getProviderForNetwork } from '@/handlers/web3';
import { ENS_DOMAIN, generateSalt, getRentPrice, REGISTRATION_STEPS } from '@/helpers/ens';
import { loadWallet } from '@/model/wallet';
import { executeRap } from '@/raps';
import { timeUnits } from '@/references';
import Routes from '@/navigation/routesNames';
import { labelhash, logger } from '@/utils';
import { getNextNonce } from '@/state/nonces';
import { Network } from '@/networks/types';
import { Hex } from 'viem';
import { executeENSRap } from '@/raps/actions/ens';

const NOOP = () => null;

Expand Down Expand Up @@ -110,7 +111,7 @@ export default function useENSRegistrationActionHandler(
salt,
};

await executeRap(wallet, RapActionTypes.commitENS, commitEnsRegistrationParameters, () => {
await executeENSRap(wallet, ENSRapActionType.commitENS, commitEnsRegistrationParameters, () => {
if (isHardwareWallet) {
goBack();
}
Expand Down Expand Up @@ -166,7 +167,7 @@ export default function useENSRegistrationActionHandler(
setReverseRecord: sendReverseRecord,
};

await executeRap(wallet, RapActionTypes.registerENS, registerEnsRegistrationParameters, callback);
await executeENSRap(wallet, ENSRapActionType.registerENS, registerEnsRegistrationParameters, callback);

updateAvatarsOnNextBlock.current = true;
},
Expand All @@ -193,7 +194,7 @@ export default function useENSRegistrationActionHandler(
rentPrice: rentPrice.toString(),
};

await executeRap(wallet, RapActionTypes.renewENS, registerEnsRegistrationParameters, callback);
await executeENSRap(wallet, ENSRapActionType.renewENS, registerEnsRegistrationParameters, callback);
},
[accountAddress, duration, registrationParameters]
);
Expand All @@ -217,7 +218,7 @@ export default function useENSRegistrationActionHandler(
ownerAddress: accountAddress,
};

await executeRap(wallet, RapActionTypes.setNameENS, registerEnsRegistrationParameters, callback);
await executeENSRap(wallet, ENSRapActionType.setNameENS, registerEnsRegistrationParameters, callback);
},
[accountAddress, registrationParameters]
);
Expand All @@ -244,11 +245,11 @@ export default function useENSRegistrationActionHandler(
nonce,
ownerAddress: accountAddress,
records: changedRecords,
resolverAddress: resolver?.address,
resolverAddress: resolver?.address as Hex,
setReverseRecord: sendReverseRecord,
};

await executeRap(wallet, RapActionTypes.setRecordsENS, setRecordsEnsRegistrationParameters, callback);
await executeENSRap(wallet, ENSRapActionType.setRecordsENS, setRecordsEnsRegistrationParameters, callback);

updateAvatarsOnNextBlock.current = true;
},
Expand Down Expand Up @@ -285,7 +286,7 @@ export default function useENSRegistrationActionHandler(
transferControl,
};

const { nonce: newNonce } = await executeRap(wallet, RapActionTypes.transferENS, transferEnsParameters, callback);
const { nonce: newNonce } = await executeENSRap(wallet, ENSRapActionType.transferENS, transferEnsParameters, callback);

return { nonce: newNonce };
},
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useParamsForExchangeModal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SwapModalField, updateSwapSlippage, updateSwapSource } from '@/redux/swap';
import { MutableRefObject, useEffect, useState } from 'react';
import { useSwapInputHandlers } from '@/hooks/index';
import { SwapMetadata } from '@/raps/common';
import { SwapMetadata } from '@/raps/references';
import { useDispatch } from 'react-redux';
import { useRoute } from '@react-navigation/native';
import { TextInput } from 'react-native';
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useSwapSettings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { AppState } from '@/redux/store';
import { Source, updateSwapSlippage as updateSwapSlippageRedux, updateSwapSource as updateSwapSourceRedux } from '@/redux/swap';
import { Source } from '@/raps/references';
import { updateSwapSlippage as updateSwapSlippageRedux, updateSwapSource as updateSwapSourceRedux } from '@/redux/swap';

export default function useSwapSettings() {
const dispatch = useDispatch();
Expand Down
70 changes: 70 additions & 0 deletions src/raps/actions/crosschainSwap.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// import { Wallet } from '@ethersproject/wallet';
walmat marked this conversation as resolved.
Show resolved Hide resolved
// import {
// CrosschainQuote,
// ETH_ADDRESS as ETH_ADDRESS_AGGREGATORS,
// QuoteError,
// SwapType,
// getCrosschainQuote,
// } from '@rainbow-me/swaps';
// import { getProvider } from '@wagmi/core';
// import { mainnet } from 'viem/chains';
// import { beforeAll, expect, test } from 'vitest';

// import { ChainId } from '~/core/types/chains';
// import {
// TEST_ADDRESS_3,
// TEST_PK_3,
// USDC_ARBITRUM_ASSET,
// delay,
// } from '~/test/utils';

// import { createTestWagmiClient } from '../../wagmi/createTestWagmiClient';

// import {
// estimateCrosschainSwapGasLimit,
// executeCrosschainSwap,
// } from './crosschainSwap';

// let crosschainQuote: CrosschainQuote | QuoteError | null;

// beforeAll(async () => {
// createTestWagmiClient();
// await delay(3000);
// crosschainQuote = await getCrosschainQuote({
// chainId: 1,
// fromAddress: TEST_ADDRESS_3,
// sellTokenAddress: ETH_ADDRESS_AGGREGATORS,
// buyTokenAddress: USDC_ARBITRUM_ASSET.address,
// sellAmount: '1000000000000000000',
// slippage: 5,
// destReceiver: TEST_ADDRESS_3,
// swapType: SwapType.crossChain,
// toChainId: ChainId.arbitrum,
// });
// }, 20000);

// test('[rap/crosschainSwap] :: should estimate crosschain swap gas limit', async () => {
// const swapGasLimit = await estimateCrosschainSwapGasLimit({
// chainId: mainnet.id,
// requiresApprove: false,
// quote: crosschainQuote as CrosschainQuote,
// });
// expect(Number(swapGasLimit)).toBeGreaterThan(0);
// });

// test('[rap/crosschainSwap] :: should execute crosschain swap', async () => {
// const provider = getProvider({ chainId: mainnet.id });
// const wallet = new Wallet(TEST_PK_3, provider);

// const swapTx = await executeCrosschainSwap({
// gasLimit: '600000',
// gasParams: {
// maxFeePerGas: '2000000000000',
// maxPriorityFeePerGas: '2000000000',
// },
// quote: crosschainQuote as CrosschainQuote,
// wallet,
// });

// expect(swapTx?.hash).toBeDefined();
// });
Loading
Loading