Skip to content

Commit 0e29693

Browse files
committed
refactor: encode wallet interaction in deep link url
1 parent 9b34b0b commit 0e29693

File tree

6 files changed

+42
-24
lines changed

6 files changed

+42
-24
lines changed

package-lock.json

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dapp-toolkit/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
},
6161
"dependencies": {
6262
"@noble/curves": "^1.4.0",
63+
"base64url": "^3.0.1",
6364
"bowser": "^2.11.0",
6465
"buffer": "^6.0.3",
6566
"immer": "^10.0.4",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import base64url from 'base64url'
2+
3+
export const base64urlEncode = <T extends Record<string, any>>(
4+
value: T,
5+
): string => base64url.encode(Buffer.from(JSON.stringify(value)))

packages/dapp-toolkit/src/modules/wallet-request/transport/radix-connect-relay/radix-connect-relay.module.ts

+18-24
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { RadixConnectRelayApiService } from './radix-connect-relay-api.service'
2323
import { RequestItem } from 'radix-connect-common'
2424
import type { TransportProvider } from '../../../../_types'
2525
import { RcfmPageModule, RcfmPageState } from './rcfm-page.module'
26+
import { base64urlEncode } from './helpers/base64url'
2627

2728
export type RadixConnectRelayModule = ReturnType<typeof RadixConnectRelayModule>
2829
export const RadixConnectRelayModule = (input: {
@@ -119,16 +120,11 @@ export const RadixConnectRelayModule = (input: {
119120
.andThen((pendingItem) =>
120121
requestItemModule
121122
.patch(walletInteraction.interactionId, { sentToWallet: true })
122-
.andThen(() =>
123-
radixConnectRelayApiService.sendRequest(
124-
session,
125-
pendingItem.walletInteraction,
126-
),
127-
)
128123
.andThen(() =>
129124
deepLinkModule.deepLinkToWallet({
130125
sessionId: session.sessionId,
131126
interactionId: pendingItem.interactionId,
127+
walletInteraction: base64urlEncode(walletInteraction),
132128
}),
133129
),
134130
)
@@ -204,27 +200,25 @@ export const RadixConnectRelayModule = (input: {
204200
pendingItem?: RequestItem
205201
}) =>
206202
pendingItem
207-
? radixConnectRelayApiService
208-
.sendRequest(activeSession, pendingItem.walletInteraction)
209-
.andThen(() =>
210-
requestItemModule
211-
.patch(pendingItem.interactionId, {
212-
sentToWallet: true,
213-
})
214-
.mapErr(() =>
215-
SdkError(
216-
'FailedToUpdateRequestItem',
217-
pendingItem.interactionId,
218-
),
219-
)
220-
.map(() => pendingItem.interactionId),
203+
? requestItemModule
204+
.patch(pendingItem.interactionId, {
205+
sentToWallet: true,
206+
})
207+
.mapErr(() =>
208+
SdkError(
209+
'FailedToUpdateRequestItem',
210+
pendingItem.interactionId,
211+
),
221212
)
222-
.map((interactionId) => {
213+
.andThen(() =>
223214
deepLinkModule.deepLinkToWallet({
224215
sessionId,
225-
interactionId,
226-
})
227-
})
216+
interactionId: pendingItem.walletInteraction.interactionId,
217+
walletInteraction: base64urlEncode(
218+
pendingItem.walletInteraction,
219+
),
220+
}),
221+
)
228222
: ok(pendingItem),
229223
)
230224

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Buffer } from 'buffer'
2+
3+
export default () => {
4+
if (!globalThis.Buffer) globalThis.Buffer = Buffer
5+
}

packages/dapp-toolkit/src/radix-dapp-toolkit.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import polyfills from './polyfills'
2+
3+
polyfills()
4+
15
import type {
26
ButtonApi,
37
GatewayApiClientConfig,

0 commit comments

Comments
 (0)