Skip to content

Commit

Permalink
linting and invalidate positions query onSuccess
Browse files Browse the repository at this point in the history
  • Loading branch information
worrex committed Dec 2, 2024
1 parent 0019e61 commit fb22102
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
10 changes: 6 additions & 4 deletions components/Pages/Trade/Liquidity/hooks/useClosePosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
import { useClients } from 'hooks/useClients'
import useTxStatus from 'hooks/useTxStatus'
import { useRecoilValue } from 'recoil'
import { isNativeToken } from 'services/asset'
import { createGasFee } from 'services/treasuryService'
import { chainState } from 'state/chainState'
import { createExecuteMessage, validateTransactionSuccess } from 'util/messages/index'
import { isNativeToken } from '../../../../../services/asset'

type OpenPosition = {
item: any
Expand Down Expand Up @@ -41,8 +41,8 @@ export const useClosePosition = ({ item, pool }: OpenPosition) => {

if (unbonding_duration === -1 && chainId === ChainId.terra && item?.liquidity_alliance) {
const tokenInfo = isNativeToken(pool.lp_token)
? { native: pool.lp_token }
: { cw20: pool.lp_token};
? { native: pool.lp_token }
: { cw20: pool.lp_token }

msg = createExecuteMessage({
message: {
Expand Down Expand Up @@ -88,8 +88,10 @@ export const useClosePosition = ({ item, pool }: OpenPosition) => {

return useMemo(() => ({
submit,
onSuccess,
...state,
...tx,

}),
[tx, state, submit])
[tx, state, submit, onSuccess])
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { useQuery } from 'react-query'

import { useChain } from '@cosmos-kit/react-lite'
import { ChainId, TERRA2_BRIBE_MARKETS } from 'constants/index'
import { useClients } from 'hooks/useClients'
import { useRecoilValue } from 'recoil'
import { chainState } from 'state/chainState'

import { TERRA2_BRIBE_MARKETS } from '../../../../../constants'

export const useLiquidityAlliancePositions = (lp_token?: any) => {
const { chainId, walletChainName } = useRecoilValue(chainState)
const { address } = useChain(walletChainName)
Expand All @@ -20,10 +19,10 @@ export const useLiquidityAlliancePositions = (lp_token?: any) => {
}

const result = await Promise.all(Object.values(TERRA2_BRIBE_MARKETS).map(async (bribeMarket) => {
const staked_balances = await cosmWasmClient?.queryContractSmart(bribeMarket, {
const stakedBalances = await cosmWasmClient?.queryContractSmart(bribeMarket, {
all_staked_balances: { address },
})
return staked_balances?.map((position) => ({ ...position,
return stakedBalances?.map((position) => ({ ...position,
bribe_market: bribeMarket })) || []
}))

Expand Down Expand Up @@ -56,15 +55,15 @@ export const queryAllStakedBalances = async (
cosmWasmClient: any, address: string, pool?: any,
) => {
const result = await Promise.all(Object.values(TERRA2_BRIBE_MARKETS).map(async (bribeMarket) => {
const staked_balances = await cosmWasmClient?.queryContractSmart(bribeMarket, {
const stakedBalances = await cosmWasmClient?.queryContractSmart(bribeMarket, {
all_staked_balances: { address },
})
return staked_balances?.map((position) => ({ ...position,
return stakedBalances?.map((position) => ({ ...position,
bribe_market: bribeMarket })) || []
}))
return result.
flat().
filter((position) => (!pool || position.asset.info.native === pool.lp_token || position.asset.info.cw20 === pool.lp_token) &&
filter((position) => (!pool || position.asset.info.native === pool.lp_token || position.asset.info.cw20 === pool.lp_token) &&
position.shares !== '1').
map((position) => ({
open_position: {
Expand Down Expand Up @@ -139,7 +138,7 @@ export const fetchAllAllianceRewards = async (
asset.reward_asset.bribe_market = bribeMarket
if (asset.reward_asset.info.native.endsWith('zluna')) {
const claimAddress = asset.reward_asset.info.native.split('/')[1]
//ampLuna
// AmpLuna
asset.reward_asset.info.contract_addr = 'terra1ecgazyd0waaj3g7l9cmy5gulhxkps2gmxu9ghducvuypjq68mq2s5lvsct'
asset.reward_asset.info.claim_addr = claimAddress
}
Expand All @@ -160,8 +159,8 @@ export const useAllianceRewards = () => {
cosmWasmClient, address, chainId,
),
{
refetchInterval: 30 * 60 * 1000,
enabled: chainId === 'phoenix-1' && Boolean(address),
refetchInterval: 30 * 60 * 1_000,
enabled: chainId === ChainId.terra && Boolean(address),
},
)
}
2 changes: 1 addition & 1 deletion constants/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export const TERRA2_BRIBE_MARKETS = {
project: 'terra1awq6t7jfakg9wfjn40fk3wzwmd57mvrqtt3a39z9rmet7wdjj3ysgw3lpa',
bluechip: 'terra14mmvqn0kthw6sre75vku263lafn5655mkjdejqjedjga4cw0qx2qlf4arv',
stable: 'terra1v399cx9drllm70wxfsgvfe694tdsd9x96p9ha36w7muffe4znlusqswspq',
single: 'terra1qdz5qgafx88kp5mf6m2tah8742g4u5g2cek0m3jrgssexexk7g4qw6e23k'
single: 'terra1qdz5qgafx88kp5mf6m2tah8742g4u5g2cek0m3jrgssexexk7g4qw6e23k',
}
export const POOL_TOKENS_DECIMALS = 6
1 change: 1 addition & 0 deletions hooks/useTxStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const useTxStatus = ({ signingClient, transactionType }: UseTxStatusProps) => {
'signingClient',
'allianceRewards',
],
exact: false,
})
}, [transactionType, description, toast, queryClient, setTxState])

Expand Down

0 comments on commit fb22102

Please sign in to comment.