Skip to content

Commit

Permalink
fix: pass intent hash correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx committed Dec 13, 2024
1 parent e689b17 commit 783f1c4
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ export const RequestItemModule = (input: RequestItemModuleInput) => {
signals.delete(id)
}
if (status === RequestStatus.success) {
getAndRemoveSignal(id)?.(item.metadata?.parentTransactionIntentHash as string)
const signal = getAndRemoveSignal(id)
signal?.(metadata?.parentTransactionIntentHash as string)
}
const updated = {
...item,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ import { WalletRequestModule } from './wallet-request'
import { RadixNetwork, TransactionStatus } from '../gateway'
import { LocalStorageModule } from '../storage'
import { ok, okAsync, ResultAsync } from 'neverthrow'
import {
WalletInteractionFailureResponse,
WalletInteractionItems,
} from '../../schemas'
import { WalletInteractionItems } from '../../schemas'
import {
failedResponseResolver,
preAuthorizationResponseResolver,
RequestResolverModule,
sendTransactionResponseResolver,
} from './request-resolver'
import { RequestItemModule } from './request-items'
import { delayAsync } from '../../test-helpers/delay-async'
import { WalletRequestSdk } from './wallet-request-sdk'
import { TransportProvider } from '../../_types'
import { TestingTransportModule } from './transport/testing-transport/transport.testing-module'
import { EnvironmentModule } from '../environment'
import { SubintentRequestBuilder } from './pre-authorization-request'

const createMockEnvironment = () => {
const storageModule = LocalStorageModule(`rdt:${crypto.randomUUID()}:1`, {
Expand All @@ -30,6 +28,16 @@ const createMockEnvironment = () => {
ResultAsync.fromSafePromise(delayAsync(2000)).map(() =>
ok({ status: 'success' as TransactionStatus }),
),

pollSubintentStatus: () => {
return {
stop: () => undefined,
result: ResultAsync.fromSafePromise(delayAsync(100)).map(() => ({
subintentStatus: 'CommittedSuccess' as TransactionStatus,
transactionIntentHash: 'transactionIntentHash',
})),
}
},
} as any
const requestItemModule = RequestItemModule({
providers: {
Expand Down Expand Up @@ -207,4 +215,100 @@ describe('WalletRequestModule', () => {
)
})
})

describe('GIVEN subintent is submitted to the network', () => {
describe('AND onSubmittedSuccess callback is provided', () => {
it('should call the callback with transaction intent hash', async () => {
// Arange
const {
storageModule,
requestItemModule,
gatewayModule,
updateConnectButtonStatus,
} = createMockEnvironment()

const requestResolverModule = RequestResolverModule({
providers: {
storageModule,
requestItemModule,
resolvers: [
preAuthorizationResponseResolver({
requestItemModule,
updateConnectButtonStatus,
}),
],
},
})

const interactionId = '8cefec84'

const testingTransport = TestingTransportModule({
requestResolverModule,
})
testingTransport.setNextWalletResponse({
discriminator: 'success',
items: {
discriminator: 'preAuthorizationResponse',
response: {
subintentHash:
'subtxid_tdx_2_17nhcfn9njxlrvgl8afk5dwcaj2peydrtzty0rppdm5dqnwqxs6sq0u59fe',
expirationTimestamp: Math.floor(Date.now() / 1000) + 3600,
signedPartialTransaction:
'4d220e03210221012105210607020a32ef0000000000000a40ef00000000000022000',
},
},
interactionId,
})

const walletRequestModule = WalletRequestModule({
useCache: false,
networkId: RadixNetwork.Stokenet,
dAppDefinitionAddress: '',
providers: {
stateModule: {} as any,
storageModule,
requestItemModule,
requestResolverModule,
environmentModule: EnvironmentModule(),
gatewayModule,
walletRequestSdk: WalletRequestSdk({
networkId: 2,
dAppDefinitionAddress: '',
providers: {
environmentModule: EnvironmentModule(),
interactionIdFactory: () => interactionId,
transports: [testingTransport],
},
}),
},
})

const onSubmittedSpy = vi.fn()
// Act
const result = await walletRequestModule.sendPreAuthorizationRequest(
SubintentRequestBuilder()
.manifest(``)
.setExpiration('afterDelay', 4600)
.onSubmittedSuccess((a) => {
console.log('onSubmittedSuccess', a)
onSubmittedSpy(a)
}),
)

await delayAsync(2000)

// Assert

expect(onSubmittedSpy).toHaveBeenCalledWith('transactionIntentHash')
expect(result.isOk() && result.value).toEqual(
expect.objectContaining({
signedPartialTransaction:
'4d220e03210221012105210607020a32ef0000000000000a40ef00000000000022000',
subintentHash:
'subtxid_tdx_2_17nhcfn9njxlrvgl8afk5dwcaj2peydrtzty0rppdm5dqnwqxs6sq0u59fe',
}),
)
})
})
})
})

0 comments on commit 783f1c4

Please sign in to comment.