Skip to content

Commit

Permalink
Fix duplicate fees (#2419)
Browse files Browse the repository at this point in the history
  • Loading branch information
onnovisser authored Sep 2, 2024
1 parent cd09c95 commit ae51a98
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4330,7 +4330,8 @@ export function getPoolsModule(inst: Centrifuge) {
switchMap((api) => api.query.poolFees.lastFeeId()),
take(1),
combineLatestWith($api),
switchMap(([lastFeeId, api]) => {
combineLatestWith(getPoolFees([poolId])),
switchMap(([[lastFeeId, api], poolFees]) => {
const removeSubmittables = remove.map((feeId) => api.tx.poolFees.removeFee([feeId]))
const addSubmittables = add.map(({ poolId, fee }) => {
return api.tx.poolFees.proposeNewFee(poolId, 'Top', {
Expand All @@ -4339,15 +4340,14 @@ export function getPoolsModule(inst: Centrifuge) {
feeType: { [fee.feeType]: { limit: { [fee.limit]: fee.amount } } },
})
})
const removedFeeIds = new Set(remove)
const remainingFeeIds = new Set(poolFees.map((fee) => fee.id).filter((id) => !removedFeeIds.has(id)))
const updatedMetadata = {
...metadata,
pool: {
...metadata.pool,
poolFees: [
...(metadata?.pool?.poolFees?.filter((fee) => {
if (remove.length) return remove.find((f) => f !== fee.id)
return true
}) || []),
...(metadata?.pool?.poolFees?.filter((fee) => remainingFeeIds.has(fee.id)) || []),
...add.map((metadata, index) => {
return {
id: parseInt(lastFeeId.toHuman() as string, 10) + index + 1,
Expand Down

0 comments on commit ae51a98

Please sign in to comment.