Skip to content

Commit

Permalink
refactor: encode wallet interaction in deep link url
Browse files Browse the repository at this point in the history
  • Loading branch information
xstelea committed Jun 11, 2024
1 parent f8c3167 commit f614de0
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 24 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/dapp-toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
},
"dependencies": {
"@noble/curves": "^1.4.0",
"base64url": "^3.0.1",
"bowser": "^2.11.0",
"buffer": "^6.0.3",
"immer": "^10.0.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import base64url from 'base64url'

export const base64urlEncode = <T extends Record<string, any>>(
value: T,
): string => base64url.encode(Buffer.from(JSON.stringify(value)))
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { RadixConnectRelayApiService } from './radix-connect-relay-api.service'
import { RequestItem } from 'radix-connect-common'
import type { TransportProvider } from '../../../../_types'
import { RcfmPageModule, RcfmPageState } from './rcfm-page.module'
import { base64urlEncode } from './helpers/base64url'

export type RadixConnectRelayModule = ReturnType<typeof RadixConnectRelayModule>
export const RadixConnectRelayModule = (input: {
Expand Down Expand Up @@ -119,16 +120,11 @@ export const RadixConnectRelayModule = (input: {
.andThen((pendingItem) =>
requestItemModule
.patch(walletInteraction.interactionId, { sentToWallet: true })
.andThen(() =>
radixConnectRelayApiService.sendRequest(
session,
pendingItem.walletInteraction,
),
)
.andThen(() =>
deepLinkModule.deepLinkToWallet({
sessionId: session.sessionId,
interactionId: pendingItem.interactionId,
walletInteraction: base64urlEncode(walletInteraction),
}),
),
)
Expand Down Expand Up @@ -204,27 +200,25 @@ export const RadixConnectRelayModule = (input: {
pendingItem?: RequestItem
}) =>
pendingItem
? radixConnectRelayApiService
.sendRequest(activeSession, pendingItem.walletInteraction)
.andThen(() =>
requestItemModule
.patch(pendingItem.interactionId, {
sentToWallet: true,
})
.mapErr(() =>
SdkError(
'FailedToUpdateRequestItem',
pendingItem.interactionId,
),
)
.map(() => pendingItem.interactionId),
? requestItemModule
.patch(pendingItem.interactionId, {
sentToWallet: true,
})
.mapErr(() =>
SdkError(
'FailedToUpdateRequestItem',
pendingItem.interactionId,
),
)
.map((interactionId) => {
.andThen(() =>
deepLinkModule.deepLinkToWallet({
sessionId,
interactionId,
})
})
interactionId: pendingItem.walletInteraction.interactionId,
walletInteraction: base64urlEncode(
pendingItem.walletInteraction,
),
}),
)
: ok(pendingItem),
)

Expand Down
5 changes: 5 additions & 0 deletions packages/dapp-toolkit/src/polyfills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Buffer } from 'buffer'

export default () => {
if (!globalThis.Buffer) globalThis.Buffer = Buffer
}
4 changes: 4 additions & 0 deletions packages/dapp-toolkit/src/radix-dapp-toolkit.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import polyfills from './polyfills'

polyfills()

import type {
ButtonApi,
GatewayApiClientConfig,
Expand Down

0 comments on commit f614de0

Please sign in to comment.