Skip to content

Commit 0eb481b

Browse files
committed
wip
1 parent 8328500 commit 0eb481b

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/app.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { zeroAddress } from "viem"
2+
13
export const apiConfig = {
24
tokensUrl: 'https://tokens.coingecko.com/uniswap/all.json',
35
// tokensUrl: 'https://erc20.cmc.eth.link/',
@@ -14,3 +16,11 @@ export const tokenSelectorConfig = {
1416
export const notificarionConfig = {
1517
duration: 5000,
1618
}
19+
20+
export const ethTokenConfig = {
21+
address: zeroAddress,
22+
name: 'Ether',
23+
symbol: 'ETH',
24+
decimals: 18,
25+
logoURI: 'https://etherscan.io/images/ethereum-icon.png',
26+
}

src/components/Swap/TokenSelector.svelte

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import fetchAllTokens from '../../libs/token/fetchAllTokens'
1010
import type { Token } from '../../libs/token/types'
1111
import Loading from '../Loading'
12-
import { inputConfig, tokenSelectorConfig } from '../../app.config'
12+
import { ethTokenConfig, inputConfig, tokenSelectorConfig } from '../../app.config'
13+
import { mainnet } from 'viem/chains'
1314
1415
export let value: Token
1516
export let onSelect: OnTokenSelect
@@ -75,8 +76,19 @@
7576
try {
7677
fetching = true
7778
const responseData = await fetchAllTokens()
79+
7880
tokens = filteredTokens = responseData.tokens
7981
82+
// We want to add ETH in our list of tokens as the first token
83+
tokens.unshift({
84+
chainId: mainnet.id, // TODO: other chains?
85+
address: ethTokenConfig.address,
86+
name: ethTokenConfig.name,
87+
symbol: ethTokenConfig.symbol,
88+
decimals: ethTokenConfig.decimals,
89+
logoURI: ethTokenConfig.logoURI,
90+
})
91+
8092
// Creates a map to quickly look up tokens based
8193
// on their name, symbol or address, by combining
8294
// them all into an unique index
@@ -103,7 +115,7 @@
103115
<button class="btn dark:btn-neutral btn-sm md:btn-md md:min-w-[140px]" on:click={openModal}>
104116
{#if value}
105117
<div class="flex items-center space-x-2">
106-
<div class="avatar">
118+
<div class="avatar w-6">
107119
<img src={value.logoURI} alt={value.name} />
108120
</div>
109121
<span class="token-label">{value.symbol}</span>
@@ -142,7 +154,7 @@
142154
disabled={token.address === disableValue?.address}
143155
class="btn btn-ghost w-full justify-start flex items-center space-x-2"
144156
on:click={() => selectToken(token)}>
145-
<div class="avatar w-[25px]">
157+
<div class="avatar w-6">
146158
<img src={token.logoURI} alt={token.name} />
147159
</div>
148160
<div class="flex flex-col items-start">

src/libs/api/0x.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
import { zeroAddress } from 'viem'
12
import type { GetPriceArgs, GetQuoteArgs, OxApiArgs, PriceResponseData, QuoteResponseData } from './types'
23

34
async function OxApi({ apiCall, sellToken, buyToken, sellAmount, chainId }: OxApiArgs) {
45
if (!apiCall || !sellToken || !buyToken || !sellAmount || !chainId) throw new Error('Missing arguments')
56

67
const queryParams = new URLSearchParams({
78
apiCall,
8-
sellToken,
9+
10+
// For Ether, which uses the zero address, we use the symbol instead of the address
11+
sellToken: sellToken === zeroAddress ? 'ETH' : sellToken,
12+
913
buyToken,
1014
sellAmount,
1115
chainId,

0 commit comments

Comments
 (0)