Skip to content

Commit

Permalink
fix: chains
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaisailovic committed Sep 6, 2024
1 parent f50f378 commit afb38d4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ export default function useSendUsdc() {

const tx = await client.writeContract({
abi: erc20Abi,
address: "0x94a9d9ac8a22534e3faca9f4e7f2e2cf85d5e4c8",
address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", // arbitrum usdc
functionName: "transfer",
args: [
"0x81D8C68Be5EcDC5f927eF020Da834AA57cc3Bd24",
BigInt(300000000000),
],
args: ["0x81D8C68Be5EcDC5f927eF020Da834AA57cc3Bd24", BigInt(500000)],
});
return tx;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export function decodeErc20Transaction({
if (functionName !== 'transfer') {
return null
}

return {
to: args[0],
contract: to as Hex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,43 +35,51 @@ export default function SessionSendTransactionModal() {
useEffect(() => {
const multibridgeCheck = async () => {
setIsTypeResolved(false)
if (!request) {
setIsTypeResolved(true)
return
}
const transfer = decodeErc20Transaction(request.params[0])
if (!transfer) {
setIsTypeResolved(true)
return
}
const parsedChainId = chainId?.split(':')[1]
const tokenBalance = await getErc20TokenBalance(
transfer.contract,
Number(parsedChainId),
transfer.from,
false
)
if (transfer.amount <= tokenBalance) {
setIsTypeResolved(true)
return
}
const otherTokens = getCrossChainTokens(transfer.contract)
let otherBalance = 0
for (const chain in otherTokens) {
const balance = await getErc20TokenBalance(
otherTokens[Number(chain)],
Number(chain),
try {
if (!request) {
setIsTypeResolved(true)
return
}
const transfer = decodeErc20Transaction(request.params[0])
if (!transfer) {
setIsTypeResolved(true)
return
}
const parsedChainId = chainId?.split(':')[1]
const tokenBalance = await getErc20TokenBalance(
transfer.contract,
Number(parsedChainId),
transfer.from,
false
)
otherBalance += balance
}
if (transfer.amount > otherBalance) {
if (transfer.amount <= tokenBalance) {
setIsTypeResolved(true)
return
}
const otherTokens = getCrossChainTokens(transfer.contract)
let otherBalance = 0

for (const chain in otherTokens) {
const balance = await getErc20TokenBalance(
otherTokens[Number(chain)],
Number(chain),
transfer.from,
false
)
otherBalance += balance
}
if (transfer.amount > otherBalance) {
setIsTypeResolved(true)
return
}
console.log('Balance on other chains', { otherBalance, requiredBalance: transfer.amount })

setShouldUseMultibridge(true)
} catch (error) {
console.log('Unable to check multibridge availability', error)
} finally {
setIsTypeResolved(true)
return
}
setShouldUseMultibridge(true)
setIsTypeResolved(true)
}
multibridgeCheck()
}, [request, chainId])
Expand Down

0 comments on commit afb38d4

Please sign in to comment.