-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from astriaorg/develop
Dawn Release
- Loading branch information
Showing
16 changed files
with
278 additions
and
137 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
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
57 changes: 57 additions & 0 deletions
57
web/src/features/EthWallet/components/AddERC20ToWalletButton/AddERC20ToWalletButton.tsx
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,57 @@ | ||
import type { EvmCurrency } from "config"; | ||
|
||
import { useEthWallet } from "../../hooks/useEthWallet"; | ||
|
||
interface AddERC20ToWalletButtonProps { | ||
evmCurrency: EvmCurrency; | ||
buttonClassNameOverride?: string; | ||
} | ||
|
||
export default function AddERC20ToWalletButton({ | ||
evmCurrency, | ||
buttonClassNameOverride, | ||
}: AddERC20ToWalletButtonProps) { | ||
const { provider } = useEthWallet(); | ||
const buttonClassName = | ||
buttonClassNameOverride ?? "p-0 is-size-7 has-text-light is-ghost"; | ||
|
||
const addCoinToWallet = async () => { | ||
if (!provider) { | ||
return; | ||
} | ||
try { | ||
const wasAdded = await provider.send("wallet_watchAsset", { | ||
type: "ERC20", | ||
options: { | ||
address: evmCurrency.erc20ContractAddress, | ||
symbol: evmCurrency.coinDenom, | ||
decimals: evmCurrency.coinDecimals, | ||
}, | ||
}); | ||
|
||
if (wasAdded) { | ||
console.debug("ERC20 token added: ", evmCurrency.erc20ContractAddress); | ||
} else { | ||
console.debug( | ||
"User declined to add ERC20 token: ", | ||
evmCurrency.erc20ContractAddress, | ||
); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<button | ||
type="button" | ||
key={evmCurrency.coinMinimalDenom} | ||
onClick={() => addCoinToWallet()} | ||
className={`button is-underlined ${buttonClassName}`} | ||
> | ||
Add ERC20 to wallet | ||
</button> | ||
</> | ||
); | ||
} |
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
Oops, something went wrong.