diff --git a/package.json b/package.json index 05a320f..2e2976a 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "tailwindcss-animate": "^1.0.7", "viem": "~2.17.3", "wagmi": "^2.10.10", + "youbet-sdk": "^0.0.7", "zod": "^3.23.8" }, "devDependencies": { diff --git a/src/components/layout/ConnectButton.tsx b/src/components/layout/ConnectButton.tsx index f0e088d..b145c41 100644 --- a/src/components/layout/ConnectButton.tsx +++ b/src/components/layout/ConnectButton.tsx @@ -1,4 +1,7 @@ import { ConnectButton } from '@rainbow-me/rainbowkit' +import Cookies from 'js-cookie' +import http from '../../service/instance' + export const CustomConnectButton = () => { return ( @@ -8,6 +11,26 @@ export const CustomConnectButton = () => { const ready = mounted && authenticationStatus !== 'loading' const connected = ready && account && chain && (!authenticationStatus || authenticationStatus === 'authenticated') + + const github = Cookies.get('username') + + const linkWallet = async () => { + console.log('call link') + if (connected) { + const address = account.address + const linkedAddress = await fetch(`/api/get-linked-wallet?github=${github}`).then((res) => res.text()) + console.log(linkedAddress) + if (linkedAddress == '0x0000000000000000000000000000000000000000') { + const res = await http.post('/link-wallet', { + github, + address, + }) + console.log(res) + } + } + } + linkWallet() + return (