8000 Tackling an issue with Viem · jscriptcoder/DEX-Aggregator@04f66ef · GitHub
[go: up one dir, main page]

Skip to content

Commit 04f66ef

Browse files
committed
Tackling an issue with Viem
1 parent 2867c1c commit 04f66ef

File tree

4 files changed

+49
-14
lines changed

4 files changed

+49
-14
lines changed

src/app.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const apiConfig = {
22
// tokensUrl: 'https://tokens.coingecko.com/uniswap/all.json',
33
// tokensUrl: 'https://raw.githubusercontent.com/compound-finance/token-list/master/compound.tokenlist.json',
44
tokensUrl: 'https://static.optimism.io/optimism.tokenlist.json',
5+
// tokensUrl: 'api/tokenlist',
56
}
67

78
export const inputConfig = {

src/components/Swap/Swap.svelte

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,28 @@
167167
// and find out if it was successful or not. We don't need
168168
// to block the execution here. The user should still be able
169169
// to swap other tokens while we wait for the tx receipt
170-
waitForTransaction({ hash: swapTxHash, chainId: $network.id }).then((receipt) => {
171-
console.log('Swap tx receipt:', receipt)
172-
173-
switch (true) {
174-
case receipt.status === 'success':
175-
successToast($t('swap.success', { values: { from, to } }))
176-
break
177-
case receipt.status === 'reverted':
178-
errorToast($t('swap.reverted', withLinkValues), withLinkDuration)
179-
break
180-
}
181-
})
170+
waitForTransaction({ hash: swapTxHash, chainId: $network.id })
171+
.then((receipt) => {
172+
console.log('Swap tx receipt:', receipt)
173+
174+
switch (true) {
175+
case receipt.status === 'success':
176+
successToast($t('swap.success', { values: { from, to } }))
177+
break
178+
case receipt.status === 'reverted':
179+
errorToast($t('swap.reverted', withLinkValues), withLinkDuration)
180+
break
181+
}
182+
})
183+
.catch((err) => {
184+
console.error(err)
185+
// TODO: There seems to be a bug in Viem when the transaction is
186+
// reverted, throwing an exception internally:
187+
// <code>
188+
// const reason = hexToString3(`0x${code.substring(138)}`) // "code" is an object
189+
// </code>
190+
errorToast($t('swap.reverted', withLinkValues), withLinkDuration)
191+
})
182192
183193
// Step 5: Clear the form
184194
clearSwap()

src/libs/web3/chains.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Chain } from '@wagmi/core'
2-
import { arbitrum, mainnet, polygon, goerli, optimism, avalanche, base, bsc } from '@wagmi/core/chains'
2+
import { arbitrum, mainnet, polygon, goerli, optimism, avalanche, base, bsc, sepolia } from '@wagmi/core/chains'
33

4-
export const chains: Chain[] = [mainnet, goerli, arbitrum, optimism, polygon, avalanche, base, bsc]
4+
export const chains: Chain[] = [mainnet, sepolia, goerli, arbitrum, optimism, polygon, avalanche, base, bsc]
55

66
const iconChainBaseURL = 'https://icons.llamao.fi/icons/chains'
77
const apiBaseDomain = 'api.0x.org'
@@ -16,6 +16,10 @@ export const chainMetaMap: Record<number, ChainMeta> = {
1616
iconUrl: `${iconChainBaseURL}/rsz_ethereum.jpg`,
1717
apiBase: `https://${apiBaseDomain}`,
1818
},
19+
[sepolia.id]: {
20+
iconUrl: `${iconChainBaseURL}/rsz_ethereum.jpg`,
21+
apiBase: `https://sepolia.${apiBaseDomain}`,
22+
},
1923
[goerli.id]: {
2024
iconUrl: `${iconChainBaseURL}/rsz_ethereum.jpg`,
2125
apiBase: `https://goerli.${apiBaseDomain}`,

src/routes/api/tokenlist/+server.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// import type { RequestEvent } from '@sveltejs/kit'
2+
3+
const data = {
4+
name: 'Testing',
5+
tokens: [
6+
{
7+
chainId: 11155111,
8+
address: "0xf08A50178dfcDe18524640EA6618a1f965821715",
9+
name: "USDC",
10+
symbol: "USDC",
11+
decimals: 6,
12+
logoURI: "https://assets.coingecko.com/coins/images/6319/thumb/usdc.png?1696506694"
13+
}
14+
]
15+
}
16+
17+
export function GET() {
18+
19+
return Promise.resolve(new Response(JSON.stringify(data), { status: 200 }))
20+
}

0 commit comments

Comments
 (0)
0