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

refactor(bridge-ui): alpha-3 #13735

Merged
merged 217 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 212 commits
Commits
Show all changes
217 commits
Select commit Hold shift + click to select a range
3f5c2bd
Update ABIs
jscriptcoder May 4, 2023
a58a527
Update ABIs
jscriptcoder May 4, 2023
b7bd6bf
Minor change
jscriptcoder May 4, 2023
fd3b747
Minor change
jscriptcoder May 4, 2023
4f07e10
Fix abi imports
jscriptcoder May 4, 2023
3553724
wip
jscriptcoder May 4, 2023
bd5da3f
Improvements
jscriptcoder May 5, 2023
48edaf1
Merge branch 'main' into update_abis
jscriptcoder May 5, 2023
c559c98
lock file got behind
jscriptcoder May 5, 2023
707f659
Merge branch 'update_abis' into select_chain
jscriptcoder May 5, 2023
7386e57
test selectChain
jscriptcoder May 5, 2023
7fe090a
remove comment
jscriptcoder May 5, 2023
757ed7f
improve copy-abi script
jscriptcoder May 6, 2023
8c6e824
add some comments
jscriptcoder May 6, 2023
779e26b
Minor change
jscriptcoder May 6, 2023
d15f1d2
minor change
jscriptcoder May 6, 2023
e1751f2
fix and improve recommendedProcessingFee test
jscriptcoder May 7, 2023
a8ef9b4
Merge branch 'main' into update_abis
dantaik May 8, 2023
89d9cba
Merge branch 'update_abis' into select_chain
jscriptcoder May 8, 2023
114a2cd
increase coverage
jscriptcoder May 8, 2023
d6d539d
Merge branch 'update_abis' into select_chain
jscriptcoder May 8, 2023
84bdde3
updated env vars to new values
jscriptcoder May 8, 2023
eb61329
Merge branch 'update_abis' of https://github.com/taikoxyz/taiko-mono …
jscriptcoder May 8, 2023
07c0f69
Merge branch 'update_abis' into select_chain
jscriptcoder May 8, 2023
d2433b4
Merge branch 'select_chain' of https://github.com/taikoxyz/taiko-mono…
jscriptcoder May 8, 2023
135130b
updated erc20 tokens
jscriptcoder May 8, 2023
718b004
updated erc20 tokens
jscriptcoder May 8, 2023
c0d6886
Merge branch 'update_abis' into select_chain
jscriptcoder May 8, 2023
fa96472
wip
jscriptcoder May 8, 2023
99740f1
wip
jscriptcoder May 8, 2023
f467f96
wip
jscriptcoder May 8, 2023
ceab4fe
add mintERC20 test
jscriptcoder May 8, 2023
c7e463f
add test
jscriptcoder May 9, 2023
f8f2388
use wagmi cli to grab the abis instead
jscriptcoder May 9, 2023
4c97f89
Minor change
jscriptcoder May 9, 2023
61bb0d8
ignore wagmi.config.ts
jscriptcoder May 9, 2023
6126122
ignore wagmi.config.ts
jscriptcoder May 9, 2023
44603ba
minor change
jscriptcoder May 9, 2023
6640dd0
test new config
jscriptcoder May 9, 2023
1dfd9e7
Minor change
jscriptcoder May 9, 2023
52cfb69
Another minor change
jscriptcoder May 9, 2023
0fefbfe
use Bridge.sol instead
jscriptcoder May 9, 2023
6d37071
Merge branch 'main' into update_abis
jscriptcoder May 9, 2023
8348282
Merge branch 'update_abis' into select_chain
jscriptcoder May 9, 2023
8a93d28
merge target
jscriptcoder May 9, 2023
0980f8a
fix abi imports
jscriptcoder May 9, 2023
599ff96
Merge branch 'main' into update_abis
jscriptcoder May 9, 2023
a0f8cc4
add logs
jscriptcoder May 9, 2023
863021f
wip
jscriptcoder May 9, 2023
2b1bcd4
Error with cause
jscriptcoder May 10, 2023
bb2accb
wip
jscriptcoder May 10, 2023
0fd5d08
wip
jscriptcoder May 10, 2023
5ae3b8e
wip: error handling
jscriptcoder May 10, 2023
e67d71a
wip
jscriptcoder May 11, 2023
2cf6f66
wip
jscriptcoder May 11, 2023
a036815
Merge branch 'main' into update_abis
jscriptcoder May 11, 2023
f9cdf06
update abis, again!!
jscriptcoder May 11, 2023
94650cb
Merge branch 'update_abis' of https://github.com/taikoxyz/taiko-mono …
jscriptcoder May 11, 2023
1b2d854
Merge branch 'update_abis' into select_chain
jscriptcoder May 11, 2023
c72f2e4
merge latest changes
jscriptcoder May 11, 2023
a711e02
wip
jscriptcoder May 11, 2023
aa8a0b9
wip
jscriptcoder May 11, 2023
b37cc26
fix conflicts
jscriptcoder May 11, 2023
c6f7f13
fix conflicts
jscriptcoder May 11, 2023
92ed42a
Merge branch 'select_chain' into error_handling
jscriptcoder May 11, 2023
4170dfa
better lower case error messages
jscriptcoder May 12, 2023
080e792
wip
jscriptcoder May 12, 2023
c686c81
fix proof
jscriptcoder May 12, 2023
26fb1d5
merge main
jscriptcoder May 15, 2023
f24ace7
wip
jscriptcoder May 15, 2023
283b88f
wip
jscriptcoder May 15, 2023
886cfab
Merge branch 'main' into error_handling
jscriptcoder May 16, 2023
3273591
wip
jscriptcoder May 16, 2023
61500b1
wip: more error handling and logging. Extracting some logic
jscriptcoder May 16, 2023
f6e1ccf
add console.error to see specific error message
jscriptcoder May 16, 2023
7359dfa
extract wagmi logic
jscriptcoder May 16, 2023
d3f7c89
minor change
jscriptcoder May 16, 2023
9888fa0
comment out relayer stuff
jscriptcoder May 16, 2023
c779e3e
minor change
jscriptcoder May 16, 2023
c89bbf3
update env vars in README file
jscriptcoder May 16, 2023
5729b6e
some improvements
jscriptcoder May 16, 2023
a8a7f89
Merge branch 'main' into error_handling
jscriptcoder May 16, 2023
a791bbb
Merge branch 'main' into error_handling
jscriptcoder May 17, 2023
52ed93a
Merge branch 'error_handling' of https://github.com/taikoxyz/taiko-mo…
jscriptcoder May 17, 2023
a4f173a
increase converage
jscriptcoder May 17, 2023
cd57429
more coverage
jscriptcoder May 17, 2023
97f63df
add more tests
jscriptcoder May 17, 2023
54e1919
add more tests
jscriptcoder May 17, 2023
1e9c963
temporal change: decresing coverage values
jscriptcoder May 17, 2023
3f159da
minor change
jscriptcoder May 17, 2023
7bd4ddf
empty amount input
jscriptcoder May 17, 2023
bd5cc0f
Merge branch 'main' into error_handling
jscriptcoder May 18, 2023
184a4f7
add more debugging
jscriptcoder May 18, 2023
0f87ce1
more changes done
jscriptcoder May 18, 2023
b96d240
Minor change
jscriptcoder May 18, 2023
dd885e3
translations
jscriptcoder May 18, 2023
9b66613
minor change
jscriptcoder May 18, 2023
47ad95f
minor change
jscriptcoder May 18, 2023
dbe1050
minor changes
jscriptcoder May 18, 2023
1f2e1ac
improvements
jscriptcoder May 18, 2023
7f2116c
remove unnecessary code
jscriptcoder May 18, 2023
dfaa939
remove unnecessary provider
jscriptcoder May 18, 2023
a8e4d79
fix issue changing tx status
jscriptcoder May 18, 2023
2bf6347
add relayer
jscriptcoder May 19, 2023
ba40a1d
improve performance
jscriptcoder May 19, 2023
6941dce
minor TODO
jscriptcoder May 19, 2023
c6c0131
increase coverage
jscriptcoder May 19, 2023
bdc9ae7
mock axios to fix an issue
jscriptcoder May 19, 2023
fb8b3ed
add TODOs
jscriptcoder May 19, 2023
a80c7ce
Merge branch 'main' into error_handling
jscriptcoder May 19, 2023
8b848b6
revert changelog whitepaper
jscriptcoder May 19, 2023
ae3ee68
Merge branch 'error_handling' of https://github.com/taikoxyz/taiko-mo…
jscriptcoder May 19, 2023
ba4e78e
revert changelog whitepaper
jscriptcoder May 19, 2023
d655529
improve paginator
jscriptcoder May 19, 2023
96570db
turn off rule temporarily
jscriptcoder May 19, 2023
ff31177
minor improvement
jscriptcoder May 19, 2023
2487d4a
remove unnecessary imports
jscriptcoder May 19, 2023
a861d0f
minor changes
jscriptcoder May 19, 2023
33d401c
add some clarification
jscriptcoder May 19, 2023
48924bc
playing around with messages
jscriptcoder May 19, 2023
fbf462d
minor change
jscriptcoder May 19, 2023
48117c9
fix pagination
jscriptcoder May 19, 2023
4118107
improve messaging
jscriptcoder May 19, 2023
324b10d
fix an issue when reconnecting
jscriptcoder May 19, 2023
9610d8b
minor changes
jscriptcoder May 19, 2023
8375492
add reject tx message
jscriptcoder May 19, 2023
37d9db3
feedback addressed
jscriptcoder May 20, 2023
08d84c6
Merge branch 'main' into error_handling
jscriptcoder May 20, 2023
cc2b969
aligning to design
jscriptcoder May 20, 2023
4184c24
minor change
jscriptcoder May 20, 2023
db5fa37
improve styling
jscriptcoder May 20, 2023
7072426
styling
jscriptcoder May 20, 2023
b824fc8
styling
jscriptcoder May 20, 2023
95b4863
styling guide
jscriptcoder May 20, 2023
6c2596a
logo in small devices
jscriptcoder May 20, 2023
074362a
remove import
jscriptcoder May 20, 2023
09135f4
minor changes
jscriptcoder May 20, 2023
2eaf961
revert CHANGELOG.md
jscriptcoder May 22, 2023
6b67d8c
revert CHANGELOG.md
jscriptcoder May 22, 2023
03aad4e
revert CHANGELOG.md
jscriptcoder May 22, 2023
21ec78d
revert CHANGELOG.md
jscriptcoder May 22, 2023
a63ccbb
revert CHANGELOG.md
jscriptcoder May 22, 2023
d09d744
revert CHANGELOG.md
jscriptcoder May 22, 2023
9613a58
Merge branch 'main' into error_handling
jscriptcoder May 22, 2023
7696438
improves around custom tokens
jscriptcoder May 22, 2023
a388a0e
minor improvements
jscriptcoder May 22, 2023
0216e16
minor change
jscriptcoder May 22, 2023
ea7fe03
minor changes
jscriptcoder May 22, 2023
e75a0d7
improve memo
jscriptcoder May 22, 2023
cbee5b8
align logo and guide
jscriptcoder May 23, 2023
67254c6
wip
jscriptcoder May 23, 2023
52b0060
add stepper
jscriptcoder May 23, 2023
2b8a6ea
minor change
jscriptcoder May 23, 2023
e0ce89e
minor improvement
jscriptcoder May 23, 2023
86dbba6
fixed two messages informing about funds claimed
jscriptcoder May 23, 2023
4a1f76e
wip
jscriptcoder May 24, 2023
4856740
components folder restructuring
jscriptcoder May 24, 2023
0d093e0
minor change
jscriptcoder May 24, 2023
d6a38e9
increase coverage in token
jscriptcoder May 24, 2023
2aca86d
fix lint warning
jscriptcoder May 24, 2023
cd92d45
rename for consistency
jscriptcoder May 24, 2023
e4ee7f8
fix issue with approve-bridge steps
jscriptcoder May 24, 2023
78e629a
wip: Faucet
jscriptcoder May 24, 2023
a4e05df
commend out current faucet
jscriptcoder May 24, 2023
d88ca4a
Merge branch 'main' into error_handling
jscriptcoder May 24, 2023
d0f9b56
wip: Faucet
jscriptcoder May 24, 2023
24fe4e9
wip: Faucet
jscriptcoder May 25, 2023
7437a1f
add Faucet
jscriptcoder May 25, 2023
0c01124
revert CHANGELOG.md
jscriptcoder May 25, 2023
948116c
wip: PoC stepper
jscriptcoder May 25, 2023
64728a0
Merge branch 'error_handling' of https://github.com/taikoxyz/taiko-mo…
jscriptcoder May 25, 2023
c6b1ffa
add new flow for approve-bridge
jscriptcoder May 25, 2023
00fee60
imports sorting
jscriptcoder May 25, 2023
bb01cfc
Merge branch 'main' into error_handling
jscriptcoder May 25, 2023
5d4716f
minor fix
jscriptcoder May 25, 2023
398d393
remove unnecessary package
jscriptcoder May 25, 2023
96b4958
Merge branch 'error_handling' of https://github.com/taikoxyz/taiko-mo…
jscriptcoder May 25, 2023
da83670
rename methods
jscriptcoder May 25, 2023
8e31950
revert CHANGELOG.md
jscriptcoder May 25, 2023
0923d0c
minor changes
jscriptcoder May 25, 2023
685811a
Merge branch 'error_handling' of https://github.com/taikoxyz/taiko-mo…
jscriptcoder May 25, 2023
601c74b
some styling improvements
jscriptcoder May 25, 2023
11f6e30
more styling improvements
jscriptcoder May 25, 2023
babc9fe
provide with network swtich
jscriptcoder May 26, 2023
d4f02f4
Merge branch 'main' into error_handling
davidtaikocha May 26, 2023
62ef52d
prevent switching network while ongoing transaction
jscriptcoder May 26, 2023
ad9a004
Merge branch 'error_handling' of https://github.com/taikoxyz/taiko-mo…
jscriptcoder May 26, 2023
528b210
prevent switching network when tx ongoing
jscriptcoder May 26, 2023
65c0164
update abis
jscriptcoder May 26, 2023
7d89537
fix issue when selecting the token from the faucet
jscriptcoder May 26, 2023
f016fe5
improvements
jscriptcoder May 26, 2023
2dd896e
trigger reactivity on token selected token
jscriptcoder May 26, 2023
9bda92b
test subscriber
jscriptcoder May 26, 2023
4fcae85
Merge branch 'main' into error_handling
cyberhorsey May 29, 2023
b377606
minor change
jscriptcoder May 29, 2023
04c622a
remove error toast on error computing fees
jscriptcoder May 29, 2023
bb286db
Merge branch 'main' into error_handling
jscriptcoder May 29, 2023
31d06c1
Merge branch 'main' into error_handling
jscriptcoder May 30, 2023
bdde471
minor changes
jscriptcoder May 30, 2023
480ed4f
remove unnecessary dependencies
jscriptcoder May 30, 2023
4312a39
wip: Relayer unit tests
jscriptcoder May 30, 2023
2cc097a
wip: Relayer unit tests
jscriptcoder May 30, 2023
b3c64dc
use same success message in the poller
jscriptcoder May 30, 2023
91e0d32
minor change
jscriptcoder May 30, 2023
8eb7e82
fix pending transactions
jscriptcoder May 30, 2023
e82f5d1
minor change
jscriptcoder May 30, 2023
126d3e9
minor change
jscriptcoder May 30, 2023
2bf48eb
minor change
jscriptcoder May 30, 2023
8d48ba1
minor change in log messages
jscriptcoder May 30, 2023
b185fa1
better looking navbar on desktop
jscriptcoder May 30, 2023
202c910
add comment
jscriptcoder May 30, 2023
80d556d
remove previous approve bridge 2 steps
jscriptcoder May 30, 2023
8092e03
Merge branch 'main' into error_handling
dantaik May 31, 2023
c66fe6a
Merge branch 'main' into error_handling
jscriptcoder May 31, 2023
ae192d6
rename selectToken to selectTokenAndBridgeType
jscriptcoder May 31, 2023
8a3c327
Merge branch 'error_handling' of https://github.com/taikoxyz/taiko-mo…
jscriptcoder May 31, 2023
0ed478a
return object instead
jscriptcoder May 31, 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
9 changes: 5 additions & 4 deletions packages/bridge-ui/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ module.exports = {
sourceType: 'module',
extraFileExtensions: ['.svelte'],
},
plugins: ['svelte3', '@typescript-eslint' /*, 'simple-import-sort'*/],
plugins: ['svelte3', '@typescript-eslint', 'simple-import-sort'],
rules: {
'linebreak-style': ['error', 'unix'],
// 'simple-import-sort/imports': 'error',
// 'simple-import-sort/exports': 'error',
semi: ['error', 'always'],
'linebreak-style': ['error', 'unix'],
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'no-console': ['error', { allow: ['warn', 'error'] }],
'no-irregular-whitespace': 'off',
},
Expand Down Expand Up @@ -51,6 +51,7 @@ module.exports = {
'@typescript-eslint/no-misused-promises': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
},
},
{
Expand Down
18 changes: 9 additions & 9 deletions packages/bridge-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,36 @@ You can use the following values in the `.env` file to spin up the Bridge UI loc

```
VITE_L1_RPC_URL=https://l1rpc.internal.taiko.xyz
VITE_L2_RPC_URL=https://l2rpc.internal.taiko.xyz
VITE_L2_RPC_URL=https://rpc.internal.taiko.xyz
VITE_L3_RPC_URL=https://l3rpc.internal.taiko.xyz

VITE_L1_EXPLORER_URL=https://l1explorer.internal.taiko.xyz
VITE_L2_EXPLORER_URL=https://l2explorer.internal.taiko.xyz
VITE_L2_EXPLORER_URL=https://explorer.internal.taiko.xyz
VITE_L3_EXPLORER_URL=https://l3explorer.internal.taiko.xyz

VITE_RELAYER_URL=https://relayer.internal.taiko.xyz/
VITE_RELAYER_URL=https://relayer.internal.taiko.xyz

VITE_L1_CHAIN_ID=31336
VITE_L2_CHAIN_ID=167001
VITE_L3_CHAIN_ID=167002

VITE_L1_CHAIN_NAME="Ethereum A3"
VITE_L2_CHAIN_NAME="Taiko A3"
VITE_L3_CHAIN_NAME="L3 Chain A3"
VITE_L1_CHAIN_NAME="Ethereum"
VITE_L2_CHAIN_NAME="Taiko"
VITE_L3_CHAIN_NAME="L3 Chain"

VITE_L1_CROSS_CHAIN_SYNC_ADDRESS=0x0B306BF915C4d645ff596e518fAf3F9669b97016
VITE_L2_CROSS_CHAIN_SYNC_ADDRESS=0x1000777700000000000000000000000000000001
VITE_L3_CROSS_CHAIN_SYNC_ADDRESS=0x1000777700000000000000000000000000000001

VITE_L1_TOKEN_VAULT_ADDRESS=0x4ed7c70F96B99c776995fB64377f0d4aB3B0e1C1
VITE_L1_TOKEN_VAULT_ADDRESS=0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44
VITE_L2_TOKEN_VAULT_ADDRESS=0x1000777700000000000000000000000000000002
VITE_L3_TOKEN_VAULT_ADDRESS=0x1000777700000000000000000000000000000002

VITE_L1_BRIDGE_ADDRESS=0x3Aa5ebB10DC797CAC828524e59A333d0A371443c
VITE_L1_BRIDGE_ADDRESS=0xc6e7DF5E7b4f2A278906862b61205850344D4e7d
VITE_L2_BRIDGE_ADDRESS=0x1000777700000000000000000000000000000004
VITE_L3_BRIDGE_ADDRESS=0x1000777700000000000000000000000000000004

VITE_L1_SIGNAL_SERVICE_ADDRESS=0x4A679253410272dd5232B3Ff7cF5dbB88f295319
VITE_L1_SIGNAL_SERVICE_ADDRESS=0x7a2088a1bFc9d81c55368AE168C2C02570cB814F
VITE_L2_SIGNAL_SERVICE_ADDRESS=0x1000777700000000000000000000000000000007
VITE_L3_SIGNAL_SERVICE_ADDRESS=0x1000777700000000000000000000000000000007

Expand Down
7 changes: 7 additions & 0 deletions packages/bridge-ui/__mocks__/axios/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { AxiosRequestConfig } from 'axios';

const axios = {
get: jest.fn<Promise<unknown>, [string, AxiosRequestConfig<unknown>]>(),
};

export default axios;
4 changes: 2 additions & 2 deletions packages/bridge-ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap"
href="https://fonts.googleapis.com/css2?family=Public+Sans:wght@400;500;700&display=swap"
rel="stylesheet" />

<title>Bridge</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
<script type="module" src="src/app.ts"></script>
</body>

<script>
Expand Down
14 changes: 10 additions & 4 deletions packages/bridge-ui/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ export default {
],
coverageThreshold: {
global: {
statements: 95,
branches: 87, // TODO: increase to 90
functions: 94,
lines: 95,
// TODO: temporal coverage decrease due to new logic,
// services, utils and and error handling.
// Mising tests for:
// - relayer-api/RelayerAPIService (partial test coverage)
// - bridge/ERC20Bridge (partial test coverage)
// - bridge/ETHBridge (partial test coverage)
statements: 89,
branches: 86,
functions: 91,
lines: 89,
},
},
modulePathIgnorePatterns: ['<rootDir>/public/build/'],
Expand Down
6 changes: 3 additions & 3 deletions packages/bridge-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"build": "vite build",
"preview": "vite preview",
"svelte:check": "svelte-check --tsconfig ./tsconfig.json --ignore ./wagmi.config.ts",
"test": "pnpm exec jest",
"test": "pnpm exec jest --silent",
"test:debug": "pnpm exec jest",
"prettier": "pnpm exec prettier '**/*.{js,ts,svelte}'",
"prettier:write": "pnpm run prettier '**/*.{js,ts,svelte}' --write",
"prettier:check": "pnpm run prettier '**/*.{js,ts,svelte}' --check",
Expand Down Expand Up @@ -63,8 +64,7 @@
"ts-loader": "^9.2.6",
"tslib": "^2.4.0",
"typescript": "^4.6.4",
"vite": "^3.0.0",
"vite-plugin-static-copy": "^0.12.0"
"vite": "^3.0.0"
},
"dependencies": {
"@coinbase/wallet-sdk": "^3.6.3",
Expand Down
Binary file modified packages/bridge-ui/public/taiko-favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
180 changes: 12 additions & 168 deletions packages/bridge-ui/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,176 +1,20 @@
<script lang="ts">
import QueryProvider from './components/providers/QueryProvider.svelte';
import { configureChains, createClient } from '@wagmi/core';
import { publicProvider } from '@wagmi/core/providers/public';
import { jsonRpcProvider } from '@wagmi/core/providers/jsonRpc';
import { CoinbaseWalletConnector } from '@wagmi/core/connectors/coinbaseWallet';
import { WalletConnectConnector } from '@wagmi/core/connectors/walletConnect';
import { MetaMaskConnector } from '@wagmi/core/connectors/metaMask';
import { onDestroy, onMount } from 'svelte';

import { setupI18n } from './i18n';
import { transactions } from './store/transactions';
import Navbar from './components/Navbar.svelte';
import Toast, { successToast } from './components/Toast.svelte';
import { signer } from './store/signer';
import type { BridgeTransaction } from './domain/transactions';
import { wagmiClient } from './store/wagmi';

setupI18n({ withLocale: 'en' });
import SwitchEthereumChainModal from './components/modals/SwitchEthereumChainModal.svelte';
import { ethers } from 'ethers';
import { MessageStatus } from './domain/message';
import { bridgeABI } from './constants/abi';
import { userTokens } from './store/userToken';
import { RelayerAPIService } from './relayer-api/RelayerAPIService';
import {
DEFAULT_PAGE,
MAX_PAGE_SIZE,
type RelayerAPI,
} from './domain/relayerApi';
import {
paginationInfo,
relayerApi,
relayerBlockInfoMap,
} from './store/relayerApi';
import { chains, mainnetWagmiChain, taikoWagmiChain } from './chain/chains';
import { providers } from './provider/providers';
import { RELAYER_URL } from './constants/envVars';
import NotificationToast from './components/NotificationToast.svelte';
import Router from './components/Router.svelte';
import { storageService, tokenService } from './storage/services';

const { chains: wagmiChains, provider } = configureChains(
[mainnetWagmiChain, taikoWagmiChain],
[
publicProvider(),
jsonRpcProvider({
rpc: (chain) => ({
http: providers[chain.id].connection.url,
}),
}),
],
);

$wagmiClient = createClient({
autoConnect: true,
provider,
connectors: [
new MetaMaskConnector({
chains: wagmiChains,
}),
new CoinbaseWalletConnector({
chains: wagmiChains,
options: {
appName: 'Taiko Bridge',
},
}),
new WalletConnectConnector({
chains: wagmiChains,
options: {
qrcode: true,
},
}),
],
});

const relayerApiService: RelayerAPI = new RelayerAPIService(
RELAYER_URL,
providers,
);

relayerApi.set(relayerApiService);

signer.subscribe(async (store) => {
if (store) {
const userAddress = await store.getAddress();

const { txs: apiTxs, paginationInfo: info } =
await $relayerApi.getAllBridgeTransactionByAddress(userAddress, {
page: DEFAULT_PAGE,
size: MAX_PAGE_SIZE,
});

paginationInfo.set(info);

const blockInfoMap = await $relayerApi.getBlockInfo();
relayerBlockInfoMap.set(blockInfoMap);

const txs = await storageService.getAllByAddress(userAddress);
const hashToApiTxsMap = new Map(
apiTxs.map((tx) => {
return [tx.hash.toLowerCase(), 1];
}),
);

const updatedStorageTxs: BridgeTransaction[] = txs.filter((tx) => {
return !hashToApiTxsMap.has(tx.hash.toLowerCase());
});

storageService.updateStorageByAddress(userAddress, updatedStorageTxs);

transactions.set([...updatedStorageTxs, ...apiTxs]);

const tokens = tokenService.getTokens(userAddress);
userTokens.set(tokens);
}
});

const transactionToIntervalMap = new Map();

transactions.subscribe((store) => {
if (store) {
store.forEach((tx) => {
const txInterval = transactionToIntervalMap.get(tx.hash);
if (txInterval) {
clearInterval(txInterval);
transactionToIntervalMap.delete(tx.hash);
}

if (tx.status === MessageStatus.New) {
const provider = providers[tx.toChainId];

const interval = setInterval(async () => {
const txInterval = transactionToIntervalMap.get(tx.hash);
if (txInterval !== interval) {
clearInterval(txInterval);
transactionToIntervalMap.delete(tx.hash);
}

transactionToIntervalMap.set(tx.hash, interval);
if (!tx.msgHash) return;

const contract = new ethers.Contract(
chains[tx.toChainId].bridgeAddress,
bridgeABI,
provider,
);

const messageStatus: MessageStatus =
await contract.getMessageStatus(tx.msgHash);
import SwitchChainModal from './components/SwitchChainModal.svelte';
import { startWatching, stopWatching } from './wagmi/watcher';

if (messageStatus === MessageStatus.Done) {
successToast('Bridge message processed successfully');
const txOngoingInterval = transactionToIntervalMap.get(tx.hash);
clearInterval(txOngoingInterval);
transactionToIntervalMap.delete(tx.hash);
}
}, 20 * 1000);
}
});
}
});
onMount(startWatching);
onDestroy(stopWatching);
</script>

<QueryProvider>
<main>
<Navbar />
<Router />
</main>
<Toast />
<SwitchEthereumChainModal />
</QueryProvider>
<main>
<Navbar />
<Router />
</main>

<style>
main {
font-family: 'Inter', sans-serif;
}
</style>
<NotificationToast />
<SwitchChainModal />
Loading