Skip to content

Live token stats - #141

Open
siirtecirlioglu wants to merge 1 commit into
Dual-Finance:masterfrom
siirtecirlioglu:live-token-stats
Open

Live token stats#141
siirtecirlioglu wants to merge 1 commit into
Dual-Finance:masterfrom
siirtecirlioglu:live-token-stats

Conversation

@siirtecirlioglu

Copy link
Copy Markdown

Closes #140

@jlkramer16
jlkramer16 requested review from brittcyr and jlkramer16 May 22, 2023 14:47

@jlkramer16 jlkramer16 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/

image

@@ -0,0 +1,14 @@
export const DAO_TREASURY_ADDRESS = 'BRSda3A6o3czoPhsAEHjA5dZVrYL4uJ3JWXxwFSY9pJM';
export const STAKING_OPTIONS_ADDRESSES = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread app/src/pages/index.tsx
{ 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 },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename just to "Token"

Comment thread app/src/utils/utils.ts
}

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}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +21 to +32
async function fetchData() {
const newHolders = await getDualHolders();
return newHolders;
}

fetchData()
.then((data) => {
if (data) {
setHolders(data as Holders);
}
})
.catch(console.error);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can avoid local scope helper altogether given that its a passthru function

Suggested change
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);

Comment on lines +19 to +30
async function fetchData() {
const newTokenMeta = await getDualTokenMeta();
return newTokenMeta;
}

fetchData()
.then((data) => {
if (data) {
setTokenMeta(data as TokenMeta);
}
})
.catch(console.error);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can avoid local scope helper altogether given that its a passthru function

Suggested change
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 }} />;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assuming data source can take a reference directly, its probably better for brevity's sake and one less context abstraction

Suggested change
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[]>([]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you think of a more descriptive var name? we try to avoid data outside of business logic context where its more acceptable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Live Token Stats

3 participants