-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,523 additions
and
112 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useAccount, useDisconnect, useEnsAvatar, useEnsName } from 'wagmi' | ||
import { useAccountBalance } from '../hooks/useAccountbalance' | ||
|
||
export function Account() { | ||
const { address } = useAccount() | ||
const { disconnect } = useDisconnect() | ||
const { data: ensName } = useEnsName({ address }) | ||
const { data: ensAvatar } = useEnsAvatar({ name: ensName! }) | ||
const balance = useAccountBalance() | ||
|
||
console.log(balance) | ||
|
||
return ( | ||
<div> | ||
{ensAvatar && <img alt="ENS Avatar" src={ensAvatar} />} | ||
{address && <div>{ensName ? `${ensName} (${address})` : address}</div>} | ||
<h1>Your balance is {balance !== null ? balance.toString() : 'Loading...'}</h1> | ||
<button onClick={() => disconnect()}>Disconnect</button> | ||
</div> | ||
) | ||
} |
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,18 @@ | ||
import { Button } from '@centrifuge/fabric' | ||
import { useConnect } from 'wagmi' | ||
|
||
export function WalletOptions() { | ||
const { connectors, connect } = useConnect() | ||
|
||
return connectors.map((connector) => ( | ||
<Button | ||
key={connector.uid} | ||
onClick={() => connect({ connector })} | ||
small | ||
variant="wallet" | ||
style={{ marginRight: 8, marginLeft: 8, marginTop: 8 }} | ||
> | ||
{connector.name} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { createConfig, http } from 'wagmi' | ||
import { base, mainnet } from 'wagmi/chains' | ||
import { coinbaseWallet, injected, metaMask, safe, walletConnect } from 'wagmi/connectors' | ||
|
||
const projectId = '492eaaf822c0081e5bab8f638789f3a2' | ||
|
||
export const wagmiConfig = createConfig({ | ||
chains: [mainnet, base], | ||
connectors: [injected(), walletConnect({ projectId }), metaMask(), safe(), coinbaseWallet()], | ||
transports: { | ||
[mainnet.id]: http(), | ||
[base.id]: http(), | ||
}, | ||
}) |
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 @@ | ||
import Centrifuge from '@centrifuge/centrifuge-sdk' | ||
import { useEffect, useState } from 'react' | ||
import { useAccount } from 'wagmi' | ||
|
||
type Balance = bigint | null | ||
|
||
export function useAccountBalance(): Balance { | ||
const { address, chain } = useAccount() | ||
const [balance, setBalance] = useState<Balance>(null) | ||
|
||
// const addressNumber = '0x423420Ae467df6e90291fd0252c0A8a637C1e03f' | ||
const chainId = 11155111 | ||
|
||
useEffect(() => { | ||
if (!address) return | ||
|
||
const fetchBalance = async () => { | ||
const centrifuge = new Centrifuge({ environment: 'demo' }) | ||
|
||
try { | ||
const accountQuery = centrifuge.account(address, chainId) | ||
accountQuery.subscribe({ | ||
next: (account) => { | ||
account.balances().subscribe({ | ||
next: (balanceValue) => { | ||
setBalance(BigInt(balanceValue)) | ||
}, | ||
error: (error) => console.error('Error fetching balance:', error), | ||
}) | ||
}, | ||
error: (error) => console.error('Error retrieving account:', error), | ||
}) | ||
} catch (error) { | ||
console.error('General Error:', error) | ||
} | ||
} | ||
|
||
fetchBalance() | ||
}, [address, chain]) | ||
|
||
return balance | ||
} |
Oops, something went wrong.