cosmology-tech/cosmology

mobx store

Opened this issue · 1 comments

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

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