Skip to content

Commit

Permalink
Merge pull request #463 from syscoin/fix/tx-state-management
Browse files Browse the repository at this point in the history
fix: solve tx state management issue
  • Loading branch information
lucasgabrielgsp authored Sep 1, 2023
2 parents 3260d2c + a835c60 commit d8ae645
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 41 deletions.
2 changes: 1 addition & 1 deletion source/pages/Home/Panel/components/Transactions/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export const TransactionsList = ({
<Icon name="select" className="text-base" />
</IconButton>

{getTxOptions(isTxCanceled, isConfirmed, tx)}
{!isBitcoinBased && getTxOptions(isTxCanceled, isConfirmed, tx)}
</div>
</div>
</li>
Expand Down
89 changes: 49 additions & 40 deletions source/state/vault/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ const VaultState = createSlice({
transactions: Array<IEvmTransaction | ISysTransaction>;
}>
) {
const { activeAccount } = state;
const { activeAccount, isBitcoinBased } = state;
const { networkType, chainId, transactions } = action.payload;
const currentAccount =
state.accounts[activeAccount.type][activeAccount.id];
Expand All @@ -546,7 +546,7 @@ const VaultState = createSlice({
const clonedUserTxs =
cloneDeep(currentAccount.transactions[networkType][chainId]) || [];

const transactionsToVerify = [...clonedUserTxs, ...transactions];
const transactionsToVerify = [...transactions, ...clonedUserTxs];

transactionsToVerify.forEach(
(tx: IEvmTransactionResponse | ISysTransaction) => {
Expand All @@ -564,32 +564,10 @@ const VaultState = createSlice({

// Check if the networkType exists in the current account's transactions
if (!currentAccount.transactions[networkType]) {
let chainTransactions = treatedTxs;
// Cast the array to the correct type based on the networkType and value bigger than 0
const chainTransactions = treatedTxs.filter((tx) => {
if (
convertTransactionValueToCompare(
tx.value as TransactionValueType
) === 0 &&
!isERC1155Transfer(tx as IEvmTransactionResponse)
) {
return false;
}
return networkType === TransactionsType.Ethereum
? (tx as IEvmTransaction)
: (tx as ISysTransaction);
});

currentAccount.transactions[networkType] = {
[chainId]:
chainTransactions as (typeof networkType extends TransactionsType.Ethereum
? IEvmTransaction
: ISysTransaction)[],
};
} else {
// Check if the chainId exists in the current networkType's transactions
if (!currentAccount.transactions[networkType][chainId]) {
// Create a new array with the correct type based on the networkType and value bigger than 0
const chainTransactions = treatedTxs.filter((tx) => {
if (!isBitcoinBased) {
chainTransactions = treatedTxs.filter((tx) => {
if (
convertTransactionValueToCompare(
tx.value as TransactionValueType
Expand All @@ -602,26 +580,57 @@ const VaultState = createSlice({
? (tx as IEvmTransaction)
: (tx as ISysTransaction);
});
}

currentAccount.transactions[networkType] = {
[chainId]:
chainTransactions as (typeof networkType extends TransactionsType.Ethereum
? IEvmTransaction
: ISysTransaction)[],
};
} else {
// Check if the chainId exists in the current networkType's transactions
if (!currentAccount.transactions[networkType][chainId]) {
let chainTransactions = treatedTxs;
// Create a new array with the correct type based on the networkType and value bigger than 0
if (!isBitcoinBased) {
chainTransactions = treatedTxs.filter((tx) => {
if (
convertTransactionValueToCompare(
tx.value as TransactionValueType
) === 0 &&
!isERC1155Transfer(tx as IEvmTransactionResponse)
) {
return false;
}
return networkType === TransactionsType.Ethereum
? (tx as IEvmTransaction)
: (tx as ISysTransaction);
});
}

currentAccount.transactions[networkType][chainId] =
chainTransactions as (typeof networkType extends TransactionsType.Ethereum
? IEvmTransaction
: ISysTransaction)[];
} else {
let castedTransactions = treatedTxs;
// Filter and push the transactions based on the networkType and value bigger than 0
const castedTransactions = treatedTxs.filter((tx) => {
if (
convertTransactionValueToCompare(
tx.value as TransactionValueType
) === 0 &&
!isERC1155Transfer(tx as IEvmTransactionResponse)
) {
return false;
}
return networkType === TransactionsType.Ethereum
? (tx as IEvmTransaction)
: (tx as ISysTransaction);
});
if (!isBitcoinBased) {
castedTransactions = treatedTxs.filter((tx) => {
if (
convertTransactionValueToCompare(
tx.value as TransactionValueType
) === 0 &&
!isERC1155Transfer(tx as IEvmTransactionResponse)
) {
return false;
}
return networkType === TransactionsType.Ethereum
? (tx as IEvmTransaction)
: (tx as ISysTransaction);
});
}

currentAccount.transactions[networkType][chainId] =
//Using take method from lodash to set TXs limit at each state to 30 and only remove the last values and keep the newests
Expand Down

0 comments on commit d8ae645

Please sign in to comment.