-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bridge-ui-v2): connect button (#14106)
- Loading branch information
1 parent
fcc154e
commit ccaa498
Showing
11 changed files
with
116 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,81 @@ | ||
<script lang="ts"> | ||
import { onDestroy, onMount } from 'svelte'; | ||
import { t } from 'svelte-i18n'; | ||
import { Button } from '$components/Button'; | ||
import { Icon } from '$components/Icon'; | ||
import { LogoWithText } from '$components/Logo'; | ||
import { drawerToggleId } from '$components/SideNavigation'; | ||
import { Spinner } from '$components/Spinner'; | ||
import { web3modal } from '$libs/connect'; | ||
export let connected = false; | ||
let web3modalOpen = false; | ||
let unsubscribeWeb3Modal: () => void; | ||
function connectWallet() { | ||
web3modal.openModal(); | ||
} | ||
function onWeb3Modal(state: { open: boolean }) { | ||
if (state.open) { | ||
web3modalOpen = true; | ||
} else { | ||
web3modalOpen = false; | ||
} | ||
} | ||
onMount(() => { | ||
unsubscribeWeb3Modal = web3modal.subscribeModal(onWeb3Modal); | ||
}); | ||
onDestroy(() => { | ||
unsubscribeWeb3Modal(); | ||
}); | ||
</script> | ||
|
||
<header | ||
class=" | ||
sticky-top | ||
f-between-center | ||
bg-primary-background | ||
z-10 | ||
px-4 | ||
py-[20px] | ||
border-b | ||
border-b-divider-border | ||
hide-under-b | ||
glassy-primary-background | ||
md:border-b-0 | ||
md:px-10 | ||
md:py-7 | ||
md:justify-end"> | ||
<LogoWithText class="w-[77px] h-[20px] md:hidden" /> | ||
|
||
<div class="f-items-center justify-end space-x-[10px]"> | ||
<Button class="px-[20px] py-2 rounded-full" type="neutral" on:click={() => web3modal.openModal()}> | ||
<Icon type="user-circle" class="md-show-block" /> | ||
<span class="body-small-regular">{$t('wallet.connect')}</span> | ||
</Button> | ||
<!-- | ||
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" /> | ||
{:else} | ||
<!-- TODO: fixing the width for English. i18n? --> | ||
<Button class="px-[20px] py-2 rounded-full w-[215px]" type="neutral" 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" /> | ||
<span>{$t('wallet.connect')}</span> | ||
{/if} | ||
</span> | ||
</Button> | ||
{/if} | ||
|
||
<label for={drawerToggleId} class="md:hidden"> | ||
<Icon type="bars-menu" /> | ||
</label> | ||
</div> | ||
|
||
<!-- TODO: think about the possibility of actually using w3m-core-button component --> | ||
<!-- <w3m-core-button balance="show" icon="hide" /> --> | ||
</header> |
13 changes: 13 additions & 0 deletions
13
packages/bridge-ui-v2/src/components/Spinner/Spinner.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script lang="ts"> | ||
import { classNames } from '$libs/util/classNames'; | ||
const classes = classNames( | ||
'w-6 h-6', | ||
'animate-spin', | ||
'box-border inline-block', | ||
'border-[3px] border-b-transparent rounded-full', | ||
$$props.class, | ||
); | ||
</script> | ||
|
||
<span class={classes} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as Spinner } from './Spinner.svelte'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.