-
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
10 changed files
with
2,778 additions
and
189 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1 @@ | ||
# React + TypeScript + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh | ||
|
||
## Expanding the ESLint configuration | ||
|
||
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: | ||
|
||
- Configure the top-level `parserOptions` property like this: | ||
|
||
```js | ||
export default tseslint.config({ | ||
languageOptions: { | ||
// other options... | ||
parserOptions: { | ||
project: ['./tsconfig.node.json', './tsconfig.app.json'], | ||
tsconfigRootDir: import.meta.dirname, | ||
}, | ||
}, | ||
}) | ||
``` | ||
|
||
- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked` | ||
- Optionally add `...tseslint.configs.stylisticTypeChecked` | ||
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config: | ||
|
||
```js | ||
// eslint.config.js | ||
import react from 'eslint-plugin-react' | ||
|
||
export default tseslint.config({ | ||
// Set the react version | ||
settings: { react: { version: '18.3' } }, | ||
plugins: { | ||
// Add the react plugin | ||
react, | ||
}, | ||
rules: { | ||
// other rules... | ||
// Enable its recommended rules | ||
...react.configs.recommended.rules, | ||
...react.configs['jsx-runtime'].rules, | ||
}, | ||
}) | ||
``` | ||
<!-- TO ADD --> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useAccount, useDisconnect, useEnsName } from 'wagmi' | ||
import { useAccountBalance } from '../hooks/useAccountbalance' | ||
|
||
export function Account() { | ||
const { address } = useAccount() | ||
const { disconnect } = useDisconnect() | ||
const { data: ensName } = useEnsName({ address }) | ||
const balance = useAccountBalance() | ||
|
||
return ( | ||
<div> | ||
{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,15 @@ | ||
import { useConnect } from 'wagmi' | ||
|
||
export function WalletOptions() { | ||
const { connectors, connect } = useConnect() | ||
|
||
return connectors.map((connector) => ( | ||
<button | ||
key={connector.uid} | ||
onClick={() => connect({ connector })} | ||
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,12 @@ | ||
import { createConfig, http } from 'wagmi' | ||
import { base, mainnet } from 'wagmi/chains' | ||
import { injected } from 'wagmi/connectors' | ||
|
||
export const wagmiConfig = createConfig({ | ||
chains: [mainnet, base], | ||
connectors: [injected()], | ||
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.