Skip to content

Commit

Permalink
fix: cosmos savers deposit and withdraw status
Browse files Browse the repository at this point in the history
  • Loading branch information
NeOMakinG committed Sep 10, 2024
1 parent e1c8358 commit 0b27699
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export const ThorchainSaversDeposit: React.FC<YearnDepositProps> = ({
},
[DefiStep.Status]: {
label: translate('defi.steps.status.title'),
component: ownProps => <Status {...ownProps} accountId={accountId} />,
component: () => <Status />,
},
}
}, [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { CheckIcon, CloseIcon, ExternalLinkIcon } from '@chakra-ui/icons'
import { Box, Button, Link, Stack } from '@chakra-ui/react'
import type { AccountId } from '@shapeshiftoss/caip'
import { fromAccountId, thorchainAssetId } from '@shapeshiftoss/caip'
import { thorchainAssetId } from '@shapeshiftoss/caip'
import { TxStatus as TxStatusType } from '@shapeshiftoss/unchained-client'
import { Summary } from 'features/defi/components/Summary'
import { TxStatus } from 'features/defi/components/TxStatus/TxStatus'
import type {
DefiParams,
DefiQueryParams,
} from 'features/defi/contexts/DefiManagerProvider/DefiCommon'
import { useCallback, useContext, useEffect, useMemo } from 'react'
import { useCallback, useContext, useEffect } from 'react'
import { useTranslate } from 'react-polyglot'
import { Amount } from 'components/Amount/Amount'
import { AssetIcon } from 'components/AssetIcon'
Expand All @@ -29,21 +28,15 @@ import {
selectAssets,
selectFeeAssetById,
selectMarketDataByAssetIdUserCurrency,
selectTxById,
} from 'state/slices/selectors'
import { serializeTxIndex } from 'state/slices/txHistorySlice/utils'
import { useAppDispatch, useAppSelector } from 'state/store'

import { ThorchainSaversDepositActionType } from '../DepositCommon'
import { DepositContext } from '../DepositContext'

type StatusProps = {
accountId: AccountId | undefined
}

const externalLinkIcon = <ExternalLinkIcon />

export const Status: React.FC<StatusProps> = ({ accountId }) => {
export const Status: React.FC = () => {
const translate = useTranslate()
const mixpanel = getMixPanel()
const { state, dispatch: contextDispatch } = useContext(DepositContext)
Expand All @@ -70,37 +63,25 @@ export const Status: React.FC<StatusProps> = ({ accountId }) => {
selectMarketDataByAssetIdUserCurrency(state, assetId ?? ''),
)

const account = useMemo(() => accountId && fromAccountId(accountId).account, [accountId])

const serializedTxIndex = useMemo(() => {
if (!(state?.txid && accountId && account)) return ''
return serializeTxIndex(accountId, state.txid, account)
}, [state?.txid, accountId, account])

const confirmedTransaction = useAppSelector(gs => selectTxById(gs, serializedTxIndex))

useEffect(() => {
if (!accountId) return

if (confirmedTransaction && confirmedTransaction.status !== 'Pending' && contextDispatch) {
;(async () => {
// Skipping outbound detection since there's no outbound tx involved here - as long as the inner swap is confirmed, we're gucci
const thorchainTxStatus = await waitForThorchainUpdate({
txId: confirmedTransaction.txid,
skipOutbound: true,
}).promise

if ([TxStatusType.Confirmed, TxStatusType.Failed].includes(thorchainTxStatus)) {
contextDispatch({
type: ThorchainSaversDepositActionType.SET_DEPOSIT,
payload: {
txStatus: thorchainTxStatus === TxStatusType.Confirmed ? 'success' : 'failed',
},
})
}
})()
}
}, [accountId, appDispatch, confirmedTransaction, contextDispatch, getOpportunitiesUserData])
if (!contextDispatch || !state?.txid) return
;(async () => {
// Skipping outbound detection since there's no outbound tx involved here - as long as the inner swap is confirmed, we're gucci
const thorchainTxStatus = await waitForThorchainUpdate({
txId: state.txid!,
skipOutbound: true,
}).promise

if ([TxStatusType.Confirmed, TxStatusType.Failed].includes(thorchainTxStatus)) {
contextDispatch({
type: ThorchainSaversDepositActionType.SET_DEPOSIT,
payload: {
txStatus: thorchainTxStatus === TxStatusType.Confirmed ? 'success' : 'failed',
},
})
}
})()
}, [appDispatch, contextDispatch, getOpportunitiesUserData, state?.txid])

const handleViewPosition = useCallback(() => {
browserHistory.push('/earn')
Expand Down

0 comments on commit 0b27699

Please sign in to comment.