From 5c9036b11f78033e4d8c66f2be8164c64e1a929f Mon Sep 17 00:00:00 2001 From: siandreev Date: Mon, 6 Jan 2025 15:55:49 +0100 Subject: [PATCH] fix: transfer notification for tron in twa --- .../components/transfer/SendNotifications.tsx | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/apps/twa/src/components/transfer/SendNotifications.tsx b/apps/twa/src/components/transfer/SendNotifications.tsx index b598ebdd9..60a01b8f7 100644 --- a/apps/twa/src/components/transfer/SendNotifications.tsx +++ b/apps/twa/src/components/transfer/SendNotifications.tsx @@ -1,7 +1,6 @@ import { TransferInitParams } from '@tonkeeper/core/dist/AppSdk'; import { BLOCKCHAIN_NAME } from '@tonkeeper/core/dist/entries/crypto'; import { AssetAmount } from '@tonkeeper/core/dist/entries/crypto/asset/asset-amount'; -import { toTronAsset } from '@tonkeeper/core/dist/entries/crypto/asset/constants'; import { jettonToTonAsset } from '@tonkeeper/core/dist/entries/crypto/asset/ton-asset'; import { RecipientData } from '@tonkeeper/core/dist/entries/send'; import { @@ -34,7 +33,7 @@ import { useAppSdk } from '@tonkeeper/uikit/dist/hooks/appSdk'; import { openIosKeyboard } from '@tonkeeper/uikit/dist/hooks/ios'; import { useTranslation } from '@tonkeeper/uikit/dist/hooks/translation'; import { useJettonList } from '@tonkeeper/uikit/dist/state/jetton'; -import { useTronBalances } from '@tonkeeper/uikit/dist/state/tron/tron'; +import { useActiveTronWallet, useTronBalances } from "@tonkeeper/uikit/dist/state/tron/tron"; import BigNumber from 'bignumber.js'; import { FC, PropsWithChildren, useCallback, useEffect, useMemo, useRef, useState } from "react"; import { CSSTransition, TransitionGroup } from 'react-transition-group'; @@ -52,6 +51,8 @@ import { RecipientTwaHeaderBlock } from './SendNotificationHeader'; import { useAnalyticsTrack } from '@tonkeeper/uikit/dist/hooks/amplitude'; +import { TRON_USDT_ASSET } from "@tonkeeper/core/dist/entries/crypto/asset/constants"; +import { seeIfValidTronAddress } from "@tonkeeper/core/dist/utils/common"; const Body = styled.div` padding: 0 16px 16px; @@ -93,10 +94,10 @@ const SendContent: FC<{ } }, []); - const { data: tronBalances } = useTronBalances(); - const { mutateAsync: getAccountAsync, isLoading: isAccountLoading } = useGetToAccount(); + const activeTronWallet = useActiveTronWallet(); + const setRecipient = (value: RecipientData) => { if ( amountViewState?.token?.blockchain && @@ -106,8 +107,8 @@ const SendContent: FC<{ } _setRecipient(value); - if (tronBalances && value.address.blockchain === BLOCKCHAIN_NAME.TRON) { - setAmountViewState({ token: toTronAsset(tronBalances.balances[0]) }); + if (activeTronWallet && value.address.blockchain === BLOCKCHAIN_NAME.TRON) { + setAmountViewState({ token: TRON_USDT_ASSET }); } }; @@ -152,6 +153,9 @@ const SendContent: FC<{ }; const processTron = (address: string) => { + if (!activeTronWallet) { + return; + } const item = { address: address, blockchain: BLOCKCHAIN_NAME.TRON } as const; setRecipient({ @@ -228,10 +232,9 @@ const SendContent: FC<{ return; } - // TODO: ENABLE TRON - // if (seeIfValidTronAddress(signature)) { - // return processTron(signature); - // } + if (seeIfValidTronAddress(signature)) { + return processTron(signature); + } return sdk.uiEvents.emit('copy', { method: 'copy', @@ -258,6 +261,19 @@ const SendContent: FC<{ }); }, [amountViewState?.token, amountViewState?.coinValue]); + let acceptBlockchains: BLOCKCHAIN_NAME[] = []; + if (chain) { + if (chain === BLOCKCHAIN_NAME.TRON && !activeTronWallet) { + acceptBlockchains = [BLOCKCHAIN_NAME.TON]; + } else { + acceptBlockchains = [chain]; + } + } else { + acceptBlockchains = activeTronWallet + ? [BLOCKCHAIN_NAME.TON, BLOCKCHAIN_NAME.TRON] + : [BLOCKCHAIN_NAME.TON]; + } + return ( @@ -279,7 +295,7 @@ const SendContent: FC<{ onScan={onScan} keyboard="decimal" isExternalLoading={isAccountLoading} - acceptBlockchains={chain ? [chain] : undefined} + acceptBlockchains={acceptBlockchains} MainButton={RecipientTwaMainButton} HeaderBlock={() => } fitContent @@ -348,6 +364,13 @@ export const TwaSendNotification: FC = ({ children }) => { reset(); const transfer = options.params; setChain(chain); + + if (transfer.chain === BLOCKCHAIN_NAME.TRON) { + setOpen(true); + track('send_open', { from: transfer.from }); + return; + } + if (transfer.address) { getAccountAsync({ address: transfer.address }).then(account => { setTonTransfer(makeTransferInitData(transfer, account, jettons));