Skip to content

Commit

Permalink
Merge pull request #60 from SimpleHold/1.25.4
Browse files Browse the repository at this point in the history
1.25.4
  • Loading branch information
Dylan-Simplehold authored Oct 24, 2022
2 parents 8810a58 + 6f3205e commit 7db331d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/pages/Wallet/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,15 @@ const WalletPage: React.FC = () => {
if (state.isNotActivated) {
return updateState({ txHistory: [] })
}

const wallet: TTxWallet = { address: state.address, chain: getWalletChain(symbol, chain), symbol }
const wallet: TTxWallet = { address: state.address, chain: chain || getWalletChain(symbol, chain), symbol }
let history = findWalletTxHistory(wallet)

const walletData = getSingleWallet(state.address, symbol)
const isNonEmptyBalance = typeof state.balance === "number" && state.balance > 0
const isFetchRequired = walletData?.txHistoryUpdateRequired
|| isNonEmptyBalance && !history.length
if (isFetchRequired) {
await updateTxsHistory({ pickSingleWallet: wallet })
await updateTxsHistory({ pickSingleWallet: {...wallet, tokenSymbol, contractAddress}})
history = findWalletTxHistory(wallet)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Skeleton from '@components/Skeleton'

// Types
import { TAddressTx } from '@utils/api/types'
import { TAddressTxGroup } from 'utils/history'
import { TAddressTxGroup } from '@utils/history'

// Styles
import Styles from './styles'
Expand Down
12 changes: 7 additions & 5 deletions src/utils/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const updateTxsHistory = async (
const { address, chain, symbol, contractAddress } = wallet
return {
address,
chain: getWalletChain(symbol, chain),
chain: chain || getWalletChain(symbol, chain),
symbol,
tokenSymbol: chain ? symbol : undefined,
contractAddress,
Expand All @@ -66,7 +66,6 @@ export const updateTxsHistory = async (
.filter(wallet => wallet.address)
}
const data = await fetchFullTxHistory(payload)

if (!data.length) return

const compare = compareFullHistory(data)
Expand Down Expand Up @@ -196,24 +195,27 @@ export const saveFullHistory = (txs: TTxFullInfo[]): void => {
const hashMatch = toLower(tx.hash) === toLower(newTx.hash)
const amountMatch = tx.amount === newTx.amount
const addressMatch = tx.address === newTx.address
return hashMatch && amountMatch && addressMatch
const symbolMatch = tx.symbol === newTx.symbol
const chainMatch = tx.chain === newTx.chain
return hashMatch && amountMatch && addressMatch && symbolMatch && chainMatch
})
})

const getUpdatedPendingTxs = getHistory.map((tx: TTxFullInfo) => {
const match = txs.find((newTx: TTxFullInfo) => {
const hashMatch = toLower(newTx.hash) === toLower(tx.hash)
const addressMatch = toLower(newTx.address) === toLower(tx.address)
const symbolMatch = tx.symbol === newTx.symbol
const chainMatch = tx.chain === newTx.chain
const pendingStatusUpdated = tx.isPending !== newTx.isPending
return hashMatch && addressMatch && pendingStatusUpdated
return hashMatch && addressMatch && symbolMatch && chainMatch && pendingStatusUpdated
})
return match ? { ...tx, isPending: false } : tx
})

for (const tx of getNewTxs) {
updateWalletHistoryFetchStatus(tx.address, tx.symbol, false)
}

setItem('full_history', JSON.stringify([...getUpdatedPendingTxs, ...getNewTxs]))
} else {
setItem('full_history', JSON.stringify(txs))
Expand Down

0 comments on commit 7db331d

Please sign in to comment.