Skip to content

Commit

Permalink
Remove walletUid from pipeWalletServices result (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink authored Aug 7, 2024
1 parent 0956294 commit 919c227
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
7 changes: 4 additions & 3 deletions helpers/__tests__/wallets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ describe('wallets helpers', () => {
uid: `${walletId}#authnpost`,
endpoint: `http://localhost:8701/api/authn`,
provider: {},
walletUid: walletId,
},
] as ServiceWithWallet[]

const servicesPipe = jest.fn(() => clone(mockResult))
const servicesPipe = jest.fn(() => [
{ ...mockResult[0], walletUid: walletId },
])
const makeServicesPipe = jest.fn(() => servicesPipe)

const res = pipeWalletServices(makeServicesPipe)(wallets)
Expand All @@ -47,7 +48,7 @@ describe('wallets helpers', () => {
...y,
walletUid: x.uid,
})),
[] as ServiceWithWallet[]
[] as ServiceWithWallet[],
),
],
])
Expand Down
18 changes: 9 additions & 9 deletions helpers/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const pipeWalletServices =
pipe(
extractWalletServices,
makeServicesPipe({ wallets }),
collectWalletsFromServices({ wallets })
collectWalletsFromServices({ wallets }),
)(wallets)

export const extractWalletServices = (wallets: Wallet[]): ServiceWithWallet[] =>
Expand All @@ -21,7 +21,7 @@ export const extractWalletServices = (wallets: Wallet[]): ServiceWithWallet[] =>
...wallet.services.map(service => ({
...service,
walletUid: wallet.uid,
}))
})),
)
return acc
}, [])
Expand All @@ -39,21 +39,21 @@ export const walletsForNetwork =
export const collectWalletsFromServices =
({ wallets }: { wallets: Wallet[] }) =>
(services: ServiceWithWallet[]) =>
services.reduce((acc, service) => {
services.reduce((acc, _service) => {
// Append service without reference to wallet
const { walletUid, ...service } = _service
const existingWalletIdx = acc.findIndex(
wallet => wallet.uid === service.walletUid
wallet => wallet.uid === walletUid,
)

if (existingWalletIdx === -1) {
const wallet = wallets.find(wallet => wallet.uid === service.walletUid)
const wallet = wallets.find(wallet => wallet.uid === walletUid)
acc.push({
...wallet,
services: [service],
})
} else {
// Append service without reference to wallet
const { walletUid, ...serviceWithoutWallet } = service
acc[existingWalletIdx].services.push(serviceWithoutWallet)
acc[existingWalletIdx].services.push(service)
}
return acc
}, [])
Expand All @@ -79,7 +79,7 @@ export function extractAllServicesWithProvider(wallets: Wallet[]) {
...walletToProvider(wallet),
...service.provider,
},
}))
})),
)
return acc
}, [])
Expand Down

0 comments on commit 919c227

Please sign in to comment.