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): ui fixes #13366

Merged
merged 6 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/bridge-ui/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@

const updatedStorageTxs: BridgeTransaction[] = txs.filter((tx) => {
const blockInfo = blockInfoMap.get(tx.fromChainId);
if (blockInfo?.latestProcessedBlock >= tx.receipt.blockNumber) {
if (blockInfo?.latestProcessedBlock >= tx.receipt?.blockNumber) {
return false;
}
return true;
Expand Down
20 changes: 18 additions & 2 deletions packages/bridge-ui/src/bridge/ERC20Bridge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumber, Contract, Signer } from 'ethers';
import { BigNumber, Contract, ethers, Signer } from 'ethers';
import type { Transaction } from 'ethers';
import type {
ApproveOpts,
Expand Down Expand Up @@ -190,7 +190,23 @@ export class ERC20Bridge implements Bridge {
});
}

return await contract.processMessage(opts.message, proof);
let processMessageTx;
try {
processMessageTx = await contract.processMessage(opts.message, proof);
} catch (error) {
if (error.code === ethers.errors.UNPREDICTABLE_GAS_LIMIT) {
processMessageTx = await contract.processMessage(
opts.message,
proof,
{
gasLimit: 1e6,
},
);
} else {
throw new Error(error);
}
}
return processMessageTx;
} else {
return await contract.retryMessage(opts.message, false);
}
Expand Down
20 changes: 18 additions & 2 deletions packages/bridge-ui/src/bridge/ETHBridge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumber, Contract } from 'ethers';
import { BigNumber, Contract, ethers } from 'ethers';
import type { Transaction } from 'ethers';
import type {
ApproveOpts,
Expand Down Expand Up @@ -133,7 +133,23 @@ export class ETHBridge implements Bridge {
};

const proof = await this.prover.GenerateProof(proofOpts);
return await contract.processMessage(opts.message, proof);
let processMessageTx;
try {
processMessageTx = await contract.processMessage(opts.message, proof);
} catch (error) {
if (error.code === ethers.errors.UNPREDICTABLE_GAS_LIMIT) {
processMessageTx = await contract.processMessage(
opts.message,
proof,
{
gasLimit: 1e6,
},
);
} else {
throw new Error(error);
}
}
return processMessageTx;
} else {
return await contract.retryMessage(opts.message, true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script lang="ts">
import TooltipModal from './modals/TooltipModal.svelte';
export let show: boolean;
</script>

<TooltipModal title="Insufficient Balance" bind:isOpen={show}>
<span slot="body">
<div class="text-left">
You have insufficient balance to claim this transaction. Please wait for
the relayer to claim the transaction for you.
</div>
</span>
</TooltipModal>
28 changes: 21 additions & 7 deletions packages/bridge-ui/src/components/Transaction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import { ArrowTopRightOnSquare } from 'svelte-heros-v2';
import { MessageStatus } from '../domain/message';
import { Contract, ethers } from 'ethers';
import { bridges, chainIdToTokenVaultAddress } from '../store/bridge';
import {
activeBridge,
bridges,
chainIdToTokenVaultAddress,
} from '../store/bridge';
import { signer } from '../store/signer';
import { pendingTransactions } from '../store/transactions';
import { errorToast, successToast } from '../utils/toast';
Expand All @@ -19,7 +23,7 @@
import { LottiePlayer } from '@lottiefiles/svelte-lottie-player';
import HeaderSync from '../constants/abi/HeaderSync';
import { providers } from '../store/providers';
import { fetchSigner, switchNetwork } from '@wagmi/core';
import { fetchFeeData, fetchSigner, switchNetwork } from '@wagmi/core';
import Bridge from '../constants/abi/Bridge';
import ButtonWithTooltip from './ButtonWithTooltip.svelte';
import TokenVault from '../constants/abi/TokenVault';
Expand All @@ -29,7 +33,7 @@
export let fromChain: Chain;
export let toChain: Chain;

export let onTooltipClick: () => void;
export let onTooltipClick: (showInsufficientBalanceMessage: boolean) => void;
export let onShowTransactionDetailsClick: () => void;

let loading: boolean;
Expand Down Expand Up @@ -76,6 +80,14 @@
await switchChainAndSetSigner(chain);
}

// For now just handling this case for when the user has near 0 balance during their first bridge transaction to L2
// TODO: estimate Claim transaction
const userBalance = await $signer.getBalance('latest');
if (!userBalance.gt(ethers.utils.parseEther('0.0001'))) {
onTooltipClick(true);
return;
}

const tx = await $bridges
.get(
bridgeTx.message?.data === '0x' || !bridgeTx.message?.data
Expand All @@ -96,6 +108,7 @@
});

successToast($_('toast.transactionSent'));
transaction.status = MessageStatus.ClaimInProgress;
} catch (e) {
console.error(e);
errorToast($_('toast.errorSendingTransaction'));
Expand Down Expand Up @@ -226,7 +239,7 @@
</td>

<td>
<ButtonWithTooltip onClick={onTooltipClick}>
<ButtonWithTooltip onClick={() => onTooltipClick(false)}>
<span slot="buttonText">
{#if !processable}
Pending
Expand All @@ -243,10 +256,11 @@
width={26}
controlsLayout={[]} />
</div>
{:else if transaction.receipt && transaction.status === MessageStatus.New}
{:else if transaction.receipt && [MessageStatus.New, MessageStatus.ClaimInProgress].includes(transaction.status)}
<button
class="cursor-pointer border rounded p-1 btn btn-sm border-white"
on:click={async () => await claim(transaction)}>
class="cursor-pointer border rounded p-1 btn btn-sm border-white disabled:border-gray-800"
on:click={async () => await claim(transaction)}
disabled={transaction.status === MessageStatus.ClaimInProgress}>
Claim
</button>
{:else if transaction.status === MessageStatus.Retriable}
Expand Down
13 changes: 10 additions & 3 deletions packages/bridge-ui/src/components/Transactions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import Transaction from './Transaction.svelte';
import TransactionDetail from './TransactionDetail.svelte';
import MessageStatusTooltip from './MessageStatusTooltip.svelte';
import InsufficientBalanceTooltip from './InsufficientBalanceTooltip.svelte';
import type { BridgeTransaction } from '../domain/transactions';
import { chainsRecord } from '../chain/chains';

let selectedTransaction: BridgeTransaction;
let showMessageStatusTooltip: boolean;
let showInsufficientBalance: boolean;
</script>

<div class="my-4 md:px-4">
Expand All @@ -25,8 +27,12 @@
<tbody class="text-sm md:text-base">
{#each $transactions as transaction}
<Transaction
onTooltipClick={() => {
showMessageStatusTooltip = true;
onTooltipClick={(showInsufficientBalanceMessage = false) => {
if (showInsufficientBalanceMessage) {
showInsufficientBalance = true;
} else {
showMessageStatusTooltip = true;
}
}}
onShowTransactionDetailsClick={() => {
selectedTransaction = transaction;
Expand All @@ -47,5 +53,6 @@
onClose={() => (selectedTransaction = null)} />
{/if}

<MessageStatusTooltip show={showMessageStatusTooltip} />
<MessageStatusTooltip bind:show={showMessageStatusTooltip} />
<InsufficientBalanceTooltip bind:show={showInsufficientBalance} />
</div>
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 @@ -6,6 +6,7 @@ export enum MessageStatus {
Done,
Failed,
FailedReleased,
ClaimInProgress,
}

export type Message = {
Expand Down