Skip to content

Commit

Permalink
feat(bridge-ui): check if failed tokens are released
Browse files Browse the repository at this point in the history
  • Loading branch information
shadab-taiko committed Feb 23, 2023
1 parent c3ff1e9 commit dc903e7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/bridge-ui/src/components/Transaction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import { fetchSigner, switchNetwork } from "@wagmi/core";
import Bridge from "../constants/abi/Bridge";
import ButtonWithTooltip from "./ButtonWithTooltip.svelte";
import TokenVault from "../constants/abi/TokenVault";
export let transaction: BridgeTransaction;
Expand Down Expand Up @@ -151,6 +152,30 @@
);
transaction.status = await contract.getMessageStatus(transaction.msgHash);
if(transaction.status === MessageStatus.Failed) {
if(transaction.message.data !== "0x") {
const srcTokenVaultContract = new ethers.Contract(
$chainIdToTokenVaultAddress.get(transaction.fromChainId),
TokenVault,
$providers.get(chains[transaction.message.srcChainId.toNumber()].id)
)
const {token, amount} = await srcTokenVaultContract.messageDeposits(transaction.msgHash);
console.log(token, amount);
if(token === ethers.constants.AddressZero && amount.eq(0)) {
transaction.status = MessageStatus.FailedReleased;
}
} else {
const srcBridgeContract = new ethers.Contract(
chains[transaction.fromChainId].bridgeAddress,
Bridge,
$providers.get(chains[transaction.message.srcChainId.toNumber()].id)
)
const {token, amount} = await srcBridgeContract.isEtherReleased(transaction.msgHash);
if(token === ethers.constants.AddressZero && amount.eq(0)) {
transaction.status = MessageStatus.FailedReleased;
}
}
}
transaction = transaction;
if (transaction.status === MessageStatus.Done) clearInterval(interval);
}, 20 * 1000);
Expand Down Expand Up @@ -215,6 +240,8 @@
</button>
{:else if transaction.status === MessageStatus.Done}
<span class="border border-transparent p-0">Claimed</span>
{:else if transaction.status === MessageStatus.FailedReleased}
<span class="border border-transparent p-0">Released</span>
{/if}
</span>
</ButtonWithTooltip>
Expand Down
19 changes: 19 additions & 0 deletions packages/bridge-ui/src/constants/abi/Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,25 @@ export default [
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "msgHash",
"type": "bytes32"
}
],
"name": "isEtherReleased",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down
1 change: 1 addition & 0 deletions packages/bridge-ui/src/domain/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ enum MessageStatus {
Retriable,
Done,
Failed,
FailedReleased
}

type Message = {
Expand Down

0 comments on commit dc903e7

Please sign in to comment.