Skip to content

Commit

Permalink
Add isBtcBridge function (#1387)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruijialin-avalabs authored Jul 3, 2024
1 parent 22a488f commit 2a19873
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
4 changes: 2 additions & 2 deletions packages/core-mobile/app/screens/bridge/Bridge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -756,10 +756,10 @@ const Bridge: FC = () => {
}}>
{isPending ? (
<>
<ActivityIndicator /> Transferring...
<ActivityIndicator /> Bridging...
</>
) : (
'Transfer'
'Bridge'
)}
</Button>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions packages/core-mobile/app/utils/isBridge.ts

This file was deleted.

11 changes: 11 additions & 0 deletions packages/core-mobile/app/utils/isBtcBridge.ts
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 2a19873

Please sign in to comment.