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

mobx store #3

Open
pyramation opened this issue May 21, 2022 · 1 comment
Open

mobx store #3

pyramation opened this issue May 21, 2022 · 1 comment

Comments

@pyramation
Copy link
Contributor

pyramation commented May 21, 2022

This issue is more for design and listing out queries that are needed.

  • all basic like ability to get users balances
  • ability to get users number of tokens inside of a pool

e.g. currently do get number of tokens in a pool

  1. get pools
  2. get prices
  3. convertPoolsToDisplayValues
  4. get the users locked coins
  5. call function getUserPools({pools, lockedPools})

instead, if we used a mobx store, we could wrap this all into a single call and it gets cached and we get simplicity and speed

@atmoner
Copy link

atmoner commented May 22, 2022

Here is how I use the pools part to add the missing information!

  1. Added gamm number from address -> pool (myAmount)
  2. Added conversion to pool total from address -> dollars amount (myAmountDollars)
  3. Adding the two images of the two coins for each pool (imgPool1, imgPool2)

My code is not perfect but it works great! 👍
If it can help

import { 
  assets,
  getUserPools,
  convertPoolsToDisplayValues,
  getPricesFromCoinGecko,
  OsmosisApiClient
} from '@cosmology/core';

const api = new OsmosisApiClient();

const lcdPools = await api.getAccountLockedLongerDuration(this.myAddress)
const lcdPoolsLocked = await api.getAccountLockedCoins(this.myAddress)
const allPools = await api.getPools()  
const getAllPrices = await getPricesFromCoinGecko()    
    
const convertPools = await convertPoolsToDisplayValues({ prices: getAllPrices, pools: allPools.pools })
const userPools = await getUserPools({ pools: convertPools, lockedPools: lcdPoolsLocked.coins})

const myPools = this.myPools // UI part
myLcdPools.locks.forEach(async function(item){
  const poolId = item.coins[0].denom.replace('gamm/pool/', '')
  const foundPoolId = userPools.find(element => element.poolId === poolId)      
  const myPretyDataPool = await api.getPoolPretty(poolId)
     
  const foundPoolImage1 = assets.find(element => element.symbol === myPretyDataPool.poolAssetsPretty[0].symbol);
  const foundPoolImage2 = assets.find(element => element.symbol === myPretyDataPool.poolAssetsPretty[1].symbol);
  myPretyDataPool.myAmount = item.coins[0].amount
  myPretyDataPool.myAmountDollars = Number(foundPoolId.value).toFixed(2)
  myPretyDataPool.imgPool1 = foundPoolImage1.logo_URIs.png
  myPretyDataPool.imgPool2 = foundPoolImage2.logo_URIs.png
  myPretyDataPool.show = false, // UI part
  myPools.push(myPretyDataPool);
});

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

No branches or pull requests

2 participants