Skip to content

Commit

Permalink
Use the advanced filter for user involved swaps in the swap preview
Browse files Browse the repository at this point in the history
  • Loading branch information
skubarenko committed Aug 31, 2022
1 parent 11e0d33 commit b8714dd
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
18 changes: 17 additions & 1 deletion src/atomex/atomexSwapPreviewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,23 @@ export class AtomexSwapPreviewManager implements Disposable {
return swapsInfo;

const swaps = (await this.atomexContext.managers.swapManager.getSwaps(userAddress))
.filter(swap => swap.user.status === 'Involved' && swap.from.currencyId === fromCurrencyId);
.filter(swap => {
if (!(
swap.from.currencyId === fromCurrencyId
&& (swap.user.status === 'Created' || swap.user.status === 'Involved')
&& (swap.counterParty.status === 'Created' || swap.counterParty.status === 'Involved'
|| swap.counterParty.status === 'PartiallyInitiated' || swap.counterParty.status === 'Initiated'
)
)) {
return false;
}

const now = Date.now();
const swapTimeStamp = swap.timeStamp.getTime();

return (swapTimeStamp + swap.user.requisites.lockTime * 1000 > now)
&& (swapTimeStamp + swap.counterParty.requisites.lockTime * 1000 > now);
});
const fromTotalAmount = swaps.reduce(
(total, swap) => total.plus(swap.from.amount),
new BigNumber(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,33 @@ const swaps: Swap[] = [
status: 'Involved',
trades: [],
transactions: [],
requisites: null as any
requisites: {
lockTime: 18000,
baseCurrencyContract: '',
quoteCurrencyContract: '',
receivingAddress: '',
refundAddress: null,
secretHash: null,
rewardForRedeem: new BigNumber(0)
}
},
counterParty: {
status: 'Involved',
trades: [],
transactions: [],
requisites: null as any
requisites: {
lockTime: 36000,
baseCurrencyContract: '',
quoteCurrencyContract: '',
receivingAddress: '',
refundAddress: null,
secretHash: null,
rewardForRedeem: new BigNumber(0)
}
},
secret: null,
secretHash: '',
timeStamp: new Date('2022-08-30T00:25:01Z')
timeStamp: new Date()
},
{
id: 89,
Expand All @@ -68,17 +84,33 @@ const swaps: Swap[] = [
status: 'Involved',
trades: [],
transactions: [],
requisites: null as any
requisites: {
lockTime: 18000,
baseCurrencyContract: '',
quoteCurrencyContract: '',
receivingAddress: '',
refundAddress: null,
secretHash: null,
rewardForRedeem: new BigNumber(0)
}
},
counterParty: {
status: 'Involved',
trades: [],
transactions: [],
requisites: null as any
requisites: {
lockTime: 36000,
baseCurrencyContract: '',
quoteCurrencyContract: '',
receivingAddress: '',
refundAddress: null,
secretHash: null,
rewardForRedeem: new BigNumber(0)
}
},
secret: null,
secretHash: '',
timeStamp: new Date('2022-08-27T14:25:01Z')
timeStamp: new Date()
},
];

Expand Down

0 comments on commit b8714dd

Please sign in to comment.