-
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.
feat(bridge-ui): add token to wallet (#13902)
- Loading branch information
1 parent
2b21f59
commit 683b19c
Showing
5 changed files
with
61 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<script lang="ts"> | ||
import { UserRejectedRequestError } from '@wagmi/core'; | ||
import { L1_CHAIN_ID } from '../constants/envVars'; | ||
import type { Token } from '../domain/token'; | ||
import { token } from '../store/token'; | ||
import MetaMask from './icons/MetaMask.svelte'; | ||
import { errorToast, warningToast } from './NotificationToast.svelte'; | ||
async function addTokenToWallet(customToken: Token) { | ||
if (!customToken) { | ||
errorToast('Token not selected.'); | ||
return; | ||
} | ||
try { | ||
await window.ethereum.request({ | ||
method: 'wallet_watchAsset', | ||
params: { | ||
type: 'ERC20', | ||
options: { | ||
address: customToken.addresses[L1_CHAIN_ID], | ||
symbol: customToken.symbol, | ||
decimals: customToken.decimals, | ||
image: customToken.logoUrl, | ||
}, | ||
}, | ||
}); | ||
} catch (e) { | ||
if (e.code === 4001 || e?.data?.originalError?.code === 4001) { | ||
warningToast('Adding token has been rejected.'); | ||
} else { | ||
errorToast('Failed to add token to wallet'); | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<span | ||
class="inline-block cursor-pointer align-middle" | ||
on:click={() => addTokenToWallet($token)}> | ||
<MetaMask width={16} /></span> |
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
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