Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
fix: remove reset for unauthorizedRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
xstelea committed Mar 22, 2023
1 parent f4cc5c4 commit bb575ae
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 0 additions & 1 deletion lib/IO/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ const WalletUnauthorizedRequestItemsSchema = object({
discriminator: literal('unauthorizedRequest'),
oneTimeAccounts: OneTimeAccountsRequestItemSchema.optional(),
oneTimePersonaData: OneTimePersonaDataRequestItemSchema.optional(),
reset: ResetRequestSchema.optional(),
})

export type WalletUnauthorizedRequestItems = z.infer<
Expand Down
24 changes: 22 additions & 2 deletions lib/IO/transform-method-input.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { ok } from 'neverthrow'
import { requestMethodRequestType } from '../methods/request'
import { NumberOfAccounts, WalletInteractionItems } from './schemas'
import {
NumberOfAccounts,
ResetRequestItem,
WalletInteractionItems,
WalletUnauthorizedRequestItems,
} from './schemas'

export const provideDefaultNumberOfAccounts = (
value: Partial<NumberOfAccounts>
Expand All @@ -9,6 +14,20 @@ export const provideDefaultNumberOfAccounts = (
quantifier: value?.quantifier || 'atLeast',
})

const removeResetForUnauthorizedRequest = (value: WalletInteractionItems) => {
if (
value.discriminator === 'transaction' ||
value.discriminator === 'authorizedRequest'
)
return value

const { reset, ...rest } = value as WalletUnauthorizedRequestItems & {
reset: ResetRequestItem
}

return rest
}

export const transformMethodInput = <I extends {}>(input: I) =>
ok(
Object.entries(input).reduce<WalletInteractionItems>(
Expand Down Expand Up @@ -73,6 +92,7 @@ export const transformMethodInput = <I extends {}>(input: I) =>

case requestMethodRequestType.reset: {
const { accounts = false, personaData = false } = value
if (!accounts && !personaData) return acc
return {
...acc,
reset: { accounts, personaData },
Expand All @@ -96,4 +116,4 @@ export const transformMethodInput = <I extends {}>(input: I) =>
discriminator: 'unauthorizedRequest',
}
)
)
).map(removeResetForUnauthorizedRequest)
1 change: 0 additions & 1 deletion lib/__tests__/transform-method-input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ describe('transformMethodInput', () => {
{
actual: requestItem.reset({ accounts: true }),
expected: {
reset: { accounts: true, personaData: false },
discriminator: 'unauthorizedRequest',
},
},
Expand Down

0 comments on commit bb575ae

Please sign in to comment.