Skip to content

Commit

Permalink
Terra alliance as position (#585)
Browse files Browse the repository at this point in the history
* feat: terra alliance as position

* feat: staking on terra alliance

* feat: claim alliance rewards

* fix: deeplink to pools
  • Loading branch information
nick134-bit authored Sep 3, 2024
1 parent 8e1b167 commit 2675587
Show file tree
Hide file tree
Showing 60 changed files with 1,339 additions and 453 deletions.
16 changes: 10 additions & 6 deletions components/AssetInput/AssetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ const AssetList: FC<AssetListProps> = ({
const { network, chainId } = useRecoilValue(chainState)
const config = useConfig(network, chainId)
const tokens = useMemo(() => {
if (!config) return []
if (!config) {
return []
}

if (!isBonding && !isIncentives) return [...(tokenList?.tokensBySymbol?.values() || [])].filter((token: any) => !token?.fromRegistry && !token?.withoutPool);
if (!isBonding && !isIncentives) {
return [...(tokenList?.tokensBySymbol?.values() || [])].filter((token: any) => !token?.fromRegistry && !token?.withoutPool)
}

let res = isBonding ? config.bonding_tokens : [...(tokenList?.tokensBySymbol?.values() || [])];
const res = isBonding ? config.bonding_tokens : [...(tokenList?.tokensBySymbol?.values() || [])]

return res.length > 0 ? res : [...(tokenList?.tokensBySymbol?.values() || [])].filter((token: any) => !token?.fromRegistry && !token?.withoutPool);
}, [config, isBonding, isIncentives, tokenList, setup]);
return res.length > 0 ? res : [...(tokenList?.tokensBySymbol?.values() || [])].filter((token: any) => !token?.fromRegistry && !token?.withoutPool)
}, [config, isBonding, isIncentives, tokenList, setup])

const [tokenBalance = []] =
unbondingBalances
Expand Down Expand Up @@ -107,7 +111,7 @@ const AssetList: FC<AssetListProps> = ({
tokenSymbol: item?.symbol,
amount,
},
true)
true)
}
>
<HStack>
Expand Down
2 changes: 1 addition & 1 deletion components/Icons/GalaxyStationExtensionIcon.tsx

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions components/Icons/LeapSnapIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as React from 'react'
export default function LeapWalletIc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x
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HStack, Image, Text } from '@chakra-ui/react'
import { useRouter } from 'next/router';
import { useRouter } from 'next/router'
import { useRecoilState } from 'recoil'
import { chainState } from 'state/chainState'

Expand Down
2 changes: 1 addition & 1 deletion components/Pages/Bonding/BondingActions/Bond.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Controller, useForm } from 'react-hook-form'
import { useMediaQuery, VStack } from '@chakra-ui/react'
import { useChain } from '@cosmos-kit/react-lite'
import AssetInput from 'components/AssetInput/index'
import { useConfig } from 'components/Pages/Bonding/hooks/useDashboardData';
import { useConfig } from 'components/Pages/Bonding/hooks/useDashboardData'
import { useRecoilState, useRecoilValue } from 'recoil'
import { bondingState } from 'state/bondingState'
import { chainState } from 'state/chainState'
Expand Down
4 changes: 2 additions & 2 deletions components/Pages/Bonding/BondingActions/Unbond.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { useMediaQuery, VStack } from '@chakra-ui/react'
import { useChain } from '@cosmos-kit/react-lite'
import AssetInput from 'components/AssetInput/index'
import { BondingTokenState, TokenBalance } from 'components/Pages/Bonding/BondingActions/Bond'
import { BondedData } from 'components/Pages/Bonding/hooks/getBonded';
import { useConfig } from 'components/Pages/Bonding/hooks/useDashboardData';
import { BondedData } from 'components/Pages/Bonding/hooks/getBonded'
import { useConfig } from 'components/Pages/Bonding/hooks/useDashboardData'
import { useRecoilState, useRecoilValue } from 'recoil'
import { bondingState } from 'state/bondingState'
import { chainState } from 'state/chainState'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingco
import { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate'
import { Config } from 'components/Pages/Bonding/hooks/useDashboardData'
import { ADV_MEMO, ChainId } from 'constants/index'
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx'
import { createGasFee } from 'services/treasuryService'
import { createExecuteMessage } from 'util/messages/createExecuteMessage'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate/build/signingco
import { InjectiveSigningStargateClient } from '@injectivelabs/sdk-ts/dist/cjs/core/stargate'
import { Config } from 'components/Pages/Bonding/hooks/useDashboardData'
import { ADV_MEMO, ChainId } from 'constants/index'
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx'
import { createGasFee } from 'services/treasuryService'
import { createExecuteMessage } from 'util/messages/createExecuteMessage'

Expand Down
1 change: 0 additions & 1 deletion components/Pages/Bonding/hooks/getBondingConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export const getBondingConfig = async (client: CosmWasmClient | null,

export const fetchConfig = async (client: CosmWasmClient,
config: Config): Promise<BondingContractConfig> => {
// TODO: API
if (!client || !config?.whale_lair) {
return null
}
Expand Down
6 changes: 3 additions & 3 deletions components/Pages/Bonding/hooks/getCurrentEpoch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export interface Epoch {

export const fetchCurrentEpoch = async (client: CosmWasmClient,
config: Config): Promise<Epoch> => {
if (!client || !config?.fee_distributor) {
return null
}
if (!client || !config?.fee_distributor) {
return null
}
const result: JsonObject = await client?.queryContractSmart(config?.fee_distributor,
{
current_epoch: {},
Expand Down
95 changes: 54 additions & 41 deletions components/Pages/Bonding/hooks/useDashboardData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useMemo, useState } from 'react'
import { useQueries } from 'react-query'
import { useEffect, useMemo, useState, useRef } from 'react'
import { useQueries, useQueryClient } from 'react-query'

import { getBonded } from 'components/Pages/Bonding/hooks/getBonded'
import { getBondingConfig } from 'components/Pages/Bonding/hooks/getBondingConfig'
Expand All @@ -14,7 +14,6 @@ import { getWithdrawable } from 'components/Pages/Bonding/hooks/getWithdrawable'
import { TokenInfo } from 'components/Pages/Trade/Pools/hooks/usePoolsListQuery'
import { DEFAULT_TOKEN_BALANCE_REFETCH_INTERVAL } from 'constants/settings'
import { useClients } from 'hooks/useClients'
import { debounce } from 'lodash'
import { NetworkType } from 'state/chainState'

import { getGlobalIndex } from './getGlobalIndex'
Expand All @@ -36,109 +35,122 @@ export interface Config {

export const useConfig = (network: NetworkType, chainId: string) => {
const [config, setConfig] = useState<Config | null>(null)
const cacheRef = useRef<{ [key: string]: Config | null }>({})

useEffect(() => {
if (network && chainId) {
// Only execute if network and chainId are defined
const cacheKey = `${network}_${chainId}`

if (cacheRef.current[cacheKey]) {
setConfig(cacheRef.current[cacheKey])
return
}

const fetchConfig = async () => {
try {
const response = await fetch(`/${network}/${chainId}/config.json`)
const json: Config = await response.json()
setConfig(json)
cacheRef.current[cacheKey] = json
} catch (error) {
console.error('Failed to load config:', error)
}
}

fetchConfig()
}
}, [network, chainId])

return config
}

export const useDashboardData = (
address: string, network: NetworkType, chainId: string, walletChainName: string,
) => {
const debouncedRefetch = useMemo(() => debounce((refetchFunc) => refetchFunc(), 500),
[])

const config: Config = useConfig(network, chainId)

const { cosmWasmClient: queryClient } = useClients(walletChainName)
const queryClient = useQueryClient()
const config = useConfig(network, chainId)
const { cosmWasmClient } = useClients(walletChainName)

const queries = useQueries([
{
queryKey: ['bonded', address, network, chainId],

queryFn: () => getBonded(
queryClient, address, config,
cosmWasmClient, address, config,
),
enabled: Boolean(queryClient) && Boolean(address) && Boolean(config),
refetchOnMount: 'always',
refetchInterval: DEFAULT_TOKEN_BALANCE_REFETCH_INTERVAL,
enabled: Boolean(cosmWasmClient) && Boolean(address) && Boolean(config),
staleTime: 30000, // 30 seconds
cacheTime: 5 * 60 * 1000, // 5 minutes
},
{
queryKey: ['unbonding', address, network, chainId],
queryFn: () => getUnbonding(
queryClient, address, config,
cosmWasmClient, address, config,
),
enabled: Boolean(queryClient) && Boolean(address) && Boolean(config),
enabled: Boolean(cosmWasmClient) && Boolean(address) && Boolean(config),

refetchOnMount: 'always',
refetchInterval: DEFAULT_TOKEN_BALANCE_REFETCH_INTERVAL,
},
{
queryKey: ['withdrawable', address, network, chainId],
queryFn: () => getWithdrawable(
queryClient, address, config,
cosmWasmClient, address, config,
),
enabled: Boolean(queryClient) && Boolean(address) && Boolean(config),
enabled: Boolean(cosmWasmClient) && Boolean(address) && Boolean(config),
refetchOnMount: 'always',
refetchInterval: DEFAULT_TOKEN_BALANCE_REFETCH_INTERVAL,
},
{
queryKey: ['totalBonded', network, chainId],
queryFn: () => getTotalBonded(queryClient, config),
enabled: Boolean(queryClient) && Boolean(config),
queryFn: () => getTotalBonded(cosmWasmClient, config),
enabled: Boolean(cosmWasmClient) && Boolean(config),
cacheTime: 5 * 60 * 1000,

},
{
queryKey: ['weightInfo', address, network, chainId],
queryFn: () => getWeight(
queryClient, address, config,
cosmWasmClient, address, config,
),
enabled: Boolean(queryClient) && Boolean(address) && Boolean(config),
enabled: Boolean(cosmWasmClient) && Boolean(address) && Boolean(config),
},
{
queryKey: ['feeDistributionConfig', network, chainId],
queryFn: () => getFeeDistributorConfig(queryClient, config),
enabled: Boolean(queryClient) && Boolean(config),
queryFn: () => getFeeDistributorConfig(cosmWasmClient, config),
enabled: Boolean(cosmWasmClient) && Boolean(config),
},
{
queryKey: ['currentEpoch', network, chainId],
queryFn: () => getCurrentEpoch(queryClient, config),
enabled: Boolean(queryClient) && Boolean(config),
queryFn: () => getCurrentEpoch(cosmWasmClient, config),
enabled: Boolean(cosmWasmClient) && Boolean(config),
cacheTime: 30 * 60 * 1000,
},
{
queryKey: ['claimableEpochs', network, chainId],
queryFn: () => getClaimableEpochs(queryClient, config),
enabled: Boolean(queryClient) && Boolean(config),
queryFn: () => getClaimableEpochs(cosmWasmClient, config),
enabled: Boolean(cosmWasmClient) && Boolean(config),
cacheTime: 10 * 60 * 1000,

},
{
queryKey: ['claimableRewards', address, network, chainId],
queryFn: () => getClaimable(
queryClient, address, config,
cosmWasmClient, address, config,
),
enabled: Boolean(queryClient) && Boolean(address) && Boolean(config),
enabled: Boolean(cosmWasmClient) && Boolean(address) && Boolean(config),
},
{
queryKey: ['bondingConfig', network, chainId],
queryFn: () => getBondingConfig(queryClient, config),
enabled: Boolean(queryClient) && Boolean(config),
queryFn: () => getBondingConfig(cosmWasmClient, config),
enabled: Boolean(cosmWasmClient) && Boolean(config),
cacheTime: 60 * 60 * 1000,

},
{
queryKey: ['globalIndex', network, chainId],
queryFn: () => getGlobalIndex(queryClient, config),
enabled: Boolean(queryClient) && Boolean(config),
queryFn: () => getGlobalIndex(cosmWasmClient, config),
enabled: Boolean(cosmWasmClient) && Boolean(config),
staleTime: 60000, // 1 minute
cacheTime: 5 * 60 * 1000, // 5 minutes
},
])

Expand All @@ -148,9 +160,7 @@ export const useDashboardData = (
[queries])

const refetchAll = () => {
queries.forEach((query) => {
debouncedRefetch(query.refetch)
})
queries.forEach((query) => query.refetch())
}

const data = useMemo(() => {
Expand Down Expand Up @@ -180,7 +190,10 @@ export const useDashboardData = (
}
}, [queries])

return { ...data,
return {
...data,
isLoading,
refetch: refetchAll }
refetch: refetchAll,
invalidateQueries: () => queryClient.invalidateQueries(),
}
}
Loading

0 comments on commit 2675587

Please sign in to comment.