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

test(bridge-ui-v2): minting logic #14149

Merged
merged 31 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
25b2902
wip
jscriptcoder Jul 10, 2023
d55c7ba
wip: faucet
jscriptcoder Jul 10, 2023
b64b0a2
wip: Modal
jscriptcoder Jul 11, 2023
2d1f1d2
wip
jscriptcoder Jul 11, 2023
bd2e4a7
wip
jscriptcoder Jul 11, 2023
2fd98ee
wip
jscriptcoder Jul 11, 2023
1ed70be
wip
jscriptcoder Jul 11, 2023
397a40b
Faucet
jscriptcoder Jul 11, 2023
2c00949
Merge branch 'main' into mint_test_tokens
jscriptcoder Jul 11, 2023
93166b7
minor change
jscriptcoder Jul 12, 2023
5b9cdb9
Merge branch 'mint_test_tokens' of https://github.com/taikoxyz/taiko-…
jscriptcoder Jul 12, 2023
8275a4b
Merge branch 'main' into mint_test_tokens
jscriptcoder Jul 12, 2023
1773ec5
wip: mobile
jscriptcoder Jul 12, 2023
8b4a0d0
Merge branch 'mint_test_tokens' of https://github.com/taikoxyz/taiko-…
jscriptcoder Jul 12, 2023
b374fd9
DesltopOrLarger helper component
jscriptcoder Jul 12, 2023
c95e2b7
minor change
jscriptcoder Jul 12, 2023
f9ad657
minor change
jscriptcoder Jul 12, 2023
2606310
Update packages/bridge-ui-v2/src/i18n/en.json
jscriptcoder Jul 12, 2023
c2e7283
fix eslint
jscriptcoder Jul 12, 2023
7834cce
Merge branch 'mint_test_tokens' of https://github.com/taikoxyz/taiko-…
jscriptcoder Jul 12, 2023
1a5c23f
minor change
jscriptcoder Jul 12, 2023
faa1986
rename free to fee
jscriptcoder Jul 12, 2023
888cf3f
typo
jscriptcoder Jul 12, 2023
30570c2
better use of conditions
jscriptcoder Jul 12, 2023
e972b2d
add minor comment
jscriptcoder Jul 12, 2023
c7d11d3
wip
jscriptcoder Jul 12, 2023
61cd279
add checkMintable test
jscriptcoder Jul 12, 2023
0029e85
minor change
jscriptcoder Jul 12, 2023
ae9999a
token minting coverage
jscriptcoder Jul 12, 2023
cb284a8
excluding coverage
jscriptcoder Jul 12, 2023
b18931a
merge main
jscriptcoder Jul 12, 2023
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
1 change: 1 addition & 0 deletions packages/bridge-ui-v2/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
node_modules
coverage
/build
/.svelte-kit
/package
Expand Down
1 change: 1 addition & 0 deletions packages/bridge-ui-v2/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
node_modules
coverage
/build
/.svelte-kit
/package
Expand Down
6 changes: 4 additions & 2 deletions packages/bridge-ui-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"build": "vite build",
"preview": "vite preview",
"test:pw": "playwright test",
"test:unit": "vitest run",
"test:unit:coverage": "vitest run --coverage",
"test:unit": "vitest run --silent",
"test:unit:debug": "vitest run",
"test:unit:coverage": "vitest run --silent --coverage",
"test:unit:watch": "vitest",
"svelte:check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --ignore ./wagmi.config.ts",
"svelte:check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --ignore ./wagmi.config.ts --watch",
Expand All @@ -25,6 +26,7 @@
"@types/debug": "^4.1.7",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"@vitest/coverage-v8": "^0.33.0",
"@wagmi/cli": "^1.0.1",
"autoprefixer": "^10.4.14",
"daisyui": "3.1.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-ui-v2/src/components/Alert/Alert.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
};

const classes = classNames(
'alert gap-[5px] py-[12px] px-[20px] rounded-[10px]',
'alert flex gap-[5px] py-[12px] px-[20px] rounded-[10px]',
type ? typeMap[type].class : null,
forceColumnFlow ? 'grid-flow-col text-left' : null,
$$props.class,
Expand Down
24 changes: 2 additions & 22 deletions packages/bridge-ui-v2/src/components/Bridge/Bridge.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts">
import type { Chain } from '@wagmi/core';
import { t } from 'svelte-i18n';

import AmountInput from '$components/AmountInput';
Expand All @@ -10,34 +9,15 @@
import { ProcessingFee } from '$components/ProcessingFee';
import { RecipientInput } from '$components/RecipientInput';
import { TokenDropdown } from '$components/TokenDropdown';
import { web3modal } from '$libs/connect';
import { tokens } from '$libs/token';
import { destChain, srcChain } from '$stores/network';

function onSrcChainChange(chain: Chain) {
if (chain !== $srcChain) {
srcChain.set(chain);

// Let's not forget to update the default chain
// in web3modal. Unfortunately we have to maintain
// two states here due to the fact that the user
// can change the network from the UI.
web3modal.setDefaultChain(chain);
}
}

function onDestChainChange(chain: Chain) {
if (chain !== $destChain) {
destChain.set(chain);
}
}
</script>

<Card class="md:w-[524px]" title={$t('bridge.title')} text={$t('bridge.subtitle')}>
<div class="space-y-[35px]">
<div class="space-y-4">
<div class="space-y-2">
<ChainSelector label={$t('chain.from')} value={$srcChain} onChange={onSrcChainChange} />
<ChainSelector label={$t('chain.from')} value={$srcChain} />
<TokenDropdown {tokens} />
</div>

Expand All @@ -50,7 +30,7 @@
</div>

<div class="space-y-2">
<ChainSelector label={$t('chain.to')} value={$destChain} onChange={onDestChainChange} />
<ChainSelector label={$t('chain.to')} value={$destChain} />
<RecipientInput />
</div>
</div>
Expand Down
22 changes: 21 additions & 1 deletion packages/bridge-ui-v2/src/components/Button/Button.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { Spinner } from '$components/Spinner';
import { classNames } from '$libs/util/classNames';

type ButtonType =
Expand All @@ -16,6 +17,7 @@

export let type: Maybe<ButtonType> = null;
export let shape: Maybe<ButtonShape> = null;
export let loading = false;
export let outline = false;
export let block = false;
export let wide = false;
Expand All @@ -42,17 +44,35 @@
square: 'btn-square',
};

const classes = classNames(
$: classes = classNames(
'btn w-full h-auto min-h-fit border-0',

type === 'primary' ? 'body-bold' : 'body-regular',

type ? typeMap[type] : null,
shape ? shapeMap[shape] : null,

outline ? 'btn-outline' : null,
block ? 'btn-block' : null,
wide ? 'btn-wide' : null,

// For loading state we want to see well the content,
// since we're showing some important information.
loading ? 'btn-disabled !text-primary-content' : null,

$$props.class,
);

// Make sure to disable the button if we're in loading state
$: if (loading) {
$$restProps.disabled = true;
}
</script>

<button {...$$restProps} class={classes} on:click>
{#if loading}
<Spinner />
{/if}

<slot />
</button>
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<script lang="ts">
import type { Chain, GetNetworkResult } from '@wagmi/core';
import { type Chain, type GetNetworkResult, switchNetwork } from '@wagmi/core';
import type { ComponentType } from 'svelte';
import { noop, onDestroy } from 'svelte/internal';
import { onDestroy } from 'svelte/internal';
import { t } from 'svelte-i18n';
import { UserRejectedRequestError } from 'viem';

import { EthIcon, Icon, TaikoIcon } from '$components/Icon';
import { LoadingMask } from '$components/LoadingMask';
import { warningToast } from '$components/NotificationToast';
import { PUBLIC_L1_CHAIN_ID, PUBLIC_L2_CHAIN_ID } from '$env/static/public';
import { chains } from '$libs/chain';
import { uid } from '$libs/util/uid';
import { account } from '$stores/account';

// TODO: think about updating the state for the network here

export let label: string;
export let value: Maybe<GetNetworkResult['chain']> = null;
export let onChange: (chain: Chain) => void = noop;

let chainToIconMap: Record<string, ComponentType> = {
[PUBLIC_L1_CHAIN_ID]: EthIcon,
[PUBLIC_L2_CHAIN_ID]: TaikoIcon,
};

let switchingNetwork = false;
let buttonId = `button-${uid()}`;
let dialogId = `dialog-${uid()}`;
let modalOpen = false;
Expand All @@ -41,12 +41,23 @@
modalOpen = true;
}

function selectChain(chain: Chain) {
if (chain === value) return;
async function selectChain(chain: Chain) {
if (chain.id === value?.id) return;

switchingNetwork = true;

value = chain;
onChange?.(chain); // TODO: data binding? 🤔
closeModal();
try {
await switchNetwork({ chainId: chain.id });
closeModal();
} catch (error) {
console.error(error);

if (error instanceof UserRejectedRequestError) {
warningToast($t('messages.network.rejected'));
}
} finally {
switchingNetwork = false;
}
}

function getChainKeydownHandler(chain: Chain) {
Expand Down Expand Up @@ -86,22 +97,33 @@
</div>

<dialog id={dialogId} class="modal modal-bottom md:modal-middle" class:modal-open={modalOpen}>
<div class="modal-box relative px-6 py-[21px] bg-primary-base-background text-primary-base-content">
<button class="absolute right-6 top-[21px]" on:click={closeModal}>
<Icon type="x-close" fillClass="fill-secondary-icon" />
<div class="modal-box relative px-6 py-[35px] md:py-[20px] bg-primary-base-background text-primary-base-content">
{#if switchingNetwork}
<LoadingMask
class="bg-grey-0/60"
spinnerClass="border-primary-base-content"
text={$t('messages.network.switching')} />
{/if}

<button class="absolute right-6 top-[35px] md:top-[20px]" on:click={closeModal}>
<Icon type="x-close" fillClass="fill-secondary-icon" size={24} />
</button>
<h3 class="title-body-bold">{$t('chain_selector.placeholder')}</h3>
<ul class="menu space-y-4">
<h3 class="title-body-bold mb-[20px]">{$t('chain_selector.placeholder')}</h3>
<ul role="menu" class="space-y-4">
{#each chains as chain (chain.id)}
{@const disabled = chain.id === value?.id}
<li
role="menuitem"
tabindex="0"
class:opacity-50={chain === value}
aria-disabled={chain === value}
class="p-4 rounded-[10px]"
class:opacity-20={disabled}
class:hover:bg-grey-10={!disabled}
class:hover:cursor-pointer={!disabled}
aria-disabled={disabled}
on:click={() => selectChain(chain)}
on:keydown={getChainKeydownHandler(chain)}>
<!-- TODO: agree on hover:bg color -->
<div class="f-row justify-between hover:text-primary-base-content hover:bg-grey-10">
<div class="f-row justify-between">
<div class="f-items-center space-x-4">
<i role="img" aria-label={chain.name}>
<svelte:component this={chainToIconMap[chain.id]} size={32} />
Expand All @@ -114,7 +136,5 @@
{/each}
</ul>
</div>

<div class="overlay-backdrop" />
</dialog>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@
import { t } from 'svelte-i18n';

import { Button } from '$components/Button';
import { DesktopOrLarger } from '$components/DesktopOrLarger';
import { Icon } from '$components/Icon';
import { Spinner } from '$components/Spinner';
import { web3modal } from '$libs/connect';

export let connected = false;

// Will help us to programmatically show or hide the balance of
// the web3modal core button
let isDesktopOrLarger: boolean;

let web3modalOpen = false;
let unsubscribeWeb3Modal = noop;

$: web3ButtonBalance = connected && isDesktopOrLarger ? 'show' : 'hide';

function connectWallet() {
if (web3modalOpen) return;
web3modal.openModal();
}

Expand All @@ -28,19 +35,20 @@
onDestroy(unsubscribeWeb3Modal);
</script>

<DesktopOrLarger bind:is={isDesktopOrLarger} />

<!--
We are gonna make use of Web3Modal core button when we are connected,
which comes with interesting features out of the box.
https://docs.walletconnect.com/2.0/web/web3modal/html/wagmi/components
-->
{#if connected}
<w3m-core-button balance="show" />
<w3m-core-button balance={web3ButtonBalance} />
{:else}
<!-- TODO: fixing the width for English. i18n? -->
<Button class="px-[20px] py-2 rounded-full w-[215px]" type="neutral" on:click={connectWallet}>
<Button class="px-[20px] py-2 rounded-full w-[215px]" type="neutral" loading={web3modalOpen} on:click={connectWallet}>
<span class="body-regular f-items-center space-x-2">
{#if web3modalOpen}
<Spinner />
<span>{$t('wallet.status.connecting')}</span>
{:else}
<Icon type="user-circle" class="md-show-block" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script lang="ts">
import { onDestroy, onMount } from 'svelte';

// This component will help us to programmatically do the same as
// CSS media queries. We can use it to show/hide elements or render
// different components based on whether or not the size is desktop
// or larger
const mediaQuery = window.matchMedia('(min-width: 768px)');
export let is: boolean;

function mediaQueryHandler(event: MediaQueryListEvent) {
is = event.matches;
}

onMount(() => {
is = mediaQuery.matches;
mediaQuery.addEventListener('change', mediaQueryHandler);
});

onDestroy(() => {
mediaQuery.removeEventListener('change', mediaQueryHandler);
});

// TODO: maybe we want something more general purpose than just `md`?
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as DesktopOrLarger } from './DesktopOrLarger.svelte';
Loading