Skip to content

Commit

Permalink
resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
jvonasek committed May 13, 2024
2 parents 95175fb + 5db9d23 commit 7ec012d
Show file tree
Hide file tree
Showing 128 changed files with 4,616 additions and 2,336 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
"@emotion/styled": "^11.10.4",
"@ethersproject/address": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@galacticcouncil/apps": "3.4.11",
"@galacticcouncil/apps": "^3.5.4",
"@galacticcouncil/math-lbp": "^0.2.1",
"@galacticcouncil/math-liquidity-mining": "^0.2.0",
"@galacticcouncil/math-omnipool": "^0.2.0",
"@galacticcouncil/math-stableswap": "^0.2.2",
"@galacticcouncil/math-staking": "^0.2.0",
"@galacticcouncil/math-xyk": "^0.2.0",
"@galacticcouncil/sdk": "^2.1.0",
"@galacticcouncil/ui": "^3.1.5",
"@galacticcouncil/xcm-cfg": "^1.11.3",
"@galacticcouncil/sdk": "^2.2.3",
"@galacticcouncil/ui": "^3.1.14",
"@galacticcouncil/xcm-cfg": "^1.11.7",
"@galacticcouncil/xcm-sdk": "^2.4.0",
"@hookform/resolvers": "^3.3.4",
"@lit-labs/react": "^1.1.0",
Expand Down Expand Up @@ -69,15 +69,15 @@
"@testing-library/user-event": "^13.5.0",
"@types/papaparse": "^5.3.14",
"@types/uuid": "^8.3.4",
"@walletconnect/modal": "^2.6.2",
"@walletconnect/sign-client": "2.8.0",
"@walletconnect/types": "^2.8.0",
"@walletconnect/universal-provider": "2.8.0",
"@walletconnect/modal": "2.6.2",
"@walletconnect/sign-client": "2.12.2",
"@walletconnect/types": "2.12.2",
"@walletconnect/universal-provider": "2.12.2",
"bignumber.js": "^9.1.0",
"color": "^4.2.3",
"comlink": "^4.3.1",
"date-fns": "^2.29.1",
"ethers": "^5.7.0",
"ethers": "5.7.0",
"ethers-decode-error": "^1.0.0",
"framer-motion": "^10.16.4",
"graphql": "^16.6.0",
Expand Down
39 changes: 25 additions & 14 deletions src/api/assetDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export type TStableSwap = TAssetCommon & {
export type TShareToken = TAssetCommon & {
assetType: "ShareToken"
assets: string[]
poolAddress: string | undefined
poolAddress: string
}

export type TAsset = TToken | TBond | TStableSwap | TShareToken
Expand Down Expand Up @@ -161,12 +161,16 @@ export const getAssets = async (api: ApiPromise) => {
rawAssetsData,
rawAssetsLocations,
hubAssetId,
poolAddresses,
xykPoolAssets,
isReferralsEnabled,
] = await Promise.all([
api.rpc.system.properties(),
api.query.assetRegistry.assets.entries(),
api.query.assetRegistry.assetLocations.entries(),
api.consts.omnipool.hubAssetId,
api.query.xyk.shareToken.entries(),
api.query.xyk.poolAssets.entries(),
api.query.referrals,
])

Expand All @@ -193,7 +197,7 @@ export const getAssets = async (api: ApiPromise) => {
//@ts-ignore
const isExternal = assetType === "External"
//@ts-ignore
const isSufficient = data.isSufficient.toPrimitive()
const isSufficient = data.isSufficient?.toPrimitive() ?? false

let meta
if (rawAssetsMeta) {
Expand Down Expand Up @@ -369,24 +373,28 @@ export const getAssets = async (api: ApiPromise) => {
stableswap.push(asset)
}
} else if (isShareToken) {
const poolAddresses = await api.query.xyk.shareToken.entries()
const poolAddress = poolAddresses
.find(
(poolAddress) => poolAddress[1].toString() === assetCommon.id,
)?.[0]
.args[0].toString()

if (poolAddress) {
const poolAssets = await api.query.xyk.poolAssets(poolAddress)
const assets = poolAssets
.unwrap()
.map((poolAsset) => poolAsset.toString())
const poolAssets = xykPoolAssets.find(
(xykPool) => xykPool[0].args[0].toString() === poolAddress,
)?.[1]

shareTokensRaw.push({
...assetCommon,
assets,
poolAddress,
})
if (poolAssets) {
const assets = poolAssets
.unwrap()
.map((poolAsset) => poolAsset.toString())

shareTokensRaw.push({
...assetCommon,
assets,
poolAddress,
})
}
}
} else if (isExternal) {
const location = rawAssetsLocations.find(
Expand Down Expand Up @@ -432,6 +440,8 @@ export const getAssets = async (api: ApiPromise) => {

const shareTokens = shareTokensRaw.reduce<Array<TShareToken>>(
(acc, shareToken) => {
if (!shareToken.assets) return acc

const [assetAId, assetBId] = shareToken.assets

const assetA = [...tokens, ...bonds, ...external].find(
Expand All @@ -441,9 +451,9 @@ export const getAssets = async (api: ApiPromise) => {
(token) => token.id === assetBId,
) as TToken

const isValdiTokens = assetA?.name && assetB?.name
const isValidTokens = assetA?.name && assetB?.name

if (isValdiTokens) {
if (isValidTokens) {
const assetDecimal =
Number(assetA.id) > Number(assetB.id) ? assetB : assetA

Expand Down Expand Up @@ -494,6 +504,7 @@ export const getAssets = async (api: ApiPromise) => {
hub,
rawTradeAssets,
},
poolService,
tradeRouter,
featureFlags: {
referrals: !!isReferralsEnabled,
Expand Down
25 changes: 25 additions & 0 deletions src/api/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,28 @@ export const getTokenLock =
type: lock.id.toString(),
}))
}

export const useShareTokenBalances = (shareTokenIds: string[]) => {
const { api, assets } = useRpcProvider()

const shareTokens = assets
.getAssets(shareTokenIds)
.reduce<{ id: string; address: string }[]>((acc, asset) => {
if (assets.isShareToken(asset)) {
asset.assets.forEach((id) =>
acc.push({ id, address: asset.poolAddress }),
)
}

return acc
}, [])

return useQueries({
queries: shareTokens.map(({ id, address }) => ({
queryKey: QUERY_KEYS.tokenBalanceLive(id, address),
queryFn:
address != null ? getTokenBalance(api, address, id) : undefinedNoop,
enabled: !!id && !!address,
})),
})
}
Loading

0 comments on commit 7ec012d

Please sign in to comment.