From d1d1389f5011e71315ccb035e1aae8fcd9363782 Mon Sep 17 00:00:00 2001 From: Aaron Quirk Date: Sat, 2 Nov 2024 07:39:58 -0400 Subject: [PATCH] Revert "Support send of arbitrary ERC-20 tokens (#223)" This reverts commit 3a6154b859b45f8feccfb70acd7333a5e81948cf. --- packages/config/src/env/default.ts | 47 +++++------- packages/config/src/env/types.ts | 11 +-- packages/ui-components/package.json | 3 +- .../src/components/Wallet/Buy.tsx | 2 +- .../src/components/Wallet/Receive.tsx | 76 +++++++++---------- .../src/components/Wallet/SelectAsset.tsx | 24 +++--- .../src/components/Wallet/Send.tsx | 67 +++++----------- .../src/components/Wallet/SendConfirm.tsx | 5 +- .../components/Wallet/SubmitTransaction.tsx | 8 +- .../src/components/Wallet/Token.tsx | 1 - .../src/hooks/useSubmitTransaction.ts | 47 ++---------- .../ui-components/src/lib/wallet/asset.ts | 5 +- .../src/lib/wallet/evm/provider.ts | 13 ---- .../src/lib/wallet/evm/token.test.ts | 27 ------- .../ui-components/src/lib/wallet/evm/token.ts | 35 --------- .../ui-components/src/lib/wallet/evm/web3.ts | 27 ------- packages/ui-components/src/locales/en.json | 6 +- .../ui-components/src/tests/mocks/wallet.ts | 1 - yarn.lock | 16 ---- 19 files changed, 104 insertions(+), 317 deletions(-) delete mode 100644 packages/ui-components/src/lib/wallet/evm/provider.ts delete mode 100644 packages/ui-components/src/lib/wallet/evm/token.test.ts delete mode 100644 packages/ui-components/src/lib/wallet/evm/token.ts delete mode 100644 packages/ui-components/src/lib/wallet/evm/web3.ts diff --git a/packages/config/src/env/default.ts b/packages/config/src/env/default.ts index 68ff9565..d431a572 100644 --- a/packages/config/src/env/default.ts +++ b/packages/config/src/env/default.ts @@ -20,8 +20,8 @@ export default function getDefaultConfig(): Config { CHAIN_ID: 5, NETWORK_NAME: 'goerli', // testnet JSON_RPC_API_URL: `https://goerli.infura.io/v3/a58ebb0c76a64c149e35145f85f82382`, - BLOCK_EXPLORER_NAME: 'oklink', - BLOCK_EXPLORER_BASE_URL: 'https://www.oklink.com/sepolia-test', + BLOCK_EXPLORER_NAME: 'etherscan', + BLOCK_EXPLORER_BASE_URL: 'https://goerli.etherscan.io', BLOCK_EXPLORER_TX_URL: 'https://www.oklink.com/sepolia-test/tx/', DISABLE_CONTRACTS_CACHE: true, PROXY_READER_ADDRESS: '0xFc5f608149f4D9e2Ed0733efFe9DD57ee24BCF68', @@ -33,40 +33,21 @@ export default function getDefaultConfig(): Config { NETWORK_NAME: 'amoy', // testnet JSON_RPC_API_URL: 'https://polygon-amoy.infura.io/v3/a58ebb0c76a64c149e35145f85f82382', - BLOCK_EXPLORER_NAME: 'oklink', - BLOCK_EXPLORER_BASE_URL: 'https://www.oklink.com/amoy', + BLOCK_EXPLORER_NAME: 'polygonscan', + BLOCK_EXPLORER_BASE_URL: 'https://amoy.polygonscan.com', BLOCK_EXPLORER_TX_URL: 'https://www.oklink.com/amoy/tx/', DISABLE_CONTRACTS_CACHE: true, PROXY_READER_ADDRESS: '0x332A8191905fA8E6eeA7350B5799F225B8ed30a9', OPEN_SEA_BASE_URL: 'https://testnets.opensea.io/assets/amoy/', }, BASE: { - CHAIN_ID: 8453, - NETWORK_NAME: 'base', - JSON_RPC_API_URL: - 'https://base-mainnet.infura.io/v3/a58ebb0c76a64c149e35145f85f82382', BLOCK_EXPLORER_TX_URL: 'https://www.oklink.com/base/tx/', - BLOCK_EXPLORER_NAME: 'oklink', - BLOCK_EXPLORER_BASE_URL: 'https://www.oklink.com/base', - DISABLE_CONTRACTS_CACHE: true, }, BTC: { - CHAIN_ID: 0, - NETWORK_NAME: 'bitcoin', - JSON_RPC_API_URL: '', BLOCK_EXPLORER_TX_URL: 'https://www.oklink.com/btc/tx/', - BLOCK_EXPLORER_NAME: 'oklink', - BLOCK_EXPLORER_BASE_URL: 'https://www.oklink.com/btc', - DISABLE_CONTRACTS_CACHE: true, }, SOL: { - CHAIN_ID: 0, - NETWORK_NAME: 'solana', - JSON_RPC_API_URL: '', BLOCK_EXPLORER_TX_URL: 'https://www.oklink.com/sol/tx/', - BLOCK_EXPLORER_NAME: 'oklink', - BLOCK_EXPLORER_BASE_URL: 'https://www.oklink.com/sol', - DISABLE_CONTRACTS_CACHE: true, }, }, UD_LOGO_URL: @@ -118,9 +99,23 @@ export default function getDefaultConfig(): Config { LANDING_PAGE_URL: 'https://unstoppabledomains.com/products/wallet', CHAINS: { BUY: ['BTC/BTC', 'MATIC/MATIC', 'SOL/SOL', 'ETH/ETH'], - RECEIVE: ['BTC/BTC', 'MATIC/MATIC', 'SOL/SOL', 'BASE/ETH', 'ETH/ETH'], - SEND: ['BTC/BTC', 'MATIC/MATIC', 'SOL/SOL', 'BASE/ETH', 'ETH/ETH'], - DOMAINS: ['ETH', 'MATIC', 'BASE'], + RECEIVE: [ + 'BTC/BTC', + 'MATIC/MATIC', + 'MATIC/USDC', + 'SOL/SOL', + 'BASE/ETH', + 'ETH/ETH', + ], + SEND: [ + 'BTC/BTC', + 'MATIC/MATIC', + 'MATIC/USDC', + 'SOL/SOL', + 'BASE/ETH', + 'ETH/ETH', + ], + DOMAINS: ['ETH', 'MATIC'], }, MOBILE: { ANDROID_URL: diff --git a/packages/config/src/env/types.ts b/packages/config/src/env/types.ts index c1169ccb..f8d6de9a 100644 --- a/packages/config/src/env/types.ts +++ b/packages/config/src/env/types.ts @@ -44,18 +44,13 @@ export type MaticBlockchainConfig = BaseBlockchainConfig & { | 'https://www.oklink.com/polygon/tx/'; }; -export type BitcoinBlockchainConfig = BaseBlockchainConfig & { - CHAIN_ID: 0; +export type BitcoinBlockchainConfig = { BLOCK_EXPLORER_TX_URL: 'https://www.oklink.com/btc/tx/'; }; - -export type SolanaBlockchainConfig = BaseBlockchainConfig & { - CHAIN_ID: 0; +export type SolanaBlockchainConfig = { BLOCK_EXPLORER_TX_URL: 'https://www.oklink.com/sol/tx/'; }; - -export type BaseChainBlockchainConfig = BaseBlockchainConfig & { - CHAIN_ID: 8453; +export type BaseChainBlockchainConfig = { BLOCK_EXPLORER_TX_URL: 'https://www.oklink.com/base/tx/'; }; diff --git a/packages/ui-components/package.json b/packages/ui-components/package.json index 1ddc824d..846cb84c 100644 --- a/packages/ui-components/package.json +++ b/packages/ui-components/package.json @@ -1,6 +1,6 @@ { "name": "@unstoppabledomains/ui-components", - "version": "0.0.51-browser-extension.7", + "version": "0.0.51-browser-extension.6", "private": true, "description": "An open and reusable suite of Unstoppable Domains management components", "keywords": [ @@ -63,7 +63,6 @@ "@xmtp/content-type-text": "^1.0.0", "@xmtp/proto": "^3.62.1", "@xmtp/xmtp-js": "12.1.0", - "abitype": "^1.0.6", "bip322-js": "^1.1.0", "bitcoin-address-validation": "^2.2.3", "bluebird": "^3.7.2", diff --git a/packages/ui-components/src/components/Wallet/Buy.tsx b/packages/ui-components/src/components/Wallet/Buy.tsx index db2c8c13..54d5c7a4 100644 --- a/packages/ui-components/src/components/Wallet/Buy.tsx +++ b/packages/ui-components/src/components/Wallet/Buy.tsx @@ -113,7 +113,7 @@ const Buy: React.FC = ({isSellEnabled, onCancelClick, wallets}) => { ? 'wallet.selectAssetToBuySell' : 'wallet.selectAssetToBuy', )} - supportedAssetList={config.WALLETS.CHAINS.BUY} + supportedTokenList={config.WALLETS.CHAINS.BUY} /> ); diff --git a/packages/ui-components/src/components/Wallet/Receive.tsx b/packages/ui-components/src/components/Wallet/Receive.tsx index 9673cd35..705f1a05 100644 --- a/packages/ui-components/src/components/Wallet/Receive.tsx +++ b/packages/ui-components/src/components/Wallet/Receive.tsx @@ -33,7 +33,6 @@ const useStyles = makeStyles()((theme: Theme) => ({ marginRight: theme.spacing(-1), }, height: '100%', - justifyContent: 'space-between', }, selectAssetContainer: { display: 'flex', @@ -60,31 +59,30 @@ const useStyles = makeStyles()((theme: Theme) => ({ width: '60px', borderRadius: '50%', overflow: 'hidden', + marginTop: theme.spacing(1), }, contentWrapper: { display: 'flex', flexDirection: 'column', alignItems: 'center', minHeight: '250px', - width: '100%', }, receiveAssetContainer: { display: 'flex', flexDirection: 'column', alignItems: 'center', + marginTop: theme.spacing(3), }, receiveContentContainer: { display: 'flex', flexDirection: 'column', alignItems: 'center', - width: '100%', }, copyButton: {}, addressWrapper: { display: 'flex', flexDirection: 'column', alignItems: 'center', - width: '100%', }, captionContainer: { display: 'flex', @@ -92,9 +90,6 @@ const useStyles = makeStyles()((theme: Theme) => ({ padding: 10, borderRadius: 9, }, - input: { - fontSize: '12px', - }, infoIcon: { fontSize: 15, }, @@ -142,7 +137,7 @@ const Receive: React.FC = ({onCancelClick, wallets}) => { wallets={wallets} onCancelClick={handleBackClick} label={t('wallet.selectAssetToReceive')} - supportedAssetList={config.WALLETS.CHAINS.RECEIVE} + supportedTokenList={config.WALLETS.CHAINS.RECEIVE} /> ); @@ -176,7 +171,7 @@ const Receive: React.FC = ({onCancelClick, wallets}) => { = ({onCancelClick, wallets}) => { stacked={true} disabled multiline - classes={{input: classes.input}} endAdornment={ } /> + + + + + + + {t( + config.WALLETS.CHAINS.DOMAINS.map(s => + s.toLowerCase(), + ).includes(asset.symbol.toLowerCase()) + ? 'wallet.receiveAddressCaptionWithDomains' + : 'wallet.receiveAddressCaption', + { + symbol: getBlockchainDisplaySymbol(asset.ticker), + blockchain: asset.walletName, + }, + )} + {' '} + {t('wallet.sendingForOtherNetworksAndTokens', { + symbol: getBlockchainDisplaySymbol(asset.ticker), + blockchain: asset.walletName, + })}{' '} + + Learn More + + + - - - - - - - {t( - config.WALLETS.CHAINS.DOMAINS.map(s => s.toLowerCase()).includes( - asset.symbol.toLowerCase(), - ) - ? 'wallet.receiveAddressCaptionWithDomains' - : 'wallet.receiveAddressCaption', - { - symbol: getBlockchainDisplaySymbol(asset.ticker), - blockchain: asset.walletName, - }, - )} - {' '} - {t('wallet.sendingForOtherNetworksAndTokens', { - symbol: getBlockchainDisplaySymbol(asset.ticker), - blockchain: asset.walletName, - })}{' '} - - Learn More - - - ); }; diff --git a/packages/ui-components/src/components/Wallet/SelectAsset.tsx b/packages/ui-components/src/components/Wallet/SelectAsset.tsx index 1445957e..fc877736 100644 --- a/packages/ui-components/src/components/Wallet/SelectAsset.tsx +++ b/packages/ui-components/src/components/Wallet/SelectAsset.tsx @@ -6,7 +6,7 @@ import type {ImmutableArray} from '@unstoppabledomains/config/build/src/env/type import {makeStyles} from '@unstoppabledomains/ui-kit/styles'; import type {SerializedWalletBalance} from '../../lib'; -import {TokenType, WalletPaletteOwner} from '../../lib'; +import {TokenType, WalletPaletteOwner, useTranslationContext} from '../../lib'; import {filterWallets} from '../../lib/wallet/filter'; import FundWalletModal from './FundWalletModal'; import {TitleWithBackButton} from './TitleWithBackButton'; @@ -56,8 +56,7 @@ type Props = { requireBalance?: boolean; onClickReceive?: () => void; onClickBuy?: () => void; - supportedAssetList: ImmutableArray; - supportErc20?: boolean; + supportedTokenList: ImmutableArray; }; export const SelectAsset: React.FC = ({ @@ -70,11 +69,11 @@ export const SelectAsset: React.FC = ({ requireBalance, onClickReceive, onClickBuy, - supportedAssetList, - supportErc20, + supportedTokenList, }) => { const {classes} = useStyles(); - const wallets = filterWallets(initialWallets, supportedAssetList); + const [t] = useTranslationContext(); + const wallets = filterWallets(initialWallets, supportedTokenList); const serializeNativeTokens = (wallet: SerializedWalletBalance) => { if ( @@ -112,8 +111,7 @@ export const SelectAsset: React.FC = ({ ...(wallets || []).flatMap(wallet => (wallet?.tokens || []).map(walletToken => { return { - address: walletToken.address, - type: walletToken.type, + type: 'Token' as never, name: walletToken.name, value: walletToken.value?.walletUsdAmt || 0, balance: walletToken.balanceAmt || 0, @@ -136,12 +134,10 @@ export const SelectAsset: React.FC = ({ ]; const filteredTokens: TokenEntry[] = allTokens .filter(token => !requireBalance || token.balance > 0) - .filter( - token => - (token.type === TokenType.Erc20 && supportErc20) || - supportedAssetList.includes( - `${token.symbol.toUpperCase()}/${token.ticker.toUpperCase()}`, - ), + .filter(token => + supportedTokenList.includes( + `${token.symbol.toUpperCase()}/${token.ticker.toUpperCase()}`, + ), ) .sort((a, b) => b.value - a.value || b.balance - a.balance); diff --git a/packages/ui-components/src/components/Wallet/Send.tsx b/packages/ui-components/src/components/Wallet/Send.tsx index a56e110e..81e26b28 100644 --- a/packages/ui-components/src/components/Wallet/Send.tsx +++ b/packages/ui-components/src/components/Wallet/Send.tsx @@ -11,17 +11,14 @@ import {makeStyles} from '@unstoppabledomains/ui-kit/styles'; import {useFeatureFlags} from '../../actions'; import { getAccountAssets, - getTransactionGasEstimate, getTransferGasEstimate, } from '../../actions/fireBlocksActions'; import {prepareRecipientWallet} from '../../actions/walletActions'; import type {SerializedWalletBalance} from '../../lib'; -import {TokenType, useTranslationContext} from '../../lib'; +import {useTranslationContext} from '../../lib'; import {sleep} from '../../lib/sleep'; import type {AccountAsset} from '../../lib/types/fireBlocks'; import {getAsset} from '../../lib/wallet/asset'; -import {getProviderUrl} from '../../lib/wallet/evm/provider'; -import {createErc20TransferTx} from '../../lib/wallet/evm/token'; import {isEthAddress} from '../Chat/protocol/resolution'; import {getBlockchainDisplaySymbol} from '../Manage/common/verification/types'; import AddressInput from './AddressInput'; @@ -211,43 +208,20 @@ const Send: React.FC = ({ const assetToSend = getAsset(assets, { token, }); - if (!assetToSend?.blockchainAsset.blockchain.networkId) { + if (!assetToSend) { throw new Error('Asset not found'); } - // depending on the type of token, estimate the required gas - if (token.type === TokenType.Erc20 && token.address) { - // retrieve gas for a transaction - const transferTx = await createErc20TransferTx({ - chainId: assetToSend.blockchainAsset.blockchain.networkId, - providerUrl: getProviderUrl( - assetToSend.blockchainAsset.blockchain.networkId, - ), - tokenAddress: token.address, - fromAddress: token.walletAddress, - toAddress: token.walletAddress, - amount: 0.000001, - }); - const transferTxGas = await getTransactionGasEstimate( - assetToSend, - accessToken, - transferTx, - ); - setGasFeeEstimate(transferTxGas.networkFee?.amount || '0'); - } else { - // retrieve gas for a transfer - const transferGas = await getTransferGasEstimate( - assetToSend, - accessToken, - // Doesn't matter what the recipient and amount are, just need to get the fee estimate - assetToSend.address, - // Use a small test amount to measure gas - '0.0001', - ); - setGasFeeEstimate(transferGas.networkFee?.amount || '0'); - } - - // save the asset entry to be sent + // estimate the gas cost + const gasResponse = await getTransferGasEstimate( + assetToSend, + accessToken, + // Doesn't matter what the recipient and amount are, just need to get the fee estimate + assetToSend.address, + // Use a small test amount to measure gas + '0.0001', + ); + setGasFeeEstimate(gasResponse.networkFee?.amount || '0'); setAccountAsset(assetToSend); setIsLoading(false); }; @@ -306,13 +280,11 @@ const Send: React.FC = ({ } // normalize asset decimals if present - const normalizedBase = parseInt(value, 10); - const normalizedValue = - value.includes('.') && accountAsset.balance?.decimals - ? `${normalizedBase}.${value - .replaceAll(`${normalizedBase}.`, '') - .slice(0, accountAsset.balance.decimals)}` - : value; + const normalizedValue = accountAsset.balance?.decimals + ? `0.${value + .replaceAll('0.', '') + .slice(0, accountAsset.balance.decimals)}` + : value; // use normalized value setAmount(normalizedValue); @@ -342,8 +314,7 @@ const Send: React.FC = ({ onClickReceive={onClickReceive} label={t('wallet.selectAssetToSend')} requireBalance={true} - supportedAssetList={config.WALLETS.CHAINS.SEND} - supportErc20={true} + supportedTokenList={config.WALLETS.CHAINS.SEND} /> ); @@ -355,7 +326,6 @@ const Send: React.FC = ({ = ({ onInvitation={handleSendInvitation} accessToken={accessToken} asset={accountAsset} - token={selectedToken} recipientAddress={recipientAddress} recipientDomain={resolvedDomain} amount={amount} diff --git a/packages/ui-components/src/components/Wallet/SendConfirm.tsx b/packages/ui-components/src/components/Wallet/SendConfirm.tsx index f8945c29..6fc1bc41 100644 --- a/packages/ui-components/src/components/Wallet/SendConfirm.tsx +++ b/packages/ui-components/src/components/Wallet/SendConfirm.tsx @@ -16,7 +16,6 @@ import { getBlockchainSymbol, } from '../Manage/common/verification/types'; import {TitleWithBackButton} from './TitleWithBackButton'; -import type {TokenEntry} from './Token'; const useStyles = makeStyles()((theme: Theme) => ({ fullWidth: { @@ -63,7 +62,6 @@ type Props = { amount: string; symbol: string; asset: AccountAsset; - token: TokenEntry; gasFee: string; amountInDollars: string; blockchainName: string; @@ -78,7 +76,6 @@ export const SendConfirm: React.FC = ({ recipientAddress, resolvedDomain, asset, - token, amount, symbol, amountInDollars, @@ -91,7 +88,7 @@ export const SendConfirm: React.FC = ({ const maxDisplayLength = asset.balance?.decimals ? Math.min(MAX_DISPLAY_LENGTH, asset.balance.decimals) : MAX_DISPLAY_LENGTH; - const assetSymbol = token.ticker; + const assetSymbol = asset.blockchainAsset.symbol.toUpperCase(); const gasSymbol = getBlockchainGasSymbol( getBlockchainSymbol(asset.blockchainAsset.blockchain.id), ).toUpperCase(); diff --git a/packages/ui-components/src/components/Wallet/SubmitTransaction.tsx b/packages/ui-components/src/components/Wallet/SubmitTransaction.tsx index 145726f6..98ba820d 100644 --- a/packages/ui-components/src/components/Wallet/SubmitTransaction.tsx +++ b/packages/ui-components/src/components/Wallet/SubmitTransaction.tsx @@ -18,7 +18,6 @@ import { getBlockchainSymbol, } from '../Manage/common/verification/types'; import {OperationStatus} from './OperationStatus'; -import type {TokenEntry} from './Token'; const useStyles = makeStyles()((theme: Theme) => ({ fullWidth: { @@ -61,7 +60,6 @@ type Props = { ) => Promise | undefined>; accessToken: string; asset: AccountAsset; - token: TokenEntry; recipientAddress: string; recipientDomain?: string; amount: string; @@ -73,7 +71,6 @@ export const SubmitTransaction: React.FC = ({ onInvitation, accessToken, asset, - token, recipientAddress, recipientDomain, amount, @@ -84,7 +81,6 @@ export const SubmitTransaction: React.FC = ({ const {transactionId, status, statusMessage} = useSubmitTransaction({ accessToken, asset, - token, recipientAddress, amount, getClient, @@ -127,7 +123,9 @@ export const SubmitTransaction: React.FC = ({ }`, { amount, - sourceSymbol: getBlockchainDisplaySymbol(token.ticker), + sourceSymbol: getBlockchainDisplaySymbol( + asset.blockchainAsset.symbol, + ), status, recipientDomain: recipientDomain ? ` ${recipientDomain}` diff --git a/packages/ui-components/src/components/Wallet/Token.tsx b/packages/ui-components/src/components/Wallet/Token.tsx index fa07b929..5be267fa 100644 --- a/packages/ui-components/src/components/Wallet/Token.tsx +++ b/packages/ui-components/src/components/Wallet/Token.tsx @@ -88,7 +88,6 @@ const useStyles = makeStyles()((theme: Theme, {palette}) => ({ })); export type TokenEntry = { - address?: string; type: TokenType; symbol: string; name: string; diff --git a/packages/ui-components/src/hooks/useSubmitTransaction.ts b/packages/ui-components/src/hooks/useSubmitTransaction.ts index 815fcb4a..57035ade 100644 --- a/packages/ui-components/src/hooks/useSubmitTransaction.ts +++ b/packages/ui-components/src/hooks/useSubmitTransaction.ts @@ -4,7 +4,6 @@ import {useEffect, useRef, useState} from 'react'; import { SendCryptoStatusMessage, cancelPendingOperations, - createTransactionOperation, getOperationStatus, getTransferOperationResponse, } from '../actions/fireBlocksActions'; @@ -12,22 +11,17 @@ import { getBlockchainSymbol, getRecordKeys, } from '../components/Manage/common/verification/types'; -import type {TokenEntry} from '../components/Wallet/Token'; -import {TokenType} from '../lib'; import {notifyEvent} from '../lib/error'; import {FB_MAX_RETRY, FB_WAIT_TIME_MS} from '../lib/fireBlocks/client'; import {isEmailValid} from '../lib/isEmailValid'; import {pollForSuccess} from '../lib/poll'; import type {AccountAsset, GetOperationResponse} from '../lib/types/fireBlocks'; import {OperationStatusType} from '../lib/types/fireBlocks'; -import {getProviderUrl} from '../lib/wallet/evm/provider'; -import {createErc20TransferTx} from '../lib/wallet/evm/token'; import useResolverKeys from './useResolverKeys'; export type Params = { accessToken: string; asset: AccountAsset; - token: TokenEntry; recipientAddress: string; amount: string; getClient: () => Promise; @@ -45,7 +39,6 @@ export enum Status { export const useSubmitTransaction = ({ accessToken, asset, - token, recipientAddress: initialRecipientAddress, amount, getClient, @@ -119,40 +112,14 @@ export const useSubmitTransaction = ({ recipientAddress = resolvedAddress; } - // create a transfer transaction if we are working with - // an ERC-20 token - const transferTx = - asset.blockchainAsset.blockchain.networkId && - token.address && - token.type === TokenType.Erc20 - ? await createErc20TransferTx({ - chainId: asset.blockchainAsset.blockchain.networkId, - providerUrl: getProviderUrl( - asset.blockchainAsset.blockchain.networkId, - ), - tokenAddress: token.address, - fromAddress: token.walletAddress, - toAddress: recipientAddress, - amount: parseFloat(amount), - }) - : undefined; - - // create new transfer request, depending on token type + // create new transfer request setStatusMessage(SendCryptoStatusMessage.STARTING_TRANSACTION); - const operationResponse = - transferTx && asset.accountId - ? await createTransactionOperation( - accessToken, - asset.accountId, - asset.id, - transferTx, - ) - : await getTransferOperationResponse( - asset, - accessToken, - recipientAddress, - parseFloat(amount), - ); + const operationResponse = await getTransferOperationResponse( + asset, + accessToken, + recipientAddress, + parseFloat(amount), + ); if (!operationResponse) { throw new Error('Error starting transaction'); } diff --git a/packages/ui-components/src/lib/wallet/asset.ts b/packages/ui-components/src/lib/wallet/asset.ts index a6fe42a0..8f4a9ab7 100644 --- a/packages/ui-components/src/lib/wallet/asset.ts +++ b/packages/ui-components/src/lib/wallet/asset.ts @@ -2,7 +2,6 @@ import config from '@unstoppabledomains/config'; import type {TokenEntry} from '../../components/Wallet/Token'; import {notifyEvent} from '../error'; -import {TokenType} from '../types'; import type {AccountAsset} from '../types/fireBlocks'; import {SUPPORTED_SIGNING_SYMBOLS} from '../types/wallet'; @@ -36,9 +35,7 @@ export const getAsset = ( a.blockchainAsset.blockchain.name.toLowerCase() === opts.token.walletName.toLowerCase() && a.blockchainAsset.symbol.toLowerCase() === - (opts.token.type === TokenType.Erc20 - ? opts.token.symbol.toLowerCase() - : opts.token.ticker.toLowerCase()) && + opts.token.ticker.toLowerCase() && a.address.toLowerCase() === opts.token.walletAddress.toLowerCase() ); } diff --git a/packages/ui-components/src/lib/wallet/evm/provider.ts b/packages/ui-components/src/lib/wallet/evm/provider.ts deleted file mode 100644 index 9b732dee..00000000 --- a/packages/ui-components/src/lib/wallet/evm/provider.ts +++ /dev/null @@ -1,13 +0,0 @@ -import config from '@unstoppabledomains/config'; - -export const getProviderUrl = (chainId: number) => { - const providerUrl = Object.values(config.BLOCKCHAINS).find( - v => v.CHAIN_ID === chainId, - )?.JSON_RPC_API_URL; - if (providerUrl) { - return providerUrl; - } - - // an RPC provider URL is required - throw new Error(`Chain ID not supported: ${chainId}`); -}; diff --git a/packages/ui-components/src/lib/wallet/evm/token.test.ts b/packages/ui-components/src/lib/wallet/evm/token.test.ts deleted file mode 100644 index 4e926b83..00000000 --- a/packages/ui-components/src/lib/wallet/evm/token.test.ts +++ /dev/null @@ -1,27 +0,0 @@ -import {createErc20TransferTx} from './token'; -import * as web3 from './web3'; - -describe('token transactions', () => { - it('should create an erc20 transfer tx', async () => { - // mock the contract decimals - jest.spyOn(web3, 'getContractDecimals').mockResolvedValue(6); - - // create the transaction - const tx = await createErc20TransferTx({ - chainId: 80002, - providerUrl: 'https://mock-provider-url', - tokenAddress: '0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582', - fromAddress: '0xCD0DAdAb45bAF9a06ce1279D1342EcC3F44845af', - toAddress: '0x8ee1E1d88EBE2B44eAD162777DE787Ef6A2dC2F2', - amount: 0.000001, - }); - expect(tx).toMatchObject({ - chainId: 80002, - to: '0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582', - // expected data generated directly from Polygon scan using MetaMask: - // https://amoy.polygonscan.com/token/0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582?a=0x8ee1e1d88ebe2b44ead162777de787ef6a2dc2f2#writeProxyContract - data: '0xa9059cbb0000000000000000000000008ee1e1d88ebe2b44ead162777de787ef6a2dc2f20000000000000000000000000000000000000000000000000000000000000001', - value: '0', - }); - }); -}); diff --git a/packages/ui-components/src/lib/wallet/evm/token.ts b/packages/ui-components/src/lib/wallet/evm/token.ts deleted file mode 100644 index 13082d1a..00000000 --- a/packages/ui-components/src/lib/wallet/evm/token.ts +++ /dev/null @@ -1,35 +0,0 @@ -import type {CreateTransaction} from '../../types'; -import {getContract, getContractDecimals} from './web3'; - -export const createErc20TransferTx = async (opts: { - chainId: number; - providerUrl: string; - tokenAddress: string; - fromAddress: string; - toAddress: string; - amount: number; -}): Promise => { - // ERC-20 contract instance for sending a specific token - const erc20Contract = getContract( - opts.providerUrl, - opts.tokenAddress, - opts.fromAddress, - ); - - // retrieve the contract decimals to represent the amount - const decimals = await getContractDecimals( - opts.providerUrl, - opts.tokenAddress, - ); - const normalizedAmt = Math.floor(opts.amount * Math.pow(10, decimals)); - - // create the transaction that should be signed to execute ERC-20 transfer - return { - chainId: opts.chainId, - to: opts.tokenAddress, - data: erc20Contract.methods - .transfer(opts.toAddress, normalizedAmt) - .encodeABI(), - value: '0', - }; -}; diff --git a/packages/ui-components/src/lib/wallet/evm/web3.ts b/packages/ui-components/src/lib/wallet/evm/web3.ts deleted file mode 100644 index fa79169c..00000000 --- a/packages/ui-components/src/lib/wallet/evm/web3.ts +++ /dev/null @@ -1,27 +0,0 @@ -import {erc20Abi} from 'abitype/abis'; -import {Web3} from 'web3'; - -export const getContract = ( - providerUrl: string, - tokenAddress: string, - fromAddress?: string, -) => { - // ERC-20 contract instance for sending a specific token - const web3 = getWeb3(providerUrl); - return new web3.eth.Contract(erc20Abi, tokenAddress, { - from: fromAddress, - }); -}; - -export const getContractDecimals = async ( - providerUrl: string, - address: string, -): Promise => { - const erc20Contract = getContract(providerUrl, address); - const decimals = await erc20Contract.methods.decimals.call([]).call(); - return Number(decimals); -}; - -export const getWeb3 = (providerUrl: string): Web3 => { - return new Web3(providerUrl); -}; diff --git a/packages/ui-components/src/locales/en.json b/packages/ui-components/src/locales/en.json index 871c6eb9..a5ac8594 100644 --- a/packages/ui-components/src/locales/en.json +++ b/packages/ui-components/src/locales/en.json @@ -924,8 +924,8 @@ "onboardSuccessTitle": "Creating your wallet. Leave this window open until complete...", "onboardWithEmailDescription": "## Create wallet\nEnter your email address and select a password for your new wallet.", "readyToUse": "Sign in successful! Your wallet is ready to use, click to open.", - "receiveAddressCaption": "**Warning: Only send supported tokens.** This address can only receive {{symbol}} on the {{blockchain}} network.", - "receiveAddressCaptionWithDomains": "**Warning: Only send supported tokens.** This address can only receive {{symbol}} tokens, ERC-20 tokens and Unstoppable Domains NFTs on the {{blockchain}} network.", + "receiveAddressCaption": "**Warning: Use supported tokens.** This address can only receive {{symbol}} on the {{blockchain}} network.", + "receiveAddressCaptionWithDomains": "**Warning: Use supported tokens.** This address can only receive {{symbol}} and Unstoppable Domains NFTs on the {{blockchain}} network.", "recipient": "Recipient", "recipientDomainEmailOrWallet": "Recipient domain, email or wallet", "recipientDomainOrAddress": "Recipient domain or wallet address", @@ -952,7 +952,7 @@ "selectAssetToReceive": "Select crypto to receive", "selectAssetToSend": "Select crypto to send", "sendByEmail": "Send to email address", - "sendingForOtherNetworksAndTokens": "Sending unsupported tokens may result in a loss of funds.", + "sendingForOtherNetworksAndTokens": "Sending {{symbol}} for other networks or other {{blockchain}} tokens is not yet supported and may result in a loss of funds.", "sendTransactionFailed": "{{amount}} {{sourceSymbol}} failed to send to {{recipientDomain}}", "sendTransactionSuccess": "{{amount}} {{sourceSymbol}} was successfully sent to {{recipientDomain}}", "signDappOperationDescription": "**{{name}}** wants to **{{actionText}}**. Verify the following details before confirming.", diff --git a/packages/ui-components/src/tests/mocks/wallet.ts b/packages/ui-components/src/tests/mocks/wallet.ts index 1e57df22..c54db5d9 100644 --- a/packages/ui-components/src/tests/mocks/wallet.ts +++ b/packages/ui-components/src/tests/mocks/wallet.ts @@ -22,7 +22,6 @@ export const mockAccountAsset = (): AccountAsset => { blockchain: { id: 'ETH', name: 'Ethereum', - networkId: 1, }, }, accountId: '', diff --git a/yarn.lock b/yarn.lock index 6a7b1809..5c3d3442 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5393,7 +5393,6 @@ __metadata: "@xmtp/content-type-text": ^1.0.0 "@xmtp/proto": ^3.62.1 "@xmtp/xmtp-js": 12.1.0 - abitype: ^1.0.6 bip322-js: ^1.1.0 bitcoin-address-validation: ^2.2.3 bluebird: ^3.7.2 @@ -6472,21 +6471,6 @@ __metadata: languageName: node linkType: hard -"abitype@npm:^1.0.6": - version: 1.0.6 - resolution: "abitype@npm:1.0.6" - peerDependencies: - typescript: ">=5.0.4" - zod: ^3 >=3.22.0 - peerDependenciesMeta: - typescript: - optional: true - zod: - optional: true - checksum: 0bf6ed5ec785f372746c3ec5d6c87bf4d8cf0b6db30867b8d24e86fbc66d9f6599ae3d463ccd49817e67eedec6deba7cdae317bcf4da85b02bc48009379b9f84 - languageName: node - linkType: hard - "abort-controller@npm:^3.0.0": version: 3.0.0 resolution: "abort-controller@npm:3.0.0"