Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: multi chain balances #6019

Merged
merged 11 commits into from
May 20, 2023
Merged

feat: multi chain balances #6019

merged 11 commits into from
May 20, 2023

Conversation

preschian
Copy link
Member

@preschian preschian commented May 17, 2023

Thank you for your contribution to the KodaDot - One Stop Shop for Polkadot NFTs.

👇 __ Let's make a quick check before the contribution.

PR Type

  • Bugfix
  • Feature
  • Refactoring

Context

image

Had issue bounty label?

  • Fill up your KSM address: Payout

Todo

  • for now, every time we open the sidebar there it always shows the skeleton component. will try to improve that in the next PR

Copilot Summary

🤖 Generated by Copilot at 18988f4

This pull request adds a new feature to show the balances of different tokens and chains for the connected wallet. It introduces a new component MultipleBalances.vue that queries and displays the balances using the Polkadot API and the fiat store. It also updates the existing component WalletAsset.vue to use the new component and to hide the total value when not on the snek prefix.

🤖 Generated by Copilot at 18988f4

Sing, O Muse, of the cunning coder who devised
A wondrous component, MultipleBalances.vue,
To show the wealth of tokens and chains that he prized,
And query the Polkadot API for the true.

@netlify
Copy link

netlify bot commented May 17, 2023

Deploy Preview for koda-canary ready!

Name Link
🔨 Latest commit
🔍 Latest deploy log https://app.netlify.com/sites/koda-canary/deploys/6468cb10b16cbf217cf304d0
😎 Deploy Preview https://deploy-preview-6019--koda-canary.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@reviewpad reviewpad bot added the medium Pull request is medium label May 17, 2023
@reviewpad
Copy link
Contributor

reviewpad bot commented May 17, 2023

AI-Generated Summary: This pull request introduces a new feature for displaying multi-chain balances, adds a new MultipleBalances.vue component, and makes changes to the WalletAsset.vue component. In the new component, available balances for Kusama, Statemine, and Basilisk chains are fetched and displayed in rows with their respective Token and USD values.

In the WalletAsset.vue component, conditions are updated to display the new MultipleBalances component when the chain is not Snek and the total value section is displayed only for the Snek chain. The import and usage of AccountBalance are replaced with MultipleBalances.

@reviewpad
Copy link
Contributor

reviewpad bot commented May 17, 2023

Reviewpad Report

⚠️ Warnings

  • Please link an issue to the pull request

@preschian
Copy link
Member Author

preschian commented May 17, 2023

hi @yangwao @exezbcz @JustLuuuu, need your feedback about multi-chain balances in this PR. Is it better like this? I change the text from Network to Chain in this PR and use the full chain name. to distinguish between kusama as a token or chain. mostly, take inspiration from sub.id website

@yangwao
Copy link
Member

yangwao commented May 17, 2023

. Is it better like this?

if it would be stable I'm okay with it 😉

@preschian
Copy link
Member Author

Todo

  • for now, every time we open the sidebar there it always shows the skeleton component. will try to improve that in the next PR

Copy link
Contributor

@roiLeo roiLeo left a comment

Choose a reason for hiding this comment

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

Screenshot 2023-05-17 at 12-09-59 KodaDot - NFT Market Explorer

It doesn't work for me.

On kusama: should show only availableBalance
How are you going to handle /snek balance?

I'd be happy to help you, since this morning I've been banging my head with #5838 as I can't manage to have identityStore.auth.balance reactive (won't update on page)

@preschian
Copy link
Member Author

preschian commented May 17, 2023

On kusama: should show only availableBalance

could you give me your address with sub.id link? I will check it. for now, should show free balance only

How are you going to handle /snek balance?

for now, snek is still unchanged, still using the old component. I think we need to distinguish main and test network/chain

I'd be happy to help you

sure, since I'm actually still new interact directly with chain/polkadot API stuff

@roiLeo
Copy link
Contributor

roiLeo commented May 17, 2023

On kusama: should show only availableBalance

could you give me your address with sub.id link? I will check it. for now, should show free balance only

Screenshot 2023-05-17 at 12-18-03 Subscan Kusama Account Detail DVYy1qnocE8t6ZvUfPx3rEjG829khNRXx3YrCGVHHj19Lcb

https://github.com/kodadot/packages/blob/53bfd21bda439c8b2fda4cfd1347c85a5d80a4fb/sub-api/src/common/query.ts#L8

How are you going to handle /snek balance?

for now, snek is still unchanged, still using the old component. I think we need to distinguish main and test network/chain

alright

@preschian preschian marked this pull request as ready for review May 17, 2023 10:20
@preschian preschian requested a review from a team as a code owner May 17, 2023 10:20
@preschian preschian requested review from daiagi and Jarsen136 and removed request for a team May 17, 2023 10:20
@exezbcz
Copy link
Member

exezbcz commented May 17, 2023

Yes! much better, thank you

ad styling, I would maybe make the column names 12 px in k-grey for both light modes
image
like here:
image

@preschian
Copy link
Member Author

kodadot/packages@53bfd21/sub-api/src/common/query.ts#L8

oohh thanks, will update that 🙏

Copy link
Contributor

@roiLeo roiLeo left a comment

Choose a reason for hiding this comment

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

would it be possible to store (or fetch) balance values in pinia auth.balance state? So it would be easier to access between components

@preschian
Copy link
Member Author

would it be possible to store (or fetch) balance values in pinia auth.balance state? So it would be easier to access between components

let me check, didn't check the store yet for balance stuff

@preschian preschian marked this pull request as draft May 17, 2023 10:37
@JustLuuuu
Copy link
Member

Love it!

@preschian
Copy link
Member Author

would it be possible to store (or fetch) balance values in pinia auth.balance state? So it would be easier to access between components

I just modified a little bit on onMounted section, so it still fetches and store to the auth.balance. seems like this is the root cause of sometimes the balance zero e5f092a

@roiLeo
Copy link
Contributor

roiLeo commented May 17, 2023

I just modified a little bit on onMounted section, so it still fetches and store to the auth.balance. seems like this is the root cause of sometimes the balance zero e5f092a

I've already tried that but it didn't worked for me, idk why but know it work wtf.
This morning, on first fetch it would show 0 balance on rmr2 but in console I had the value from store...

@yangwao
Copy link
Member

yangwao commented May 17, 2023

viki did meanwhile, if something can be reused?

components/balance/MultipleBalances.vue Outdated Show resolved Hide resolved
components/balance/MultipleBalances.vue Outdated Show resolved Hide resolved
components/balance/MultipleBalances.vue Outdated Show resolved Hide resolved
@daiagi
Copy link
Contributor

daiagi commented May 17, 2023

more of a feature request, but can we highlight / make bold the token used for paying? (on Basilisk)

overall great stuff. love it

@preschian
Copy link
Member Author

more of a feature request, but can we highlight / make bold the token used for paying? (on Basilisk)

for this, how do I know the token is being used for transactions on Basilisk? cc @vikiival @roiLeo

@roiLeo
Copy link
Contributor

roiLeo commented May 17, 2023

more of a feature request, but can we highlight / make bold the token used for paying? (on Basilisk)

for this, how do I know the token is being used for transactions on Basilisk?

getAssetIdByAccount

check out

export const getFeesToken = async (): Promise<Token> => {
const { apiInstance } = useApi()
const { accountId } = useAuth()
const { $consola } = useNuxtApp()
const bsxTokenId = '0'
try {
const api = await apiInstance.value
//this function returns
// '0' if paying in bsx (on Basilisk and Snek)
// '1' if paying in ksm (on basilisk)
// '5' if paying in ksm (on Snek)
const tokenId = await getAssetIdByAccount(api, accountId.value)
return tokenId === bsxTokenId ? 'BSX' : 'KSM'
} catch (e) {
$consola.log(e)
}
return 'BSX'
}

Comment on lines 105 to 142
async function getBalance(chainName, token = 'KSM', tokenId = 0) {
const currentAddress = accountId.value
const prefix = mapToPrefix[chainName]
const chain = CHAINS[prefix]

const publicKey = decodeAddress(currentAddress)
const prefixAddress = encodeAddress(publicKey, chain.ss58Format)
const wsProvider = new WsProvider(ENDPOINT_MAP[prefix])

const api = await ApiPromise.create({
provider: wsProvider,
})

let currentBalance

if (tokenId) {
const balance = await api.query.tokens.accounts(prefixAddress, tokenId)
currentBalance = format(
(balance as PalletBalancesAccountData).free,
chain.tokenDecimals,
false
)
} else {
const balance = await balanceOf(api, prefixAddress)
currentBalance = format(balance, chain.tokenDecimals, false)
}

const balance = delimiter(currentBalance)
const usd = calculateUsd(balance, token)

availableChains[chainName].push({
token,
balance,
usd,
})
totalUsd.value.push(usd)

await wsProvider.disconnect()
Copy link
Member

Choose a reason for hiding this comment

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

Try to leverage the identity store imo

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, on the Todo section, I'm planning to store them in the store to improve the skeleton. the question is, should I make a new state or use the existing state balance? because the existing balance is a kinda different format with multi-chain assets. need feedback btw cc @vikiival @roiLeo @Jarsen136 @daiagi

in the existing balance state, is using prefix: balance format
so, it will store like this

ksm: 1,
rmrk: 1,
bsx: 1,
stmn: 1,

total: 4

in the multi-chain assets, because of ksm (rmrk2) and rmrk using the same chain (Kusama). I'm thinking to store them like this

kusama: 1,
basilisk: 1,
statemime: 1,

total: 3

Copy link
Contributor

Choose a reason for hiding this comment

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

Do as you like we will apply new format where it's needed.
Keep in mind we'll need something simple to access in order to check if account has sufficient funds to buy/makeOffer on item (it was pretty easy with urlPrefix)

But I would like to know if we will loose snek balance with this changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

But I would like to know if we will loose snek balance with this changes?

identity store and snek are so far still untouched in this PR, it should show the balance with existing components. ref: https://github.com/kodadot/nft-gallery/pull/6019/files#diff-88e8e60a0e3064ffe92b5025e2fc8fda186fbaa66718474a9142cfd1af489262R17-R18

but, lmk if you found something strange on snek wallet

Copy link
Member

@vikiival vikiival left a comment

Choose a reason for hiding this comment

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

I would leverage more identity store

@daiagi
Copy link
Contributor

daiagi commented May 17, 2023

image

I guess this is not what you meant to do

@preschian
Copy link
Member Author

more of a feature request, but can we highlight / make bold the token used for paying? (on Basilisk)
I guess this is not what you meant to do

seems like we need to ask the @kodadot/design-squad how to deliver this, wdyt? to make it clear

@exezbcz
Copy link
Member

exezbcz commented May 17, 2023

@preschian, just to be sure, do you mean asset to pay the transactions or buying nfts in general?

@daiagi
Copy link
Contributor

daiagi commented May 17, 2023

@exezbcz the asset used for paying for transactions on Basilisk (ksm or bsx)

Copy link
Contributor

@Jarsen136 Jarsen136 left a comment

Choose a reason for hiding this comment

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

lgtm

@exezbcz
Copy link
Member

exezbcz commented May 17, 2023

@daiagi Okay, I am not 100% sure whether we should highlight it somehow. If it isn't explicitly mentioned, the user could be confused about what that means. I can think of some possible solutions, but it's against the concept of a smart and simple asset view.

It would require additional tooltips etc.; that is not what we want.

I could mention this in the signing modal.

I can create a follow-up issue with p5, and I may come up with another, more innovative solution.

@codeclimate
Copy link

codeclimate bot commented May 20, 2023

Code Climate has analyzed commit 32f443e and detected 0 issues on this pull request.

View more on Code Climate.

@yangwao
Copy link
Member

yangwao commented May 20, 2023

I would try but https://deploy-preview-6019--koda-canary.netlify.app/

image

let me retry
image

@yangwao
Copy link
Member

yangwao commented May 20, 2023

I'm good, works

image

@yangwao
Copy link
Member

yangwao commented May 20, 2023

pay 80 usd

I like fresh take and all others contributing to discussion!

probably continue in

@yangwao yangwao merged commit d3746c1 into main May 20, 2023
19 checks passed
@yangwao yangwao deleted the feat/multi-chain-balances branch May 20, 2023 13:43
@yangwao
Copy link
Member

yangwao commented May 20, 2023

😍 Perfect, I’ve sent the payout
💵 $80 @ 25.6 USD/KSM ~ 3.125 $KSM
🧗 DY4SQF2iD456tH89aQtz5wv1EV3BbSW8wKKuMcwbmXaj1pM
🔗 0x7911bee1678741be63c420089f97770cf42b3bff3cab5c2504141e4b2c87498e

🪅 Let’s grab another issue and get rewarded!
🪄 github.com/kodadot/nft-gallery/issues

@yangwao yangwao added S-works-for-me-✅ qa-guild has tested PR from end user perspective and functionality worked paid pull-request has been paid labels May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium Pull request is medium paid pull-request has been paid S-works-for-me-✅ qa-guild has tested PR from end user perspective and functionality worked waiting-for-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants