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

feat(bridge-ui-v2): Faucet #14145

Merged
merged 25 commits into from
Jul 12, 2023
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
better use of conditions
  • Loading branch information
jscriptcoder committed Jul 12, 2023
commit 30570c2dbb28be22f7a6209d0c0d091055e4c232
28 changes: 14 additions & 14 deletions packages/bridge-ui-v2/src/components/Faucet/Faucet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@
}

function isUserConnected(user: Maybe<typeof $account>) {
return user?.isConnected;
return Boolean(user?.isConnected);
}

function isWrongChain(network: Maybe<Chain>) {
return network?.id.toString() !== PUBLIC_L1_CHAIN_ID;
return Boolean(network?.id.toString() !== PUBLIC_L1_CHAIN_ID);
}

async function shouldEnableMintButton(token: Maybe<Token>, network: Maybe<Chain>) {
Expand Down Expand Up @@ -122,8 +122,15 @@
return false;
}

function getAlertMessage(connected: boolean, wrongChain: boolean, reasonNotMintable: string) {
if (!connected) return $t('messages.account.required');
if (wrongChain) return $t('faucet.wrong_chain.message', { values: { network: PUBLIC_L1_CHAIN_NAME } });
if (reasonNotMintable) return reasonNotMintable;
}

$: connected = isUserConnected($account);
$: wrongChain = isWrongChain($srcChain);
$: alertMessage = getAlertMessage(connected, wrongChain, reasonNotMintable);

$: shouldEnableMintButton(selectedToken, $srcChain).then((enable) => (mintButtonEnabled = enable));
</script>
Expand All @@ -135,15 +142,14 @@
<TokenDropdown tokens={testERC20Tokens} bind:value={selectedToken} />
</div>

{#if !connected}
<Alert type="warning" forceColumnFlow>
{$t('messages.account.required')}
</Alert>
{:else if wrongChain}
{#if alertMessage}
<Alert type="warning" forceColumnFlow>
{$t('faucet.wrong_chain.message', { values: { network: PUBLIC_L1_CHAIN_NAME } })}
{alertMessage}
</Alert>
{/if}

{#if connected && wrongChain}
<!-- We give the user an easier way to switch chains with this button -->
<Button type="primary" class="px-[28px] py-[14px]" loading={switchingNetwork} on:click={switchNetworkToL1}>
{#if switchingNetwork}
<span>{$t('messages.network.switching')}</span>
Expand All @@ -155,12 +161,6 @@
{/if}
</Button>
{:else}
{#if reasonNotMintable}
<Alert type="warning" forceColumnFlow>
{reasonNotMintable}
</Alert>
{/if}

<Button
type="primary"
class="px-[28px] py-[14px]"
Expand Down