-
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.
refactor(bridge-ui): alpha-3 (#13735)
Co-authored-by: Daniel Wang <99078276+dantaik@users.noreply.github.com> Co-authored-by: David <david@taiko.xyz> Co-authored-by: jeff <113397187+cyberhorsey@users.noreply.github.com>
- Loading branch information
1 parent
85cc830
commit 98017a2
Showing
139 changed files
with
6,426 additions
and
2,639 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
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,7 @@ | ||
import type { AxiosRequestConfig } from 'axios'; | ||
|
||
const axios = { | ||
get: jest.fn<Promise<unknown>, [string, AxiosRequestConfig<unknown>]>(), | ||
}; | ||
|
||
export default axios; |
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
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,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 /> |
Oops, something went wrong.