Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bridge-ui): transaction and pendingTransaction refactor #13307

Merged
merged 9 commits into from
Mar 15, 2023
24 changes: 12 additions & 12 deletions packages/bridge-ui/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,20 @@
});

pendingTransactions.subscribe((store) => {
store.forEach(async (tx) => {
await $signer.provider.waitForTransaction(tx.hash, 1);
(async () => {
const confirmedPendingTxIndex = await Promise.race(
shadab-taiko marked this conversation as resolved.
Show resolved Hide resolved
store.map((tx, index) => {
return new Promise<number>(async (resolve) => {
await $signer.provider.waitForTransaction(tx.hash, 1);
resolve(index);
});
}),
);
successToast('Transaction completed!');

// TODO: Fix, .pop() removes the last tx but the confirmed tx is not necessarily the last one in the pendingTransactions array.
const s = store;
s.pop();
let s = store;
s = s.slice(confirmedPendingTxIndex, 0);
pendingTransactions.set(s);

// TODO: Do we need this?
transactions.set(
await $transactioner.GetAllByAddress(await $signer.getAddress()),
);
});
})();
});

const transactionToIntervalMap = new Map();
Expand Down
20 changes: 8 additions & 12 deletions packages/bridge-ui/src/relayer-api/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ class RelayerAPIService implements RelayerAPI {
}

const txs: BridgeTransaction[] = data.map((tx) => {
const depositValue = ethers.utils.parseUnits(
tx.data.Message.DepositValue.toString(),
'wei',
);
return {
status: tx.status,
message: {
Expand All @@ -60,8 +56,8 @@ class RelayerAPIService implements RelayerAPI {
callValue: tx.data.Message.CallValue,
srcChainId: BigNumber.from(tx.data.Message.SrcChainId),
destChainId: BigNumber.from(tx.data.Message.DestChainId),
depositValue: depositValue,
processingFee: BigNumber.from(tx.data.Message.ProcessingFee),
depositValue: BigNumber.from(`${tx.data.Message.DepositValue}`),
processingFee: BigNumber.from(`${tx.data.Message.ProcessingFee}`),
refundAddress: tx.data.Message.RefundAddress,
},
amountInWei: tx.amount,
Expand All @@ -73,9 +69,7 @@ class RelayerAPIService implements RelayerAPI {
};
});

const bridgeTxs: BridgeTransaction[] = [];

await Promise.all(
const bridgeTxs: BridgeTransaction[] = await Promise.all(
(txs || []).map(async (tx) => {
if (tx.message.owner.toLowerCase() !== address.toLowerCase()) return;

Expand Down Expand Up @@ -116,7 +110,9 @@ class RelayerAPIService implements RelayerAPI {
);

const event = events.find(
(e) => e.args.message.owner.toLowerCase() === address.toLowerCase(),
(e) =>
e.args.message.owner.toLowerCase() === address.toLowerCase() &&
e.args.message.depositValue.eq(tx.message.depositValue),
shadab-taiko marked this conversation as resolved.
Show resolved Hide resolved
);

if (!event) {
Expand Down Expand Up @@ -172,12 +168,12 @@ class RelayerAPIService implements RelayerAPI {
from: tx.from,
};

bridgeTxs.push(bridgeTx);
return bridgeTx;
}),
);

bridgeTxs.reverse();
bridgeTxs.sort((tx) => (tx.status === MessageStatus.New ? -1 : 1));

return bridgeTxs;
}

Expand Down
30 changes: 30 additions & 0 deletions packages/bridge-ui/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
/// <reference types="svelte" />
/// <reference types="vite/client" />
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly VITE_L1_RPC_URL: string;
readonly VITE_L1_RPC_URL: string;
readonly VITE_L2_RPC_URL: string;
readonly VITE_L1_EXPLORER_URL: string;
readonly VITE_L2_EXPLORER_URL: string;
readonly VITE_RELAYER_URL: string;
readonly VITE_TEST_ERC20_ADDRESS_MAINNET: string;
readonly VITE_TEST_ERC20_SYMBOL_MAINNET: string;
readonly VITE_TEST_ERC20_NAME_MAINNET: string;
readonly VITE_MAINNET_CHAIN_ID: string;
readonly VITE_TAIKO_CHAIN_ID: string;
readonly VITE_MAINNET_CHAIN_NAME: string;
readonly VITE_TAIKO_CHAIN_NAME: string;
readonly VITE_MAINNET_TOKEN_VAULT_ADDRESS: string;
readonly VITE_TAIKO_TOKEN_VAULT_ADDRESS: string;
readonly VITE_MAINNET_HEADER_SYNC_ADDRESS: string;
readonly VITE_TAIKO_HEADER_SYNC_ADDRESS: string;
readonly VITE_MAINNET_BRIDGE_ADDRESS: string;
readonly VITE_TAIKO_BRIDGE_ADDRESS: string;
readonly VITE_MAINNET_SIGNAL_SERVICE_ADDRESS: string;
readonly VITE_TAIKO_SIGNAL_SERVICE_ADDRESS: string;
readonly VITE_TEST_ERC20: string;
}

interface ImportMeta {
jscriptcoder marked this conversation as resolved.
Show resolved Hide resolved
readonly env: ImportMetaEnv;
}