diff --git a/packages/extension-koni-ui/src/Popup/Transaction/variants/SendFund.tsx b/packages/extension-koni-ui/src/Popup/Transaction/variants/SendFund.tsx index 26058892c0..724df72f1a 100644 --- a/packages/extension-koni-ui/src/Popup/Transaction/variants/SendFund.tsx +++ b/packages/extension-koni-ui/src/Popup/Transaction/variants/SendFund.tsx @@ -8,13 +8,13 @@ import { _getAssetDecimals, _getOriginChainOfAsset, _getTokenMinAmount, _isAsset import { SWTransactionResponse } from '@subwallet/extension-base/services/transaction-service/types'; import { BitcoinFeeDetail, ResponseSubscribeTransfer, TransactionFee } from '@subwallet/extension-base/types'; import { BN_ZERO, detectTranslate } from '@subwallet/extension-base/utils'; -import { AccountSelector, AddressInput, AlertBox, AlertModal, AmountInput, BitcoinFeeSelector, ChainSelector, HiddenInput, TokenItemType, TokenSelector } from '@subwallet/extension-koni-ui/components'; +import { AccountSelector, AddressInput, AlertBox, AlertModal, AmountInput, BitcoinFeeSelector, HiddenInput, TokenItemType, TokenSelector } from '@subwallet/extension-koni-ui/components'; import { BITCOIN_CHAINS, SUPPORT_CHAINS } from '@subwallet/extension-koni-ui/constants'; import { useAlert, useFetchChainAssetInfo, useGetChainPrefixBySlug, useGetNativeTokenBasicInfo, useHandleSubmitTransaction, useInitValidateTransaction, useNotification, usePreCheckAction, useRestoreTransaction, useSelector, useSetCurrentPage, useTransactionContext, useWatchTransaction } from '@subwallet/extension-koni-ui/hooks'; import { cancelSubscription, makeCrossChainTransfer, makeTransfer, subscribeMaxTransfer } from '@subwallet/extension-koni-ui/messaging'; import { FreeBalance } from '@subwallet/extension-koni-ui/Popup/Transaction/parts'; import { RootState } from '@subwallet/extension-koni-ui/stores'; -import { ChainItemType, FormCallbacks, Theme, ThemeProps, TransferParams } from '@subwallet/extension-koni-ui/types'; +import { FormCallbacks, Theme, ThemeProps, TransferParams } from '@subwallet/extension-koni-ui/types'; import { findAccountByAddress, formatBalance, noop, reformatAddress } from '@subwallet/extension-koni-ui/utils'; import { getKeypairTypeByAddress } from '@subwallet/keyring'; import { KeypairType } from '@subwallet/keyring/types'; @@ -22,7 +22,7 @@ import { Button, Form, Icon, Number } from '@subwallet/react-ui'; import { Rule } from '@subwallet/react-ui/es/form'; import BigN from 'bignumber.js'; import CN from 'classnames'; -import { PaperPlaneRight, PaperPlaneTilt } from 'phosphor-react'; +import { PaperPlaneTilt } from 'phosphor-react'; import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import styled from 'styled-components'; @@ -52,10 +52,6 @@ function getTokenItems ( multiChainAssetMap: Record, tokenGroupSlug?: string // is ether a token slug or a multiChainAsset slug ): TokenItemType[] { - if (!address) { - return []; - } - const isSetTokenSlug = !!tokenGroupSlug && !!assetRegistry[tokenGroupSlug]; const isSetMultiChainAssetSlug = !!tokenGroupSlug && !!multiChainAssetMap[tokenGroupSlug]; const addressType = getKeypairTypeByAddress(address); @@ -94,9 +90,9 @@ function getTokenItems ( return; } - if (!checkValidBetweenAddressTypeAndChain(addressType, chainAsset.originChain)) { - return; - } + // if (!checkValidBetweenAddressTypeAndChain(addressType, chainAsset.originChain)) { + // return; + // } if (isSetMultiChainAssetSlug) { if (chainAsset.multiChainAsset === tokenGroupSlug) { @@ -128,34 +124,6 @@ function getTokenItems ( }); } -function getTokenAvailableDestinations (tokenSlug: string, xcmRefMap: Record, chainInfoMap: Record): ChainItemType[] { - if (!tokenSlug) { - return []; - } - - const result: ChainItemType[] = []; - const originChain = chainInfoMap[_getOriginChainOfAsset(tokenSlug)]; - - // Firstly, push the originChain of token - result.push({ - name: originChain.name, - slug: originChain.slug - }); - - Object.values(xcmRefMap).forEach((xcmRef) => { - if (xcmRef.srcAsset === tokenSlug) { - const destinationChain = chainInfoMap[xcmRef.destChain]; - - result.push({ - name: destinationChain.name, - slug: destinationChain.slug - }); - } - }); - - return result; -} - const hiddenFields: Array = ['chain', 'fromProxyId']; const validateFields: Array = ['value', 'to']; const alertModalId = 'confirmation-alert-modal'; @@ -187,7 +155,7 @@ const _SendFund = ({ className = '' }: Props): React.ReactElement => { const { alertProps, closeAlert, openAlert } = useAlert(alertModalId); const { chainInfoMap, chainStatusMap } = useSelector((root) => root.chainStore); - const { assetRegistry, multiChainAssetMap, xcmRefMap } = useSelector((root) => root.assetRegistry); + const { assetRegistry, multiChainAssetMap } = useSelector((root) => root.assetRegistry); const { accounts } = useSelector((state: RootState) => state.accountState); const destChainNetworkPrefix = useGetChainPrefixBySlug(destChainValue); @@ -206,10 +174,6 @@ const _SendFund = ({ className = '' }: Props): React.ReactElement => { const chainStatus = useMemo(() => chainStatusMap[chainValue]?.connectionStatus, [chainValue, chainStatusMap]); - const destChainItems = useMemo(() => { - return getTokenAvailableDestinations(assetValue, xcmRefMap, chainInfoMap); - }, [chainInfoMap, assetValue, xcmRefMap]); - const currentChainAsset = useMemo(() => { const _asset = isFirstRender ? defaultData.asset : assetValue; @@ -504,8 +468,16 @@ const _SendFund = ({ className = '' }: Props): React.ReactElement => { const addressBookFilter = useCallback((addressJson: AbstractAddressJson): boolean => { const addressType = getKeypairTypeByAddress(addressJson.address); + if (chainValue === 'bitcoin') { + return 'bitcoin-84'.includes(addressType) && addressJson.address !== fromValue; + } else if (chainValue === 'bitcoinTestnet') { + return 'bittest-84'.includes(addressType) && addressJson.address !== fromValue; + } else if (chainValue === 'ethereum') { + return 'ethereum'.includes(addressType) && addressJson.address !== fromValue; + } + return ['ethereum', 'bitcoin-84', 'bittest-84'].includes(addressType); - }, []); + }, [chainValue, fromValue]); // TODO: Need to review // Auto fill logic @@ -605,8 +577,16 @@ const _SendFund = ({ className = '' }: Props): React.ReactElement => { const accountType = account.type || getKeypairTypeByAddress(account.address); + if (chainValue === 'bitcoin') { + return 'bitcoin-84'.includes(accountType); + } else if (chainValue === 'bitcoinTestnet') { + return 'bittest-84'.includes(accountType); + } else if (chainValue === 'ethereum') { + return 'ethereum'.includes(accountType); + } + return ['ethereum', 'bitcoin-84', 'bittest-84'].includes(accountType); - }, [fromProxyId]); + }, [chainValue, fromProxyId]); useEffect(() => { const bnTransferAmount = new BigN(transferAmountValue || '0'); @@ -634,15 +614,6 @@ const _SendFund = ({ className = '' }: Props): React.ReactElement => { onFinish={onSubmit} onValuesChange={onValuesChange} > - - - -
=> { tooltip={t('Select token')} /> - - - - - -
+ + +