Skip to content

Commit

Permalink
Merge pull request #9 from DLC-link/feat-add-token
Browse files Browse the repository at this point in the history
feat: add token to metamask button
  • Loading branch information
scolear authored Nov 24, 2023
2 parents 8dbafee + 7103c03 commit 812541c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Button, HStack, Image, Link, Text } from "@chakra-ui/react";
import { TutorialVideo } from "@components/tutorial-video/tutorial-video";
import { BlockchainContext } from "../../../../providers/blockchain-context-provider";

import { WalkthroughHeader } from "./components/walkthrough-header";
import { WalkthroughLayout } from "./components/walkthrough.layout";
import { useContext } from "react";

interface WalkthroughProps {
flow: "mint" | "unmint";
Expand All @@ -13,6 +15,9 @@ export function Walkthrough({
flow,
currentStep,
}: WalkthroughProps): React.JSX.Element {
const blockchainContext = useContext(BlockchainContext);
const ethereum = blockchainContext?.ethereum;

switch (flow) {
case "mint":
switch (currentStep) {
Expand Down Expand Up @@ -93,7 +98,10 @@ export function Walkthrough({
simply <span style={{ fontWeight: 800 }}>add them </span>
to your Ethereum Wallet.
</Text>
<Button variant={"vault"}>
<Button
variant={"vault"}
onClick={() => ethereum?.recommendDlcBtcTokenToMetamask()}
>
<HStack>
<Image
src={"/images/logos/dlc-btc-logo.svg"}
Expand All @@ -113,16 +121,6 @@ export function Walkthrough({
title={"Minted dlcBTC"}
blockchain={"ethereum"}
/>
<Button variant={"vault"}>
<HStack>
<Image
src={"/images/logos/dlc-btc-logo.svg"}
alt={"dlcBTC"}
boxSize={"25px"}
/>
<Text> Add Token to Wallet</Text>
</HStack>
</Button>
</WalkthroughLayout>
);
}
Expand Down
26 changes: 26 additions & 0 deletions src/app/hooks/use-ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface UseEthereumReturn {
getVault: (vaultUUID: string) => Promise<void>;
setupVault: (btcDepositAmount: number) => Promise<void>;
closeVault: (vaultUUID: string) => Promise<void>;
recommendDlcBtcTokenToMetamask: () => Promise<boolean>;
}

export function useEthereum(): UseEthereumReturn {
Expand Down Expand Up @@ -294,6 +295,30 @@ export function useEthereum(): UseEthereumReturn {
}
}

async function recommendDlcBtcTokenToMetamask(): Promise<boolean> {
try {
const { ethereum } = window;
if (!ethereum) return false;
const added = await ethereum.request({
method: "wallet_watchAsset",
params: {
type: "ERC20",
options: {
address: dlcBTCContract?.address,
symbol: "dlcBTC",
decimals: 8,
image:
"https://cdn.discordapp.com/attachments/994505799902691348/1035507437748367360/DLC.Link_Emoji.png",
},
},
});
return added;
} catch (error) {
console.error(error);
return false;
}
}

return {
protocolContract,
dlcManagerContract,
Expand All @@ -306,5 +331,6 @@ export function useEthereum(): UseEthereumReturn {
getVault,
setupVault,
closeVault,
recommendDlcBtcTokenToMetamask,
};
}

0 comments on commit 812541c

Please sign in to comment.