From 2a1987355663e1326cab838d0463e190d29f6f56 Mon Sep 17 00:00:00 2001
From: Ray Lin <137183702+ruijialin-avalabs@users.noreply.github.com>
Date: Wed, 3 Jul 2024 15:12:55 -0400
Subject: [PATCH] Add isBtcBridge function (#1387)
---
packages/core-mobile/app/screens/bridge/Bridge.tsx | 4 ++--
.../rpc/components/v2/BitcoinSendTransaction.tsx | 11 ++++++-----
.../activity/utils/evmTransactionConverter.ts | 12 +++++++-----
packages/core-mobile/app/utils/isBridge.ts | 9 ---------
packages/core-mobile/app/utils/isBtcBridge.ts | 11 +++++++++++
5 files changed, 26 insertions(+), 21 deletions(-)
delete mode 100644 packages/core-mobile/app/utils/isBridge.ts
create mode 100644 packages/core-mobile/app/utils/isBtcBridge.ts
diff --git a/packages/core-mobile/app/screens/bridge/Bridge.tsx b/packages/core-mobile/app/screens/bridge/Bridge.tsx
index 18c3952378..190a842a17 100644
--- a/packages/core-mobile/app/screens/bridge/Bridge.tsx
+++ b/packages/core-mobile/app/screens/bridge/Bridge.tsx
@@ -756,10 +756,10 @@ const Bridge: FC = () => {
}}>
{isPending ? (
<>
- Transferring...
+ Bridging...
>
) : (
- 'Transfer'
+ 'Bridge'
)}
)
diff --git a/packages/core-mobile/app/screens/rpc/components/v2/BitcoinSendTransaction.tsx b/packages/core-mobile/app/screens/rpc/components/v2/BitcoinSendTransaction.tsx
index b5a7428417..164fd1ccad 100644
--- a/packages/core-mobile/app/screens/rpc/components/v2/BitcoinSendTransaction.tsx
+++ b/packages/core-mobile/app/screens/rpc/components/v2/BitcoinSendTransaction.tsx
@@ -26,7 +26,8 @@ import { mustNumber } from 'utils/JsTools'
import { BitcoinSendTransactionApproveData } from 'store/rpc/handlers/bitcoin_sendTransaction/bitcoin_sendTransaction'
import { SendState } from 'services/send/types'
import { NetworkLogo } from 'screens/network/NetworkLogo'
-import { isBridge } from 'utils/isBridge'
+import { selectBridgeCriticalConfig } from 'store/bridge'
+import { isBtcBridge } from 'utils/isBtcBridge'
type BitcoinSendTransactionScreenProps = WalletScreenProps<
typeof AppNavigation.Modal.BitcoinSendTransaction
@@ -47,7 +48,7 @@ const BitcoinSendTransaction = (): JSX.Element => {
const isDeveloperMode = useSelector(selectIsDeveloperMode)
const btcNetwork = getBitcoinNetwork(isDeveloperMode)
const { sendState } = data
-
+ const bridgeConfig = useSelector(selectBridgeCriticalConfig)
const allAccounts = useSelector(selectAccounts)
const toAccountName =
Object.values(allAccounts).find(a => a.addressBTC === sendState.address)
@@ -114,10 +115,10 @@ const BitcoinSendTransaction = (): JSX.Element => {
)
const title = useMemo(() => {
- return sendState.address && isBridge(sendState.address)
- ? 'Bridge'
+ return sendState.address && isBtcBridge(sendState.address, bridgeConfig)
+ ? 'Confirm Bridge'
: 'Approve Transaction'
- }, [sendState.address])
+ }, [bridgeConfig, sendState.address])
const renderNetwork = (): JSX.Element | undefined => {
return (
diff --git a/packages/core-mobile/app/services/activity/utils/evmTransactionConverter.ts b/packages/core-mobile/app/services/activity/utils/evmTransactionConverter.ts
index e4c0c51850..d645f68dea 100644
--- a/packages/core-mobile/app/services/activity/utils/evmTransactionConverter.ts
+++ b/packages/core-mobile/app/services/activity/utils/evmTransactionConverter.ts
@@ -3,23 +3,25 @@ import {
TransactionType,
TokenType
} from '@avalabs/vm-module-types'
+import { NULL_ADDRESS } from 'screens/bridge/utils/bridgeUtils'
+import UnifiedBridgeService from 'services/bridge/UnifiedBridgeService'
import { Transaction } from 'store/transaction'
-import { isBridge } from 'utils/isBridge'
export const convertTransaction = (
transaction: EvmTransaction
): Transaction => {
- const isBridgeTx =
+ const bridgeAddresses = UnifiedBridgeService.getBridgeAddresses()
+ const isBridge =
transaction.tokens[0]?.type === TokenType.ERC20 &&
[
transaction.tokens[0].to?.address.toLowerCase(),
transaction.tokens[0].from?.address.toLowerCase()
- ].some(item => item && isBridge(item))
+ ].some(item => item && [...bridgeAddresses, NULL_ADDRESS].includes(item))
return {
...transaction,
- isBridge: isBridgeTx,
- txType: isBridgeTx
+ isBridge,
+ txType: isBridge
? TransactionType.BRIDGE
: transaction.txType
? transaction.txType
diff --git a/packages/core-mobile/app/utils/isBridge.ts b/packages/core-mobile/app/utils/isBridge.ts
deleted file mode 100644
index c8e3c8aac3..0000000000
--- a/packages/core-mobile/app/utils/isBridge.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import { NULL_ADDRESS } from 'screens/bridge/utils/bridgeUtils'
-import UnifiedBridgeService from 'services/bridge/UnifiedBridgeService'
-
-export const isBridge = (address: string): boolean => {
- return [
- NULL_ADDRESS,
- ...UnifiedBridgeService.getBridgeAddresses().map(item => item.toLowerCase())
- ].includes(address.toLowerCase())
-}
diff --git a/packages/core-mobile/app/utils/isBtcBridge.ts b/packages/core-mobile/app/utils/isBtcBridge.ts
new file mode 100644
index 0000000000..2c54fe7688
--- /dev/null
+++ b/packages/core-mobile/app/utils/isBtcBridge.ts
@@ -0,0 +1,11 @@
+import { CriticalConfig } from '@avalabs/bridge-sdk'
+
+export const isBtcBridge = (
+ address: string,
+ bridgeConfig?: CriticalConfig
+): boolean => {
+ const btcBridgeAddress =
+ bridgeConfig &&
+ bridgeConfig.criticalBitcoin?.walletAddresses.btc?.toLowerCase()
+ return btcBridgeAddress === address.toLowerCase()
+}