Live token stats - #141
Conversation
jlkramer16
left a comment
There was a problem hiding this comment.
Main change is not depending on solscan's api which I think is why when I run locally I don't see much data (see screenshot). Using the RPC directly to call on-chain data will be good to get familiar with as its used all over the rest of the repos. Reference https://solana-labs.github.io/solana-web3.js/
| @@ -0,0 +1,14 @@ | |||
| export const DAO_TREASURY_ADDRESS = 'BRSda3A6o3czoPhsAEHjA5dZVrYL4uJ3JWXxwFSY9pJM'; | |||
| export const STAKING_OPTIONS_ADDRESSES = [ | |||
There was a problem hiding this comment.
Need to pull this list of accounts dynamically. They will change/expire over the course of time. Check out how we pull data into the SO (stakingOptions.tsx) tab as reference
| { label: 'GSO', value: 'GSO', disabled: false }, | ||
| { label: 'Treasury', value: 'Treasury', disabled: false }, | ||
| { label: 'Liquidity', value: 'Liquidity', disabled: false }, | ||
| { label: 'DUAL Stats', value: 'DUAL Stats', disabled: false }, |
| } | ||
|
|
||
| export async function getDualHolders(limit = 50, offset = 0): Promise<any> { | ||
| const url = `https://public-api.solscan.io/token/holders?tokenAddress=DUALa4FC2yREwZ59PHeu1un4wis36vHRv5hWVBmzykCJ&limit=${limit}&offset=${offset}`; |
There was a problem hiding this comment.
We prefer pulling the data directly on-chain, rather than depending on solscan's API. Use provider & hlper fcts like findProgramAddressWithMint & getMultipleTokenAccounts. Treasury.tsx has some good examples of how to do this
| async function fetchData() { | ||
| const newHolders = await getDualHolders(); | ||
| return newHolders; | ||
| } | ||
|
|
||
| fetchData() | ||
| .then((data) => { | ||
| if (data) { | ||
| setHolders(data as Holders); | ||
| } | ||
| }) | ||
| .catch(console.error); |
There was a problem hiding this comment.
nit: can avoid local scope helper altogether given that its a passthru function
| async function fetchData() { | |
| const newHolders = await getDualHolders(); | |
| return newHolders; | |
| } | |
| fetchData() | |
| .then((data) => { | |
| if (data) { | |
| setHolders(data as Holders); | |
| } | |
| }) | |
| .catch(console.error); | |
| getDualHolders() | |
| .then((data) => { | |
| if (data) { | |
| setHolders(data as Holders); | |
| } | |
| }) | |
| .catch(console.error); |
| async function fetchData() { | ||
| const newTokenMeta = await getDualTokenMeta(); | ||
| return newTokenMeta; | ||
| } | ||
|
|
||
| fetchData() | ||
| .then((data) => { | ||
| if (data) { | ||
| setTokenMeta(data as TokenMeta); | ||
| } | ||
| }) | ||
| .catch(console.error); |
There was a problem hiding this comment.
nit: can avoid local scope helper altogether given that its a passthru function
| async function fetchData() { | |
| const newTokenMeta = await getDualTokenMeta(); | |
| return newTokenMeta; | |
| } | |
| fetchData() | |
| .then((data) => { | |
| if (data) { | |
| setTokenMeta(data as TokenMeta); | |
| } | |
| }) | |
| .catch(console.error); | |
| getDualTokenMeta() | |
| .then((data) => { | |
| if (data) { | |
| setTokenMeta(data as TokenMeta); | |
| } | |
| }) | |
| .catch(console.error); |
| return data; | ||
| }; | ||
|
|
||
| return <DualfiTable columns={columns} pagination={{ pageSize: 50 }} dataSource={getData()} scroll={{ x: true }} />; |
There was a problem hiding this comment.
assuming data source can take a reference directly, its probably better for brevity's sake and one less context abstraction
| return <DualfiTable columns={columns} pagination={{ pageSize: 50 }} dataSource={getData()} scroll={{ x: true }} />; | |
| return <DualfiTable columns={columns} pagination={{ pageSize: 50 }} dataSource={data} scroll={{ x: true }} />; |
| const { price } = usePrice(); | ||
| const { holders } = useHolders(); | ||
| const { tokenMeta } = useTokenMeta(); | ||
| const [data, setData] = useState<StatsParams[]>([]); |
There was a problem hiding this comment.
Can you think of a more descriptive var name? we try to avoid data outside of business logic context where its more acceptable.

Closes #140