Skip to content

Commit

Permalink
fix(withdraw-amount): adjusted amount conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
worrex committed Nov 14, 2023
1 parent b05235a commit b7f6ac6
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 30 deletions.
6 changes: 3 additions & 3 deletions components/Pages/Dashboard/BondingActions/BondingActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const BondingActions = ({ globalAction }) => {
)

const unbondingPeriodInNano = Number(bondingConfig?.unbonding_period)
const totalWithdrawable = withdrawableInfos?.reduce((acc, e) => acc + e?.amount,
const totalWithdrawable = withdrawableInfos?.reduce((acc, e) => acc + (e?.amount || 0),
0)

const buttonLabel = useMemo(() => {
Expand Down Expand Up @@ -249,14 +249,14 @@ const BondingActions = ({ globalAction }) => {
txStep === TxStep.Posting ||
txStep === TxStep.Broadcasting
}
onClick={async () => {
onClick={ () => {
if (isWalletConnected) {
let { denom } = config.bonding_tokens.find((token) => token.tokenSymbol === currentBondState.tokenSymbol)
if (globalAction === ActionType.withdraw) {
denom = getFirstDenomWithPositiveAmount(withdrawableInfos,
config)
}
await submit(
submit(
globalAction, currentBondState.amount, denom,
)
} else {
Expand Down
6 changes: 1 addition & 5 deletions components/Pages/Dashboard/BondingActions/Withdraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import usePrices from 'hooks/usePrices'
import { useTokenList } from 'hooks/useTokenList'
import { useRecoilValue } from 'recoil'
import { chainState } from 'state/chainState'
import {
convertMicroDenomToDenom,
} from 'util/conversion/index'
import { calculateDurationString, nanoToMilli } from 'util/conversion/timeUtil'

type Props = {
Expand Down Expand Up @@ -57,8 +54,7 @@ const Withdraw = ({
const withdrawableTokens = withdrawableInfos?.map((row) => ({
...row,
dollarValue:
(prices?.[row.tokenSymbol] ?? whalePrice) *
convertMicroDenomToDenom(row.amount, 6),
(prices?.[row.tokenSymbol] ?? whalePrice) * row.amount,
}))

const ProgressBar = ({ percent }) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const useTransaction = () => {

const { mutate } = useMutation(async (data: any) => {
const adjustedAmount = convertDenomToMicroDenom(data.amount, 6)
if (data.bondingAction === ActionType.bond) {
if (data.bondingAction === ActionType.bond) {
return await bondTokens(
signingClient,
address,
Expand Down
31 changes: 14 additions & 17 deletions components/Pages/Dashboard/hooks/getGlobalIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,32 @@ import { CosmWasmClient, JsonObject } from '@cosmjs/cosmwasm-stargate'
import { Config } from './useDashboardData'

export interface GlobalIndexInfo {
bonded_amount: string
bonded_assets: any
bonded_amount: string
bonded_assets: any
weight: string
timestamp: string
}

const fetchGlobalIndex = async (client: CosmWasmClient,
config: Config): Promise<GlobalIndexInfo> => {
const result: JsonObject = await client.queryContractSmart(config.whale_lair,
{
global_index: {},
})

return result as GlobalIndexInfo
}

export const getGlobalIndex = async (client: CosmWasmClient,
config: Config) => {
if (!client ) {
if (!client) {
return null
}
try {
const globalIndexInfo = await fetchGlobalIndex(
client, config,
)
const globalIndexInfo = await fetchGlobalIndex(client, config)
return { globalIndexInfo }
} catch (e) {
return 0
}
}

const fetchGlobalIndex = async (
client: CosmWasmClient,
config: Config,
): Promise<GlobalIndexInfo> => {
const result: JsonObject = await client.queryContractSmart(config.whale_lair,
{
global_index: {},
})

return result as GlobalIndexInfo
}
4 changes: 3 additions & 1 deletion hooks/useRefetchQueries.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useCallback, useRef } from 'react'
import { useQueryClient } from 'react-query'

const sleep = (delayMs: number) => new Promise((resolve) => setTimeout(resolve, delayMs))
const sleep = (delayMs: number) => new Promise((resolve) => {
setTimeout(resolve, delayMs)
})

export const useRefetchQueries = (queryKey?: string | Array<string>,
delayMs?: number) => {
Expand Down
4 changes: 2 additions & 2 deletions hooks/useTxInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ const useTxInfo = ({ txHash, signingClient }: TxInfo) => {
['txInfo', txHash],
() => {
if (!txHash) {
return
return null
}
return signingClient.getTx(txHash)
},
{
enabled: txHash != null,
enabled: Boolean(txHash),
retry: true,
},
)
Expand Down
2 changes: 1 addition & 1 deletion hooks/useTxStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const useTxStatus = ({ signingClient, transactionType }: Props) => {
const reset = () => {
setTxState({
txStep: TxStep.Idle,
txHash: undefined,
txHash: null,
error: null,
buttonLabel: null,
})
Expand Down

0 comments on commit b7f6ac6

Please sign in to comment.