From 8c5d2d2f64483a28051e98b8769c08e4fbe99ec4 Mon Sep 17 00:00:00 2001 From: wenty22 Date: Tue, 3 Dec 2024 01:31:19 +0800 Subject: [PATCH 1/2] feat: Using metaMask sdk to avoid default wallet issue --- apps/canonical-bridge-ui/package.json | 2 +- common/config/rush/pnpm-lock.yaml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/canonical-bridge-ui/package.json b/apps/canonical-bridge-ui/package.json index 01771be5..7c626d5a 100644 --- a/apps/canonical-bridge-ui/package.json +++ b/apps/canonical-bridge-ui/package.json @@ -15,7 +15,7 @@ "@emotion/css": "~11.13.0", "@emotion/react": "~11.13.3", "@emotion/styled": "~11.13.0", - "@node-real/walletkit": "2.4.1-alpha.8", + "@node-real/walletkit": "2.6.1-alpha.0", "@solana/spl-token": "~0.4.9", "@solana/wallet-adapter-react": "~0.15.35", "@solana/web3.js": "~1.95.4", diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index d6031cf5..c018a47e 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -140,8 +140,8 @@ importers: specifier: ~11.13.0 version: 11.13.0(@emotion/react@11.13.3(@types/react@18.3.12)(react@18.3.1)(supports-color@9.4.0))(@types/react@18.3.12)(react@18.3.1)(supports-color@9.4.0) '@node-real/walletkit': - specifier: 2.4.1-alpha.8 - version: 2.4.1-alpha.8(@babel/core@7.26.0(supports-color@9.4.0))(@babel/runtime@7.26.0)(@react-native-async-storage/async-storage@1.24.0)(@tanstack/react-query@5.50.1(react@18.3.1))(bs58@6.0.0)(bufferutil@4.0.8)(encoding@0.1.13)(ioredis@5.4.1(supports-color@9.4.0))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(supports-color@9.4.0)(tslib@2.8.1)(utf-8-validate@5.0.10)(viem@2.21.48(bufferutil@4.0.8)(typescript@5.5.4)(utf-8-validate@5.0.10))(wagmi@2.12.33(@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.12)(bufferutil@4.0.8)(encoding@0.1.13)(ioredis@5.4.1(supports-color@9.4.0))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(supports-color@9.4.0)(typescript@5.5.4)(utf-8-validate@5.0.10)(viem@2.21.48(bufferutil@4.0.8)(typescript@5.5.4)(utf-8-validate@5.0.10))) + specifier: 2.6.1-alpha.0 + version: 2.6.1-alpha.0(@babel/core@7.26.0(supports-color@9.4.0))(@babel/runtime@7.26.0)(@react-native-async-storage/async-storage@1.24.0)(@tanstack/react-query@5.50.1(react@18.3.1))(bs58@6.0.0)(bufferutil@4.0.8)(encoding@0.1.13)(ioredis@5.4.1(supports-color@9.4.0))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(supports-color@9.4.0)(tslib@2.8.1)(utf-8-validate@5.0.10)(viem@2.21.48(bufferutil@4.0.8)(typescript@5.5.4)(utf-8-validate@5.0.10))(wagmi@2.12.33(@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.12)(bufferutil@4.0.8)(encoding@0.1.13)(ioredis@5.4.1(supports-color@9.4.0))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(supports-color@9.4.0)(typescript@5.5.4)(utf-8-validate@5.0.10)(viem@2.21.48(bufferutil@4.0.8)(typescript@5.5.4)(utf-8-validate@5.0.10))) '@solana/spl-token': specifier: ~0.4.9 version: 0.4.9(@solana/web3.js@1.95.4(bufferutil@4.0.8)(encoding@0.1.13)(utf-8-validate@5.0.10))(bufferutil@4.0.8)(encoding@0.1.13)(typescript@5.5.4)(utf-8-validate@5.0.10) @@ -2946,8 +2946,8 @@ packages: resolution: {integrity: sha512-1j6kQFb7QRru7eKN3ZDvRcP13rugwdxZqCjbiAVZfIJwgj2A65UmT4TgARXGlXgnRkORLTDTrO19ZErt7+QXgA==} engines: {node: ^14.21.3 || >=16} - '@node-real/walletkit@2.4.1-alpha.8': - resolution: {integrity: sha512-JfmA0yfdhAgeviPZjrgh3iJPXR0msE6XE556dwqyJbYF8d+IVzvvBmOPrJ5no+jl9jc25O/2OdF1mfr4kjuCYw==} + '@node-real/walletkit@2.6.1-alpha.0': + resolution: {integrity: sha512-4xhTrmPrOVbGa4r4m06HvxeFqqAUbJUSTGA2KZSW7068XelSo0LTHLhpbgX1cd0AaIyBbtL56is9hsC8KpzPnQ==} peerDependencies: '@tanstack/react-query': ^5 react: '>=17' @@ -15234,7 +15234,7 @@ snapshots: '@noble/hashes@1.5.0': {} - '@node-real/walletkit@2.4.1-alpha.8(@babel/core@7.26.0(supports-color@9.4.0))(@babel/runtime@7.26.0)(@react-native-async-storage/async-storage@1.24.0)(@tanstack/react-query@5.50.1(react@18.3.1))(bs58@6.0.0)(bufferutil@4.0.8)(encoding@0.1.13)(ioredis@5.4.1(supports-color@9.4.0))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(supports-color@9.4.0)(tslib@2.8.1)(utf-8-validate@5.0.10)(viem@2.21.48(bufferutil@4.0.8)(typescript@5.5.4)(utf-8-validate@5.0.10))(wagmi@2.12.33(@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.12)(bufferutil@4.0.8)(encoding@0.1.13)(ioredis@5.4.1(supports-color@9.4.0))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(supports-color@9.4.0)(typescript@5.5.4)(utf-8-validate@5.0.10)(viem@2.21.48(bufferutil@4.0.8)(typescript@5.5.4)(utf-8-validate@5.0.10)))': + '@node-real/walletkit@2.6.1-alpha.0(@babel/core@7.26.0(supports-color@9.4.0))(@babel/runtime@7.26.0)(@react-native-async-storage/async-storage@1.24.0)(@tanstack/react-query@5.50.1(react@18.3.1))(bs58@6.0.0)(bufferutil@4.0.8)(encoding@0.1.13)(ioredis@5.4.1(supports-color@9.4.0))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(supports-color@9.4.0)(tslib@2.8.1)(utf-8-validate@5.0.10)(viem@2.21.48(bufferutil@4.0.8)(typescript@5.5.4)(utf-8-validate@5.0.10))(wagmi@2.12.33(@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.12)(bufferutil@4.0.8)(encoding@0.1.13)(ioredis@5.4.1(supports-color@9.4.0))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(supports-color@9.4.0)(typescript@5.5.4)(utf-8-validate@5.0.10)(viem@2.21.48(bufferutil@4.0.8)(typescript@5.5.4)(utf-8-validate@5.0.10)))': 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.10))(bs58@6.0.0)(react@18.3.1) From 4f3d0beed1ed486684bc9543430315c2ed2f2dbc Mon Sep 17 00:00:00 2001 From: wenty22 Date: Wed, 4 Dec 2024 10:20:04 +0800 Subject: [PATCH 2/2] feat: Solve the cost calculation issue of solana --- .release/.changeset/poor-news-hear.md | 5 ++++ .release/.changeset/pre.json | 11 +++++++++ packages/canonical-bridge-widget/CHANGELOG.md | 6 +++++ packages/canonical-bridge-widget/package.json | 2 +- .../src/core/utils/address.ts | 2 +- .../deBridge/hooks/useGetDeBridgeFees.ts | 23 +++++++++++++++++++ 6 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 .release/.changeset/poor-news-hear.md create mode 100644 .release/.changeset/pre.json diff --git a/.release/.changeset/poor-news-hear.md b/.release/.changeset/poor-news-hear.md new file mode 100644 index 00000000..7feb5f67 --- /dev/null +++ b/.release/.changeset/poor-news-hear.md @@ -0,0 +1,5 @@ +--- +"@bnb-chain/canonical-bridge-widget": patch +--- + +Add address info to token list element diff --git a/.release/.changeset/pre.json b/.release/.changeset/pre.json new file mode 100644 index 00000000..3e141b23 --- /dev/null +++ b/.release/.changeset/pre.json @@ -0,0 +1,11 @@ +{ + "mode": "pre", + "tag": "alpha", + "initialVersions": { + "@bnb-chain/canonical-bridge-sdk": "0.4.2", + "@bnb-chain/canonical-bridge-widget": "0.5.5" + }, + "changesets": [ + "poor-news-hear" + ] +} diff --git a/packages/canonical-bridge-widget/CHANGELOG.md b/packages/canonical-bridge-widget/CHANGELOG.md index 0915dd58..4a5b647d 100644 --- a/packages/canonical-bridge-widget/CHANGELOG.md +++ b/packages/canonical-bridge-widget/CHANGELOG.md @@ -1,5 +1,11 @@ # @bnb-chain/canonical-bridge-widget +## 0.5.6-alpha.0 + +### Patch Changes + +- Add address info to token list element + ## 0.5.5 ### Patch Changes diff --git a/packages/canonical-bridge-widget/package.json b/packages/canonical-bridge-widget/package.json index 83a29389..8a5b3b1e 100644 --- a/packages/canonical-bridge-widget/package.json +++ b/packages/canonical-bridge-widget/package.json @@ -1,6 +1,6 @@ { "name": "@bnb-chain/canonical-bridge-widget", - "version": "0.5.5", + "version": "0.5.6-alpha.0", "description": "canonical bridge widget", "author": "bnb-chain", "private": false, diff --git a/packages/canonical-bridge-widget/src/core/utils/address.ts b/packages/canonical-bridge-widget/src/core/utils/address.ts index 89bf1b60..6147ccef 100644 --- a/packages/canonical-bridge-widget/src/core/utils/address.ts +++ b/packages/canonical-bridge-widget/src/core/utils/address.ts @@ -50,7 +50,7 @@ export function isEvmAddress(address?: string) { return !!address && /^0x[a-f0-9]{40}$/i.test(address); } -export function isNativeToken(tokenAddress: string, chainType: ChainType = 'evm') { +export function isNativeToken(tokenAddress?: string, chainType: ChainType = 'evm') { if (chainType === 'solana') { return tokenAddress === '11111111111111111111111111111111'; } diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/deBridge/hooks/useGetDeBridgeFees.ts b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/deBridge/hooks/useGetDeBridgeFees.ts index 4b4783f2..705ba422 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/deBridge/hooks/useGetDeBridgeFees.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/deBridge/hooks/useGetDeBridgeFees.ts @@ -15,6 +15,7 @@ import { useGetTokenBalance } from '@/core/contract/hooks/useGetTokenBalance'; import { ERC20_TOKEN } from '@/core/contract/abi'; import { useNativeCurrency } from '@/modules/aggregator/hooks/useNativeCurrency'; import { useSolanaBalance } from '@/modules/wallet/hooks/useSolanaBalance'; +import { isNativeToken } from '@/core/utils/address'; export interface IFeeDetails { value: string; @@ -213,6 +214,7 @@ export const useGetDeBridgeFees = () => { dispatch(setRouteError({ deBridge: 'Failed to get gas fee' })); isFailedToGetGas = true; } + const result = feeList.reduce((acc: { [key: string]: number }, item) => { const symbol = item.symbol; const value = Number(item.value); @@ -220,6 +222,26 @@ export const useGetDeBridgeFees = () => { acc[symbol] += value; return acc; }, {} as { [key: string]: number }); + + if ( + fromChain?.chainType === 'solana' && + isNativeToken(selectedToken?.deBridge?.raw?.address, fromChain?.chainType) && + nativeToken && + nativeTokenBalance + ) { + const totalNativeTokenCost = Number(result[nativeToken]) + Number(sendValue); + const userNativeTokenBalance = Number(nativeTokenBalance.formatted); + + if (userNativeTokenBalance < totalNativeTokenCost) { + dispatch( + setRouteError({ + deBridge: `Insufficient ${nativeToken} to cover protocol fee and market maker gas costs`, + }), + ); + isDisplayError = true; + } + } + const resultString = Object.keys(result) .map((symbol) => { return `${formatFeeAmount(result[symbol])} ${symbol}`; @@ -234,6 +256,7 @@ export const useGetDeBridgeFees = () => { }, }), ); + return { summary: resultString ? resultString : '--', breakdown: feeBreakdown,