Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove walletUid from /api/wallets call #223

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading