Skip to content

Commit

Permalink
feat(bridge-ui-v2): insufficient funds modal (#14759)
Browse files Browse the repository at this point in the history
  • Loading branch information
KorbinianK authored Sep 20, 2023
1 parent 12805a5 commit c6e23ad
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte';
import { t } from 'svelte-i18n';
import { formatEther } from 'viem';
Expand All @@ -15,7 +16,9 @@
export let closeDetails = noop;
export let detailsOpen = false;
export let selectedItem: BridgeTransaction | null;
export let selectedItem: BridgeTransaction;
const dispatch = createEventDispatcher();
let openStatusDialog = false;
Expand All @@ -29,6 +32,10 @@
const handleStatusDialog = () => {
openStatusDialog = !openStatusDialog;
};
const handleInsufficientFunds = (e: CustomEvent) => {
dispatch('insufficientFunds', e.detail);
};
</script>

<dialog id={dialogId} class="modal modal-bottom" class:modal-open={detailsOpen}>
Expand Down Expand Up @@ -66,7 +73,7 @@
</div>
</h4>
<div class="f-items-center space-x-1">
<Status bridgeTx={selectedItem} />
<Status bridgeTx={selectedItem} on:insufficientFunds={handleInsufficientFunds} />
</div>
</li>
<li class="f-between-center">
Expand Down
25 changes: 12 additions & 13 deletions packages/bridge-ui-v2/src/components/Transactions/Status.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { type Address, fetchBalance, switchNetwork } from '@wagmi/core';
import { onDestroy, onMount } from 'svelte';
import { createEventDispatcher, onDestroy, onMount } from 'svelte';
import { t } from 'svelte-i18n';
import { parseEther, UserRejectedRequestError } from 'viem';
Expand Down Expand Up @@ -31,22 +31,23 @@
import { network } from '$stores/network';
import { pendingTransactions } from '$stores/pendingTransactions';
import InsufficientFunds from './InsufficientFunds.svelte';
export let bridgeTx: BridgeTransaction;
const log = getLogger('components:Status');
export let bridgeTx: BridgeTransaction;
const dispatch = createEventDispatcher();
let polling: ReturnType<typeof startPolling>;
// UI state
let processable = false; // bridge tx state to be processed: claimed/retried/released
let bridgeTxStatus: Maybe<MessageStatus>;
let modalOpen = false;
enum LoadingState {
CLAIMING = 'claiming',
RELEASING = 'releasing',
}
// TODO: enum?
let loading: 'claiming' | 'releasing' | false = false;
let loading: LoadingState | false = false;
function onProcessable(isTxProcessable: boolean) {
processable = isTxProcessable;
Expand Down Expand Up @@ -78,7 +79,7 @@
async function claim() {
if (!$network || !$account?.address) return;
loading = 'claiming';
loading = LoadingState.CLAIMING;
try {
const { msgHash, message } = bridgeTx;
Expand Down Expand Up @@ -140,7 +141,7 @@
warningToast($t('transactions.actions.claim.rejected'));
break;
case err instanceof InsufficientBalanceError:
modalOpen = true;
dispatch('insufficientFunds', { tx: bridgeTx });
break;
case err instanceof InvalidProofError:
errorToast($t('TODO: InvalidProofError'));
Expand All @@ -163,7 +164,7 @@
async function release() {
if (!$network || !$account?.address) return;
loading = 'releasing';
loading = LoadingState.RELEASING;
try {
const { msgHash, message } = bridgeTx;
Expand Down Expand Up @@ -266,7 +267,7 @@
<div class="Status f-items-center space-x-1">
{#if !processable}
<StatusDot type="pending" />
<span>{$t('transactions.status.initiated.name')}</span>
<span>{$t('transactions.status.processing.name')}</span>
{:else if loading}
<div class="f-items-center space-x-2">
<Spinner />
Expand All @@ -293,5 +294,3 @@
<span>{$t('transactions.status.error.name')}</span>
{/if}
</div>

<InsufficientFunds bind:modalOpen />
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
<div class="inline-flex flex-col px-[37px] text-base">
<br />
{$t('transactions.status.dialog.description')}
<h4 class={classes.headline}>{$t('transactions.status.initiated.name')}</h4>
{$t('transactions.status.initiated.description')}
<h4 class={classes.headline}>{$t('transactions.status.processing.name')}</h4>
{$t('transactions.status.processing.description')}
<h4 class={classes.headline}>{$t('transactions.status.claim.name')}</h4>
{$t('transactions.status.claim.description')}
<h4 class={classes.headline}>{$t('transactions.status.claimed.name')}</h4>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,49 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte';
import { t } from 'svelte-i18n';
import { formatEther } from 'viem';
import type { BridgeTransaction } from '$libs/bridge';
export let item: BridgeTransaction;
import { createEventDispatcher } from 'svelte';
import { chainConfig } from '$chainConfig';
import { DesktopOrLarger } from '$components/DesktopOrLarger';
import { Icon } from '$components/Icon';
import { type BridgeTransaction, MessageStatus } from '$libs/bridge';
import ChainSymbolName from './ChainSymbolName.svelte';
import InsufficientFunds from './InsufficientFunds.svelte';
import MobileDetailsDialog from './MobileDetailsDialog.svelte';
import Status from './Status.svelte';
const dispatch = createEventDispatcher();
export let item: BridgeTransaction;
const dispatch = createEventDispatcher();
let insufficientModal = false;
let detailsOpen = false;
let isDesktopOrLarger = false;
const handleClick = () => dispatch('click');
const handleClick = () => {
openDetails();
dispatch('click');
};
const handlePress = () => {
openDetails();
dispatch('press');
};
const closeDetails = () => {
detailsOpen = false;
};
const openDetails = () => {
if (item?.status === MessageStatus.DONE && !isDesktopOrLarger) {
detailsOpen = true;
}
};
const handlePress = () => dispatch('press');
const handleInsufficientFunds = () => {
insufficientModal = true;
openDetails();
};
let attrs = isDesktopOrLarger ? {} : { role: 'button' };
</script>
Expand Down Expand Up @@ -65,7 +87,11 @@
{/if}

<div class="sm:w-1/4 md:w-1/5 py-2 flex flex-col justify-center">
<Status bridgeTx={item} />
<Status
on:click={isDesktopOrLarger ? undefined : openDetails}
bridgeTx={item}
on:insufficientFunds={handleInsufficientFunds} />
<!-- <div class="btn btn-primary" on:click={isDesktopOrLarger ? undefined : openDetails}></div> -->
</div>
<div class="hidden md:flex w-1/5 py-2 flex flex-col justify-center">
<a
Expand All @@ -77,4 +103,9 @@
</a>
</div>
</div>

<DesktopOrLarger bind:is={isDesktopOrLarger} />

<MobileDetailsDialog {closeDetails} {detailsOpen} selectedItem={item} on:insufficientFunds={handleInsufficientFunds} />

<InsufficientFunds bind:modalOpen={insufficientModal} />
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import { account, network } from '$stores';
import type { Account } from '$stores/account';
import MobileDetailsDialog from './MobileDetailsDialog.svelte';
import StatusInfoDialog from './StatusInfoDialog.svelte';
import Transaction from './Transaction.svelte';
Expand All @@ -31,11 +30,8 @@
let loadingTxs = false;
let detailsOpen = false;
let isDesktopOrLarger: boolean;
let selectedItem: BridgeTransaction | null = null;
const handlePageChange = (detail: number) => {
isBlurred = true;
setTimeout(() => {
Expand Down Expand Up @@ -67,16 +63,6 @@
}
};
const closeDetails = () => {
detailsOpen = false;
selectedItem = null;
};
const openDetails = (tx: BridgeTransaction) => {
detailsOpen = true;
selectedItem = tx;
};
const updateTransactions = async (address: Address) => {
const { mergedTransactions, outdatedLocalTransactions, error } = await fetchTransactions(address);
transactions = mergedTransactions;
Expand Down Expand Up @@ -136,7 +122,7 @@
class="flex flex-col items-center"
style={isBlurred ? `filter: blur(5px); transition: filter ${transitionTime / 1000}s ease-in-out` : ''}>
{#each transactionsToShow as item (item.hash)}
<Transaction {item} on:click={isDesktopOrLarger ? undefined : () => openDetails(item)} />
<Transaction {item} />
<div class="h-sep" />
{/each}
</div>
Expand All @@ -156,8 +142,6 @@
</div>
</div>

<MobileDetailsDialog {closeDetails} {detailsOpen} {selectedItem} />

<OnAccount change={onAccountChange} />

<DesktopOrLarger bind:is={isDesktopOrLarger} />
6 changes: 3 additions & 3 deletions packages/bridge-ui-v2/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@
"release": "Release"
},
"status": {
"initiated": {
"name": "Initiated",
"description": "Transaction initiated"
"processing": {
"name": "Processing",
"description": "Transaction is processing. Depending on the pending blocks to be verified this can take up to several minutes."
},
"pending": {
"name": "Pending",
Expand Down

1 comment on commit c6e23ad

@vercel
Copy link

@vercel vercel bot commented on c6e23ad Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

bridge-ui-v2-internal – ./packages/bridge-ui-v2

bridge-ui-v2-internal.vercel.app
bridge-ui-v2-internal-taikoxyz.vercel.app
bridge-ui-v2-internal-git-main-taikoxyz.vercel.app

Please sign in to comment.