Skip to content

Commit

Permalink
chore: make wallets unique by id before updating state (#2366)
Browse files Browse the repository at this point in the history
Co-authored-by: Enes <[email protected]>
  • Loading branch information
tomiir and enesozturk authored Jun 11, 2024
1 parent 092a328 commit fc69404
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/controllers/ApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export const ApiController = {
...(images as string[]).map(id => ApiController._fetchWalletImage(id)),
CoreHelperUtil.wait(300)
])
state.wallets = [...state.wallets, ...data]
state.wallets = CoreHelperUtil.uniqueBy([...state.wallets, ...data], 'id')
state.count = count > state.count ? count : state.count
state.page = page
},
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/utils/CoreHelperUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,19 @@ export const CoreHelperUtil = {
}

return false
},

uniqueBy<T>(arr: T[], key: keyof T) {
const set = new Set()

return arr.filter(item => {
const keyValue = item[key]
if (set.has(keyValue)) {
return false
}
set.add(keyValue)

return true
})
}
}

0 comments on commit fc69404

Please sign in to comment.