Skip to content

Commit

Permalink
feat(bridge-ui-v2): use web3modal (#14043)
Browse files Browse the repository at this point in the history
  • Loading branch information
jscriptcoder authored Jun 24, 2023
1 parent 4eec587 commit 911c701
Show file tree
Hide file tree
Showing 29 changed files with 273 additions and 39 deletions.
3 changes: 3 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ pre-commit:
bridge-ui:
glob: "packages/bridge-ui/**.{js,svelte,ts}"
run: pnpm -F bridge-ui lint:fix && git add {staged_files}
bridge-ui-v2:
glob: "packages/bridge-ui-v2/**.{js,ts,css,svelte}"
run: pnpm -F bridge-ui-v2 lint:fix && git add {staged_files}
protocol_sol:
glob: "packages/protocol/**.{sol}"
run: pnpm -F protocol lint:sol && git add {staged_files}
Expand Down
8 changes: 6 additions & 2 deletions packages/bridge-ui-v2/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Chain Names
export export PUBLIC_L1_CHAIN_NAME=""
export export PUBLIC_L2_CHAIN_NAME=""
export PUBLIC_L1_CHAIN_NAME=""
export PUBLIC_L2_CHAIN_NAME=""
export PUBLIC_L3_CHAIN_NAME=""


Expand Down Expand Up @@ -58,6 +58,10 @@ export PUBLIC_L3_SIGNAL_SERVICE_ADDRESS=0x
export PUBLIC_TEST_ERC20=[]


# Web3Modal Project ID
export PUBLIC_WEB3_MODAL_PROJECT_ID=""


# Sentry
export PUBLIC_SENTRY_DSN=https://

Expand Down
3 changes: 3 additions & 0 deletions packages/bridge-ui-v2/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode", "eslint.vscode-eslint"]
}
7 changes: 7 additions & 0 deletions packages/bridge-ui-v2/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
2 changes: 2 additions & 0 deletions packages/bridge-ui-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/adapter-static": "^2.0.2",
"@sveltejs/kit": "^1.5.0",
"@types/debug": "^4.1.7",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"autoprefixer": "^10.4.14",
Expand All @@ -47,6 +48,7 @@
"@web3modal/ethereum": "^2.4.7",
"@web3modal/html": "^2.4.7",
"debug": "^4.3.4",
"svelte-i18n": "^3.5.1",
"viem": "^1.0.7"
}
}
2 changes: 1 addition & 1 deletion packages/bridge-ui-v2/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
</script>
</head>
<body data-sveltekit-preload-data="hover">
%sveltekit.body%
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>
4 changes: 2 additions & 2 deletions packages/bridge-ui-v2/src/components/Button/Button.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { classNames } from '@libs/classNames';
import { classNames } from '$libs/util/classNames';
type ButtonType = 'neutral' | 'primary' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'error' | 'ghost';
type ButtonSize = 'lg' | 'md' | 'sm' | 'xs';
Expand Down Expand Up @@ -41,7 +41,7 @@
};
const classes = classNames(
'btn',
'btn btn-sm md:btn-md',
type ? typeMap[type] : null,
size ? sizeMap[size] : null,
shape ? shapeMap[shape] : null,
Expand Down
19 changes: 14 additions & 5 deletions packages/bridge-ui-v2/src/components/Header/Header.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
<script lang="ts">
import { web3modal } from '$libs/connect';
import { t } from '$libs/i18n';
import Button from '../Button';
import Icon from '../Icon';
import Logo from '../Logo';
import { LogoWithText } from '../Logo';
import { drawerToogleId } from '../SideNavigation';
</script>

<header class="sticky md:px-10 md:py-7 flex justify-between">
<header class="sticky p-2 md:px-10 md:py-7 flex justify-between md:justify-end items-center">
<div class="flex space-x-2 items-center md:hidden">
<label for={drawerToogleId} class="btn btn-ghost drawer-button">
<label for={drawerToogleId} class="btn btn-sm md:btn-md btn-ghost drawer-button">
<Icon type="bars-menu" />
</label>
<Logo />
<LogoWithText class="w-[88px] h-[24px]" />
</div>

<Button>Connect Wallet</Button>
<!-- <Button on:click={() => web3modal.openModal()} class="rounded-full" type="neutral">
<Icon type="user-circle" />
<span>{$t('wallet.connect')}</span>
</Button> -->

<!-- TODO: think about the possibility of actually using w3m-core-button component -->
<w3m-core-button balance="show" icon="hide" />
</header>
10 changes: 8 additions & 2 deletions packages/bridge-ui-v2/src/components/Icon/Icon.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script lang="ts">
type IconType = 'bridge' | 'faucet' | 'activities' | 'explorer' | 'guide' | 'bars-menu';
type IconType = 'bridge' | 'faucet' | 'activities' | 'explorer' | 'guide' | 'bars-menu' | 'user-circle';
export let type: IconType;
export let width = 20;
export let height = 20;
export let fillClass = 'fill-primary-icon';
</script>

<svg {width} {height} viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<svg {width} {height} class={$$props.class} viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
{#if type === 'bridge'}
<path
class={fillClass}
Expand Down Expand Up @@ -49,5 +49,11 @@
fill-rule="evenodd"
clip-rule="evenodd"
d="M2 4.75C2 4.33579 2.33579 4 2.75 4H17.25C17.6642 4 18 4.33579 18 4.75C18 5.16421 17.6642 5.5 17.25 5.5H2.75C2.33579 5.5 2 5.16421 2 4.75ZM2 10C2 9.58579 2.33579 9.25 2.75 9.25H17.25C17.6642 9.25 18 9.58579 18 10C18 10.4142 17.6642 10.75 17.25 10.75H2.75C2.33579 10.75 2 10.4142 2 10ZM2 15.25C2 14.8358 2.33579 14.5 2.75 14.5H17.25C17.6642 14.5 18 14.8358 18 15.25C18 15.6642 17.6642 16 17.25 16H2.75C2.33579 16 2 15.6642 2 15.25Z" />
{:else if type === 'user-circle'}
<path
class={fillClass}
fill-rule="evenodd"
clip-rule="evenodd"
d="M18 10C18 14.4183 14.4183 18 10 18C5.58172 18 2 14.4183 2 10C2 5.58172 5.58172 2 10 2C14.4183 2 18 5.58172 18 10ZM12.5 7.5C12.5 8.88071 11.3807 10 10 10C8.61929 10 7.5 8.88071 7.5 7.5C7.5 6.11929 8.61929 5 10 5C11.3807 5 12.5 6.11929 12.5 7.5ZM10 12C8.04133 12 6.30187 12.9385 5.20679 14.3904C6.39509 15.687 8.1026 16.5 10 16.5C11.8974 16.5 13.6049 15.687 14.7932 14.3904C13.6981 12.9385 11.9587 12 10 12Z" />
{/if}
</svg>
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<script lang="ts">
import { classNames } from '@libs/classNames';
type LinkTarget = '_blank' | '_self';
import { classNames } from '$libs/util/classNames';
export let active = false;
export let href = '/';
export let target: LinkTarget = '_self';
export let external = false;
$: activeClass = active ? 'bg-primary-interactive hover:bg-primary-interactive-hover' : '';
</script>

<a
{href}
{target}
class={classNames('btn btn-ghost rounded-full body-bold flex justify-start content-center', activeClass)}>
target={external ? '_blank' : null}
class={classNames(
'btn btn-sm md:btn-md btn-ghost p-3 rounded-full body-bold flex justify-start content-center',
activeClass,
)}>
<slot />
</a>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export let height = 34;
</script>

<svg {width} {height} viewBox="0 0 830 228" fill="none" xmlns="http://www.w3.org/2000/svg">
<svg {width} {height} class={$$props.class} viewBox="0 0 830 228" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
class={textFillClass}
d="M467.907 180.22C463.762 186.119 458.262 190.503 451.406 193.373C444.55 196.084 436.897 197.439 428.447 197.439C421.751 197.439 415.613 196.642 410.032 195.047C404.612 193.453 399.829 191.061 395.683 187.873C391.538 184.525 388.27 180.459 385.878 175.676C383.486 170.734 382.291 165.153 382.291 158.935C382.291 152.08 383.646 146.26 386.356 141.477C389.067 136.535 392.734 132.549 397.357 129.519C402.14 126.49 407.721 124.258 414.098 122.823C420.475 121.229 427.172 120.432 434.187 120.432H466.473C466.473 111.184 464.4 104.01 460.255 98.9079C456.109 93.8059 448.855 91.1753 438.492 91.0158C432.433 91.0158 427.172 92.0521 422.708 94.1248C418.403 96.1975 415.533 99.6253 414.098 104.408H386.117C387.074 97.7121 389.226 92.0521 392.574 87.4285C396.082 82.8049 400.227 78.9784 405.01 75.9492C409.953 72.9199 415.374 70.7675 421.273 69.4921C427.331 68.2166 433.39 67.5788 439.448 67.5788C447.261 67.5788 454.515 68.6151 461.211 70.6878C467.907 72.7605 473.727 76.268 478.669 81.2105C484.25 86.9502 487.996 93.8059 489.91 101.778C491.823 109.749 492.779 118.439 492.779 127.845V195.765H469.103L467.907 180.22ZM466.473 139.803H440.166C435.542 139.803 430.918 140.202 426.295 140.999C421.671 141.637 417.685 143.311 414.337 146.021C411.148 148.572 409.554 152.319 409.554 157.261C409.554 163.32 411.707 167.943 416.011 171.132C420.475 174.161 425.896 175.676 432.274 175.676C437.216 175.676 441.76 175.038 445.905 173.763C450.21 172.487 453.877 170.415 456.906 167.545C459.936 164.516 462.247 160.769 463.842 156.305C465.596 151.681 466.473 146.18 466.473 139.803Z" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<script lang="ts">
import { PUBLIC_GUIDE_URL, PUBLIC_L2_EXPLORER_URL } from '$env/static/public';
import { t } from '$libs/i18n';
import Icon from '../Icon';
import LinkButton from '../LinkButton';
Expand All @@ -20,39 +21,40 @@
<div class="drawer-side z-1 bg-primary-background">
<label for={drawerToogleId} class="drawer-overlay bg-overlay-background" />

<aside class="w-[226px] md:px-4 md:py-8 md:border-r md:border-r-grey-600 h-full">
<a href="/" class="hidden md:block">
<aside class="w-[226px] p-2 md:px-4 md:py-8 md:border-r md:border-r-grey-600 h-full">
<a href="/" class="hidden md:inline-block">
<LogoWithText />
</a>

<ul class="menu md:pt-10 space-y-2">
<li>
<LinkButton active>
<Icon type="bridge" fillClass="fill-white" />
<span>Bridge</span>
<span>{$t('nav.bridge')}</span>
</LinkButton>
</li>
<li>
<LinkButton href="/faucet">
<Icon type="faucet" />
<span>Faucet</span>
<span>{$t('nav.faucet')}</span>
</LinkButton>
</li>
<li>
<LinkButton href="/activities">
<Icon type="activities" />
<span>Activities</span>
<span>{$t('nav.activities')}</span>
</LinkButton>
</li>
<li>
<LinkButton href={PUBLIC_L2_EXPLORER_URL} target="_blank">
<LinkButton href={PUBLIC_L2_EXPLORER_URL} external>
<Icon type="explorer" />
<span>Exploreer</span>
<span>{$t('nav.explorer')}</span>
</LinkButton>
</li>
<li>
<LinkButton href={PUBLIC_GUIDE_URL} target="_blank">
<LinkButton href={PUBLIC_GUIDE_URL} external>
<Icon type="guide" />
<span>Guide</span>
<span>{$t('nav.guide')}</span>
</LinkButton>
</li>
</ul>
Expand Down
1 change: 0 additions & 1 deletion packages/bridge-ui-v2/src/libs/classNames/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/bridge-ui-v2/src/libs/connect/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { web3modal } from './web3modal';
28 changes: 28 additions & 0 deletions packages/bridge-ui-v2/src/libs/connect/web3modal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { EthereumClient } from '@web3modal/ethereum';
import { Web3Modal } from '@web3modal/html';

import { PUBLIC_WEB3_MODAL_PROJECT_ID } from '$env/static/public';
import { chains, wagmiConfig } from '$libs/wagmi';

const projectId = PUBLIC_WEB3_MODAL_PROJECT_ID;

const ethereumClient = new EthereumClient(wagmiConfig, chains);

export const web3modal = new Web3Modal(
{
projectId,
// TODO: can we bring these vars into Tailwind theme?
themeVariables: {
'--w3m-background-border-radius': '1.25rem',
'--w3m-container-border-radius': '0rem',
'--w3m-font-family': 'Public Sans, system-ui, sans-serif',
'--w3m-button-border-radius': '9999px',
'--w3m-accent-color': 'var(--primary-interactive)',
'--w3m-accent-fill-color': 'var(--primary-content)',
'--w3m-background-color': 'var(--neutral-background)',
// '--w3m-color-bg-1': 'var(--primary-background)',
// TODO: customize the rest of the theme variables
},
},
ethereumClient,
);
18 changes: 18 additions & 0 deletions packages/bridge-ui-v2/src/libs/i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"nav": {
"bridge": "Bridge",
"faucet": "Faucet",
"activities": "Activities",
"explorer": "Explorer",
"guide": "Guide"
},

"wallet": {
"connect": "Connect Wallet",
"status": {
"disconnected": "Disconnected",
"connected": "Connected",
"connecting": "Connecting..."
}
}
}
14 changes: 14 additions & 0 deletions packages/bridge-ui-v2/src/libs/i18n/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { addMessages, getLocaleFromNavigator, init } from 'svelte-i18n';

import en from './en.json';
// TODO: import other languages here...

export { _ } from 'svelte-i18n';

addMessages('en', en);
// TODO: add other languages here...

init({
fallbackLocale: 'en',
initialLocale: getLocaleFromNavigator(),
});
1 change: 1 addition & 0 deletions packages/bridge-ui-v2/src/libs/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { _ as t } from './i18n';
5 changes: 5 additions & 0 deletions packages/bridge-ui-v2/src/libs/util/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import debug from 'debug';

export function getLogger(namesapce: string) {
return debug(`bridge:${namesapce}`);
}
68 changes: 68 additions & 0 deletions packages/bridge-ui-v2/src/libs/wagmi/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { type Chain, configureChains, createConfig } from '@wagmi/core';
import { w3mConnectors, w3mProvider } from '@web3modal/ethereum';

import {
PUBLIC_L1_CHAIN_ID,
PUBLIC_L1_CHAIN_NAME,
PUBLIC_L1_EXPLORER_URL,
PUBLIC_L1_RPC_URL,
PUBLIC_L2_CHAIN_ID,
PUBLIC_L2_CHAIN_NAME,
PUBLIC_L2_EXPLORER_URL,
PUBLIC_L2_RPC_URL,
PUBLIC_WEB3_MODAL_PROJECT_ID,
} from '$env/static/public';

const projectId = PUBLIC_WEB3_MODAL_PROJECT_ID;

const mainnet: Chain = {
id: parseInt(PUBLIC_L1_CHAIN_ID),
name: PUBLIC_L1_CHAIN_NAME,
network: 'L1',
nativeCurrency: {
name: 'Ether',
symbol: 'ETH',
decimals: 18,
},
rpcUrls: {
public: { http: [PUBLIC_L1_RPC_URL] },
default: { http: [PUBLIC_L1_RPC_URL] },
},
blockExplorers: {
default: {
name: 'Main',
url: PUBLIC_L1_EXPLORER_URL,
},
},
};

const taiko: Chain = {
id: parseInt(PUBLIC_L2_CHAIN_ID),
name: PUBLIC_L2_CHAIN_NAME,
network: 'L2',
nativeCurrency: {
name: 'Ether',
symbol: 'ETH',
decimals: 18,
},
rpcUrls: {
public: { http: [PUBLIC_L2_RPC_URL] },
default: { http: [PUBLIC_L2_RPC_URL] },
},
blockExplorers: {
default: {
name: 'Main',
url: PUBLIC_L2_EXPLORER_URL,
},
},
};

export const chains = [mainnet, taiko];

export const { publicClient } = configureChains(chains, [w3mProvider({ projectId })]);

export const wagmiConfig = createConfig({
autoConnect: true,
connectors: w3mConnectors({ projectId, version: 2, chains }),
publicClient,
});
2 changes: 2 additions & 0 deletions packages/bridge-ui-v2/src/libs/wagmi/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './client';
export { startWatching, stopWatching } from './watcher';
Loading

0 comments on commit 911c701

Please sign in to comment.