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

fix: pass intent hash correctly #300

Merged
merged 1 commit into from
Dec 13, 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
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',
}),
)
})
})
})
})
Loading