Skip to content

Commit

Permalink
fix: adjust subintents to wallet api
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx committed Oct 22, 2024
1 parent 791f129 commit a8aac19
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 33 deletions.
2 changes: 0 additions & 2 deletions packages/dapp-toolkit/src/_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import type { Observable } from 'rxjs'
import type { RadixButtonStatus, RadixButtonTheme } from 'radix-connect-common'
import {
CallbackFns,
ExpireAfterSignature,
ExpireAtTime,
Persona,
PersonaDataName,
WalletInteraction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,44 @@ describe('SubintentRequestBuilder', () => {
expect(tx).toEqual({
discriminator: 'subintent',
version: 1,
transactionManifestVersion: 1,
transactionManifest: '...',
manifestVersion: 2,
subintentManifest: '...',
expiration: {
discriminator: 'expireAfterSignature',
value: 60,
discriminator: 'expireAfterDelay',
expireAfterSeconds: 60,
},
blobs: ['deadbeef', 'beefdead'],
message: 'hello',
})
})

it('should build a subintent request with expiration at time', () => {
const tx = SubintentRequestBuilder()
.manifest('...')
.setExpiration('atTime', 1970)
.toRequestItem()

expect(tx).toEqual({
discriminator: 'subintent',
version: 1,
manifestVersion: 2,
subintentManifest: '...',
expiration: {
discriminator: 'expireAtTime',
unixTimestampSeconds: 1970,
},
})
})

it('should build a subintent request using raw object', () => {
const tx = SubintentRequestBuilder()
.rawConfig({
version: 1,
transactionManifestVersion: 1,
transactionManifest: '...',
manifestVersion: 2,
subintentManifest: '...',
expiration: {
discriminator: 'expireAfterSignature',
value: 60,
discriminator: 'expireAfterDelay',
expireAfterSeconds: 60,
},
blobs: ['deadbeef', 'beefdead'],
message: 'hello',
Expand All @@ -42,11 +60,11 @@ describe('SubintentRequestBuilder', () => {
expect(tx).toEqual({
discriminator: 'subintent',
version: 1,
transactionManifestVersion: 1,
transactionManifest: '...',
manifestVersion: 2,
subintentManifest: '...',
expiration: {
discriminator: 'expireAfterSignature',
value: 60,
discriminator: 'expireAfterDelay',
expireAfterSeconds: 60,
},
blobs: ['deadbeef', 'beefdead'],
message: 'hello',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const SubintentRequestBuilder = () => {
let state: Partial<SubintentRequestItem> = {
discriminator: 'subintent',
version: 1,
transactionManifestVersion: 1,
manifestVersion: 2,
}

/**
Expand All @@ -35,10 +35,12 @@ export const SubintentRequestBuilder = () => {
type: 'atTime' | 'secondsAfterSignature',
value: number,
) => {
state.expiration = {
discriminator:
type === 'atTime' ? 'expireAtTime' : 'expireAfterSignature',
value,
state.expiration = type === 'atTime' ? {
discriminator: 'expireAtTime',
unixTimestampSeconds: value,
} : {
discriminator: 'expireAfterDelay',
expireAfterSeconds: value
}
return api
}
Expand Down Expand Up @@ -72,7 +74,7 @@ export const SubintentRequestBuilder = () => {
* @returns The API object for method chaining.
*/
const manifest = (value: string) => {
state.transactionManifest = value
state.subintentManifest = value
return api
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,14 @@ export const WalletRequestModule = (input: {
> => {
const walletInteraction = walletRequestSdk.createWalletInteraction({
discriminator: 'preAuthorizationRequest',
subintent: value.toRequestItem(),
request: value.toRequestItem(),
})

return addNewRequest('preAuthorizationRequest', walletInteraction, false)
.andThen(() => sendRequestAndAwaitResponse(walletInteraction))
.map((requestItem) => ({
signedPartialTransaction:
requestItem.walletResponse.signedPartialTransaction,
requestItem.walletResponse.response.signedPartialTransaction,
}))
}

Expand Down
28 changes: 17 additions & 11 deletions packages/dapp-toolkit/src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,24 +246,30 @@ export const CancelRequest = object({
export type ExpireAtTime = InferOutput<typeof ExpireAtTime>
export const ExpireAtTime = object({
discriminator: literal('expireAtTime'),
value: number(),
unixTimestampSeconds: number(),
})

export type ExpireAfterSignature = InferOutput<typeof ExpireAfterSignature>
export const ExpireAfterSignature = object({
discriminator: literal('expireAfterSignature'),
value: number(),
export type ExpireAfterDelay = InferOutput<typeof ExpireAfterDelay>
export const ExpireAfterDelay = object({
discriminator: literal('expireAfterDelay'),
expireAfterSeconds: number(),
})

export type SubintentRequestItem = InferOutput<typeof SubintentRequestItem>
export const SubintentRequestItem = object({
discriminator: literal('subintent'),
/**
* Version of the message interface
*/
version: number(),
transactionManifestVersion: number(),
transactionManifest: string(),
/**
* Version of the Transaction Manifest
*/
manifestVersion: number(),
subintentManifest: string(),
blobs: optional(array(string())),
message: optional(string()),
expiration: optional(union([ExpireAtTime, ExpireAfterSignature])),
expiration: optional(union([ExpireAtTime, ExpireAfterDelay])),
})

export type SubintentResponseItem = InferOutput<typeof SubintentResponseItem>
Expand All @@ -277,7 +283,7 @@ export type WalletPreAuthorizationItems = InferOutput<
>
export const WalletPreAuthorizationItems = object({
discriminator: literal('preAuthorizationRequest'),
subintent: optional(SubintentRequestItem),
request: optional(SubintentRequestItem),
})

export type WalletInteractionItems = InferOutput<typeof WalletInteractionItems>
Expand Down Expand Up @@ -334,8 +340,8 @@ export type WalletPreAuthorizationResponseItems = InferOutput<
typeof WalletPreAuthorizationResponseItems
>
export const WalletPreAuthorizationResponseItems = object({
discriminator: literal('preAuthorizationRequest'),
subintent: optional(SubintentResponseItem),
discriminator: literal('preAuthorizationResponse'),
response: optional(SubintentResponseItem),
})

export const AuthLoginRequestResponseItem = union([
Expand Down

0 comments on commit a8aac19

Please sign in to comment.