From a379680c164ac5ee86ba24e73c0503d98c0b1790 Mon Sep 17 00:00:00 2001 From: aidencao Date: Mon, 11 Nov 2024 10:34:04 +0800 Subject: [PATCH 01/29] feat(canonical-bridge-server): Update keepalive timeout --- apps/canonical-bridge-server/src/main.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/canonical-bridge-server/src/main.ts b/apps/canonical-bridge-server/src/main.ts index 7968ee17..793c8338 100644 --- a/apps/canonical-bridge-server/src/main.ts +++ b/apps/canonical-bridge-server/src/main.ts @@ -38,8 +38,8 @@ async function bootstrap() { logger.log('Listening on port', SERVER_PORT); }); - server.keepAliveTimeout = 61 * 1000; - server.headersTimeout = 62 * 1000; + server.keepAliveTimeout = 121 * 1000; + server.headersTimeout = 122 * 1000; } bootstrap(); From a67b1102698a68aa32f41c730046c3d7aae0f50b Mon Sep 17 00:00:00 2001 From: wenty22 Date: Mon, 11 Nov 2024 16:01:15 +0800 Subject: [PATCH 02/29] fix: Show solana native token balance --- common/config/rush/pnpm-lock.yaml | 10 ++--- packages/canonical-bridge-widget/package.json | 2 +- .../aggregator/shared/getTokenBalances.ts | 39 ++++++++++++------- .../transfer/components/ToAccount/index.tsx | 2 +- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 8b20f718..989428b7 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -304,8 +304,8 @@ importers: specifier: ~11.13.0 version: 11.13.0(@emotion/react@11.13.3(@types/react@18.3.8)(react@18.3.1)(supports-color@9.4.0))(@types/react@18.3.8)(react@18.3.1)(supports-color@9.4.0) '@node-real/walletkit': - specifier: 2.4.1-alpha.0 - version: 2.4.1-alpha.0(@babel/runtime@7.25.0)(@react-native-async-storage/async-storage@1.24.0)(@tanstack/react-query@5.50.1(react@18.3.1))(@types/react@18.3.8)(bs58@6.0.0)(bufferutil@4.0.8)(encoding@0.1.13)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(tslib@2.7.0)(typescript@5.5.4)(utf-8-validate@5.0.9)(viem@2.21.14(bufferutil@4.0.8)(typescript@5.5.4)(utf-8-validate@5.0.9)(zod@3.22.4))(wagmi@2.12.14(@react-native-async-storage/async-storage@1.24.0)(@tanstack/query-core@5.50.1)(@tanstack/react-query@5.50.1(react@18.3.1))(@types/react@18.3.8)(bufferutil@4.0.8)(encoding@0.1.13)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(rollup@3.29.4)(typescript@5.5.4)(utf-8-validate@5.0.9)(viem@2.21.14(bufferutil@4.0.8)(typescript@5.5.4)(utf-8-validate@5.0.9)(zod@3.22.4))(zod@3.22.4))(zod@3.22.4) + specifier: 2.4.1-alpha.1 + version: 2.4.1-alpha.1(@babel/runtime@7.25.0)(@react-native-async-storage/async-storage@1.24.0)(@tanstack/react-query@5.50.1(react@18.3.1))(@types/react@18.3.8)(bs58@6.0.0)(bufferutil@4.0.8)(encoding@0.1.13)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(tslib@2.7.0)(typescript@5.5.4)(utf-8-validate@5.0.9)(viem@2.21.14(bufferutil@4.0.8)(typescript@5.5.4)(utf-8-validate@5.0.9)(zod@3.22.4))(wagmi@2.12.14(@react-native-async-storage/async-storage@1.24.0)(@tanstack/query-core@5.50.1)(@tanstack/react-query@5.50.1(react@18.3.1))(@types/react@18.3.8)(bufferutil@4.0.8)(encoding@0.1.13)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(rollup@3.29.4)(typescript@5.5.4)(utf-8-validate@5.0.9)(viem@2.21.14(bufferutil@4.0.8)(typescript@5.5.4)(utf-8-validate@5.0.9)(zod@3.22.4))(zod@3.22.4))(zod@3.22.4) '@tanstack/react-query': specifier: ~5.50.1 version: 5.50.1(react@18.3.1) @@ -2993,8 +2993,8 @@ packages: viem: ^2 wagmi: ^2 - '@node-real/walletkit@2.4.1-alpha.0': - resolution: {integrity: sha512-rl/uXrktICOROw4cGWXAmIdA9Hw8QlBW/GVYts2ucSJuwrST0EInM10Z7jwNCdJyn1ANDwzB5L/lA41BDJPafA==} + '@node-real/walletkit@2.4.1-alpha.1': + resolution: {integrity: sha512-1IBDDYb6b6EqytQxCqp5BdztMp3V2XR+numoyzdASYE8eoDEEEhfTv6fB8t11MFKzauIQGTWbVDHyM39hDlUxw==} peerDependencies: '@tanstack/react-query': ^5 react: '>=17' @@ -15978,7 +15978,7 @@ snapshots: - utf-8-validate - zod - '@node-real/walletkit@2.4.1-alpha.0(@babel/runtime@7.25.0)(@react-native-async-storage/async-storage@1.24.0)(@tanstack/react-query@5.50.1(react@18.3.1))(@types/react@18.3.8)(bs58@6.0.0)(bufferutil@4.0.8)(encoding@0.1.13)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(tslib@2.7.0)(typescript@5.5.4)(utf-8-validate@5.0.9)(viem@2.21.14(bufferutil@4.0.8)(typescript@5.5.4)(utf-8-validate@5.0.9)(zod@3.22.4))(wagmi@2.12.14(@react-native-async-storage/async-storage@1.24.0)(@tanstack/query-core@5.50.1)(@tanstack/react-query@5.50.1(react@18.3.1))(@types/react@18.3.8)(bufferutil@4.0.8)(encoding@0.1.13)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(rollup@3.29.4)(typescript@5.5.4)(utf-8-validate@5.0.9)(viem@2.21.14(bufferutil@4.0.8)(typescript@5.5.4)(utf-8-validate@5.0.9)(zod@3.22.4))(zod@3.22.4))(zod@3.22.4)': + '@node-real/walletkit@2.4.1-alpha.1(@babel/runtime@7.25.0)(@react-native-async-storage/async-storage@1.24.0)(@tanstack/react-query@5.50.1(react@18.3.1))(@types/react@18.3.8)(bs58@6.0.0)(bufferutil@4.0.8)(encoding@0.1.13)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(tslib@2.7.0)(typescript@5.5.4)(utf-8-validate@5.0.9)(viem@2.21.14(bufferutil@4.0.8)(typescript@5.5.4)(utf-8-validate@5.0.9)(zod@3.22.4))(wagmi@2.12.14(@react-native-async-storage/async-storage@1.24.0)(@tanstack/query-core@5.50.1)(@tanstack/react-query@5.50.1(react@18.3.1))(@types/react@18.3.8)(bufferutil@4.0.8)(encoding@0.1.13)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(rollup@3.29.4)(typescript@5.5.4)(utf-8-validate@5.0.9)(viem@2.21.14(bufferutil@4.0.8)(typescript@5.5.4)(utf-8-validate@5.0.9)(zod@3.22.4))(zod@3.22.4))(zod@3.22.4)': dependencies: '@metamask/jazzicon': 2.0.0 '@solana/wallet-adapter-react': 0.15.35(@solana/web3.js@1.95.4(bufferutil@4.0.8)(encoding@0.1.13)(utf-8-validate@5.0.9))(bs58@6.0.0)(react@18.3.1) diff --git a/packages/canonical-bridge-widget/package.json b/packages/canonical-bridge-widget/package.json index 34187212..1da97e61 100644 --- a/packages/canonical-bridge-widget/package.json +++ b/packages/canonical-bridge-widget/package.json @@ -45,7 +45,7 @@ "@bnb-chain/space": "workspace:*", "@emotion/react": "~11.13.0", "@emotion/styled": "~11.13.0", - "@node-real/walletkit": "2.4.1-alpha.0", + "@node-real/walletkit": "2.4.1-alpha.1", "@tanstack/react-query": "~5.50.1", "@types/lodash": "~4.17.7", "@types/node": "^20", diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/shared/getTokenBalances.ts b/packages/canonical-bridge-widget/src/modules/aggregator/shared/getTokenBalances.ts index 239db51b..1f3e6002 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/shared/getTokenBalances.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/shared/getTokenBalances.ts @@ -1,7 +1,7 @@ import { Address, Chain, createPublicClient, formatUnits, http } from 'viem'; import { TronWeb } from 'tronweb'; import * as SPLToken from '@solana/spl-token'; -import { Connection, PublicKey } from '@solana/web3.js'; +import { Connection, LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js'; import { TOKEN_PROGRAM_ID } from '@solana/spl-token'; import axios from 'axios'; @@ -192,24 +192,33 @@ async function getSolanaTokenBalances({ if (!account || !tokens?.length || !connection) { return {}; } - const balances: Record = {}; // https://stackoverflow.com/questions/69700173/solana-check-all-spl-token-balances-of-a-wallet - const res = await connection.getTokenAccountsByOwner(new PublicKey(account), { - programId: TOKEN_PROGRAM_ID, - }); + const [splTokensRes, nativeTokenRes] = await Promise.allSettled([ + connection.getTokenAccountsByOwner(new PublicKey(account), { + programId: TOKEN_PROGRAM_ID, + }), + connection.getBalance(new PublicKey(account!)), + ]); - res?.value?.forEach((e) => { - const accountInfo = SPLToken.AccountLayout.decode(e.account.data); + const balances: Record = {}; + if (splTokensRes.status === 'fulfilled') { + splTokensRes.value?.value?.forEach((e) => { + const accountInfo = SPLToken.AccountLayout.decode(e.account.data); + + const token = tokens.find((t) => isSameAddress(t.address, accountInfo.mint.toBase58())); + if (token) { + balances[token.displaySymbol.toUpperCase()] = formatUnits( + accountInfo.amount, + token.decimals, + ); + } + }); + } - const token = tokens.find((t) => isSameAddress(t.address, accountInfo.mint.toBase58())); - if (token) { - balances[token.displaySymbol.toUpperCase()] = formatUnits( - accountInfo.amount, - token.decimals, - ); - } - }); + if (nativeTokenRes.status === 'fulfilled') { + balances['SOL'] = String(nativeTokenRes.value / LAMPORTS_PER_SOL); + } tokens.forEach((t) => { const key = t.displaySymbol.toUpperCase(); diff --git a/packages/canonical-bridge-widget/src/modules/transfer/components/ToAccount/index.tsx b/packages/canonical-bridge-widget/src/modules/transfer/components/ToAccount/index.tsx index 6d580e08..0bae50f8 100644 --- a/packages/canonical-bridge-widget/src/modules/transfer/components/ToAccount/index.tsx +++ b/packages/canonical-bridge-widget/src/modules/transfer/components/ToAccount/index.tsx @@ -60,7 +60,7 @@ export function ToAccount(props: FlexProps) { if (!toAccount.address) setInputValue(''); }, [toAccount.address]); - const { isInvalid, isAvailableAccount } = useMemo(() => { + const { isInvalid } = useMemo(() => { if (isTronTransfer) { return { isInvalid: From aeadcfe8395513c9636ca83311eb1c63f52af521 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 7 Nov 2024 18:28:13 +1000 Subject: [PATCH 03/29] chore: Add class name WIP --- .../components/Button/RefreshingButton.tsx | 1 + .../transfer/components/FromSection/index.tsx | 10 +++++++++- .../components/NetWorkSection/index.tsx | 16 ++++++++++++++-- .../transfer/components/SelectButton/index.tsx | 2 ++ .../transfer/components/ToSection/index.tsx | 10 +++++++++- .../RouteInfo/AllowedSendAmount.tsx | 1 + .../RouteInfo/EstimatedArrivalTime.tsx | 5 +++-- .../TransferOverview/RouteInfo/FeeBreakdown.tsx | 7 ++++++- .../TransferOverview/RouteInfo/FeesInfo.tsx | 3 +++ .../RouteInfo/OtherRouteError.tsx | 1 + .../RouteInfo/RouteName/BestRouteTag.tsx | 1 + .../RouteInfo/RouteName/index.tsx | 2 ++ .../RouteInfo/RouteSkeleton.tsx | 1 + .../TransferOverview/RouteInfo/RouteTitle.tsx | 10 +++++++++- .../TransferOverview/RouteInfo/RouteWrapper.tsx | 1 + .../RouteInfo/TokenInfoTooltip.tsx | 2 +- .../components/TransferOverview/index.tsx | 17 ++++++++++++++--- .../TransferOverview/modal/RoutesModal.tsx | 11 +++++++++-- .../src/modules/transfer/index.tsx | 2 ++ 19 files changed, 89 insertions(+), 14 deletions(-) diff --git a/packages/canonical-bridge-widget/src/modules/transfer/components/Button/RefreshingButton.tsx b/packages/canonical-bridge-widget/src/modules/transfer/components/Button/RefreshingButton.tsx index cae4f583..81adfeb7 100644 --- a/packages/canonical-bridge-widget/src/modules/transfer/components/Button/RefreshingButton.tsx +++ b/packages/canonical-bridge-widget/src/modules/transfer/components/Button/RefreshingButton.tsx @@ -66,6 +66,7 @@ export const RefreshingButton = (props: BoxProps) => { return transferActionInfo ? ( + { const theme = useTheme(); return ( - + - + {formatMessage({ id: 'from.section.title' })} { {' '} state.transfer.toChain); return ( - + - + {formatMessage({ id: 'route.time.title' })} {waitingTime ? ( - + ~{formatEstimatedTime(waitingTime)} ) : ( diff --git a/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/RouteInfo/FeeBreakdown.tsx b/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/RouteInfo/FeeBreakdown.tsx index c961bde0..2fee40aa 100644 --- a/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/RouteInfo/FeeBreakdown.tsx +++ b/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/RouteInfo/FeeBreakdown.tsx @@ -4,7 +4,12 @@ export const FeeBreakdown = ({ title, value }: { title: string; value: string }) const theme = useTheme(); // TODO: Use colorMode return ( - + {title} diff --git a/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/RouteInfo/FeesInfo.tsx b/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/RouteInfo/FeesInfo.tsx index 1145390b..836fc034 100644 --- a/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/RouteInfo/FeesInfo.tsx +++ b/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/RouteInfo/FeesInfo.tsx @@ -18,6 +18,7 @@ export const FeesInfo = ({ summary, breakdown, bridgeType, isError }: FeesInfoPr const { formatMessage } = useIntl(); return ( { const routeError = useAppSelector((state) => state.transfer.routeError); return routeError && routeError[bridgeType] ? ( { const { formatMessage } = useIntl(); return ( { return ( + isNativeToken(tokenAddress), [tokenAddress]); return ( - + {children} diff --git a/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/index.tsx b/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/index.tsx index 0254bf20..aa0ce8d8 100644 --- a/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/index.tsx +++ b/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/index.tsx @@ -118,6 +118,7 @@ export function TransferOverview({ routeContentBottom }: { routeContentBottom?: > ) : ( - + {options?.map((bridge: ReactNode) => bridge)} )} @@ -173,7 +175,14 @@ export function TransferOverview({ routeContentBottom }: { routeContentBottom?: transition={'width 0.15s'} > {cBridgeSupport && } - + + {!routeContentBottom ? ( content ) : ( @@ -183,7 +192,9 @@ export function TransferOverview({ routeContentBottom }: { routeContentBottom?: )} - {routeContentBottom ? routeContentBottom : null} + + {routeContentBottom ? routeContentBottom : null} + ); diff --git a/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/modal/RoutesModal.tsx b/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/modal/RoutesModal.tsx index 3d715d09..268c7d26 100644 --- a/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/modal/RoutesModal.tsx +++ b/packages/canonical-bridge-widget/src/modules/transfer/components/TransferOverview/modal/RoutesModal.tsx @@ -16,8 +16,9 @@ export function RoutesModal(props: RoutesModalProps) { return ( - + - + {children} diff --git a/packages/canonical-bridge-widget/src/modules/transfer/index.tsx b/packages/canonical-bridge-widget/src/modules/transfer/index.tsx index 09a1c4c6..aca0cf0a 100644 --- a/packages/canonical-bridge-widget/src/modules/transfer/index.tsx +++ b/packages/canonical-bridge-widget/src/modules/transfer/index.tsx @@ -35,6 +35,7 @@ export function TransferWidget() { <> Date: Mon, 11 Nov 2024 12:32:37 +1000 Subject: [PATCH 04/29] chore: Add more class name --- .../core/components/ConfirmCheckbox/index.tsx | 69 ------------------- .../src/core/components/CopyAddress/index.tsx | 8 ++- .../src/core/components/InfoTooltip/index.tsx | 1 + .../src/core/components/StateModal/index.tsx | 12 +++- .../src/core/components/VirtualList/index.tsx | 5 +- .../components/icons/ConfirmCheckIcon.tsx | 7 +- .../src/core/locales/en.ts | 1 - .../SelectModal/ChooseTokenModal.tsx | 9 ++- .../SelectModal/DestinationNetworkModal.tsx | 4 +- .../SelectModal/SourceNetworkModal.tsx | 4 +- .../SelectModal/components/BaseModal.tsx | 10 ++- .../SelectModal/components/ListItem.tsx | 1 + .../SelectModal/components/NoResultFound.tsx | 19 ++++- .../SelectModal/components/SearchInput.tsx | 1 + .../components/Button/ExchangeChain.tsx | 1 + .../components/Button/SwitchNetworkButton.tsx | 1 + .../components/Button/SwitchWalletButton.tsx | 1 + .../components/Button/TransferButton.tsx | 2 +- .../components/Button/WalletConnectButton.tsx | 1 + .../components/ExternalTokenAddress/index.tsx | 43 ------------ .../Modal/TransactionApproveModal/index.tsx | 2 + .../TransactionConfirmingModal/index.tsx | 1 + .../Modal/TransactionFailedModal/index.tsx | 1 + .../Modal/TransactionSubmittedModal/index.tsx | 2 + .../components/ReceiveInfo/ReceiveLoading.tsx | 6 +- .../transfer/components/ReceiveInfo/index.tsx | 8 ++- .../SelectButton/TokenSelectButton.tsx | 1 + .../SendInput/InputValidationMessage.tsx | 1 + .../transfer/components/SendInput/MaxLink.tsx | 2 +- .../transfer/components/SendInput/index.tsx | 3 +- .../transfer/components/ToAccount/index.tsx | 22 +++++- .../components/TransferButtonGroup/index.tsx | 6 +- .../TransferOverview/NoRouteFound.tsx | 13 +++- .../components/TransferOverview/index.tsx | 1 + .../src/modules/wallet/WalletProvider.tsx | 1 + .../wallet/components/ConnectButton/index.tsx | 7 +- .../components/Dropdown/DropdownButton.tsx | 1 + .../components/Dropdown/DropdownItem.tsx | 1 + .../components/Dropdown/DropdownList.tsx | 1 + .../wallet/components/NetworkStatus/index.tsx | 3 +- .../wallet/components/ProfileMenu/index.tsx | 4 +- .../components/SwitchingTipsModal/index.tsx | 1 + 42 files changed, 143 insertions(+), 145 deletions(-) delete mode 100644 packages/canonical-bridge-widget/src/core/components/ConfirmCheckbox/index.tsx delete mode 100644 packages/canonical-bridge-widget/src/modules/transfer/components/ExternalTokenAddress/index.tsx diff --git a/packages/canonical-bridge-widget/src/core/components/ConfirmCheckbox/index.tsx b/packages/canonical-bridge-widget/src/core/components/ConfirmCheckbox/index.tsx deleted file mode 100644 index 5e2ed4f9..00000000 --- a/packages/canonical-bridge-widget/src/core/components/ConfirmCheckbox/index.tsx +++ /dev/null @@ -1,69 +0,0 @@ -import { Checkbox, CheckboxProps, theme, useColorMode } from '@bnb-chain/space'; - -export const ConfirmCheckbox: React.FC = (props: CheckboxProps) => { - const { colorMode } = useColorMode(); - - const { isChecked } = props; - - return ( - - ); -}; diff --git a/packages/canonical-bridge-widget/src/core/components/CopyAddress/index.tsx b/packages/canonical-bridge-widget/src/core/components/CopyAddress/index.tsx index 9bc3adee..4d30a6ff 100644 --- a/packages/canonical-bridge-widget/src/core/components/CopyAddress/index.tsx +++ b/packages/canonical-bridge-widget/src/core/components/CopyAddress/index.tsx @@ -27,7 +27,13 @@ export const CopyAddress = ({ return null; } return ( - + { return ( { bodyProps?: ModalBodyProps; mainButtonIsDisabled?: boolean; closeButtonIsDisabled?: boolean; + className?: string; } export function StateModal(props: StateModalProps) { @@ -58,6 +59,7 @@ export function StateModal(props: StateModalProps) { mainButtonIsDisabled = false, closeButtonIsDisabled = false, onClose, + className, mainButtonProps, bodyProps, footerProps, @@ -76,8 +78,9 @@ export function StateModal(props: StateModalProps) { - + - {icon} + {icon} {description && ( {mainButtonText && (