Skip to content

Commit a6b7051

Browse files
authored
fix: avoid tx data as url param for approve view (#911)
Signed-off-by: Marc Juchli <[email protected]>
1 parent ada3acb commit a6b7051

File tree

8 files changed

+262
-20
lines changed

8 files changed

+262
-20
lines changed

api-specs/openrpc-user-api.json

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,7 @@
348348
"type": "string"
349349
},
350350
"commandId": {
351-
"title": "commandId",
352-
"type": "string"
351+
"$ref": "#/components/schemas/CommandId"
353352
},
354353
"partyId": {
355354
"title": "partyId",
@@ -407,8 +406,7 @@
407406
"type": "string"
408407
},
409408
"commandId": {
410-
"title": "commandId",
411-
"type": "string",
409+
"$ref": "#/components/schemas/CommandId",
412410
"description": "The command ID of the transaction to be executed."
413411
},
414412
"signedBy": {
@@ -494,6 +492,62 @@
494492
"required": ["sessions"]
495493
}
496494
}
495+
},
496+
{
497+
"name": "getTransaction",
498+
"params": [
499+
{
500+
"name": "params",
501+
"schema": {
502+
"title": "GetTransactionParams",
503+
"type": "object",
504+
"properties": {
505+
"commandId": {
506+
"$ref": "#/components/schemas/CommandId"
507+
}
508+
},
509+
"required": ["commandId"]
510+
}
511+
}
512+
],
513+
"result": {
514+
"name": "result",
515+
"schema": {
516+
"title": "GetTransactionResult",
517+
"type": "object",
518+
"properties": {
519+
"commandId": {
520+
"$ref": "#/components/schemas/CommandId"
521+
},
522+
"status": {
523+
"title": "status",
524+
"type": "string",
525+
"description": "The status of the transaction."
526+
},
527+
"preparedTransaction": {
528+
"title": "preparedTransaction",
529+
"type": "string",
530+
"description": "The transaction data corresponding to the command ID."
531+
},
532+
"preparedTransactionHash": {
533+
"title": "preparedTransactionHash",
534+
"type": "string",
535+
"description": "The hash of the prepared transaction."
536+
},
537+
"payload": {
538+
"title": "payload",
539+
"type": "string",
540+
"description": "Optional payload associated with the transaction."
541+
}
542+
},
543+
"required": [
544+
"commandId",
545+
"status",
546+
"preparedTransaction",
547+
"preparedTransactionHash"
548+
]
549+
}
550+
}
497551
}
498552
],
499553
"components": {
@@ -503,6 +557,11 @@
503557
"type": "null",
504558
"description": "Represents a null value, used in responses where no data is returned."
505559
},
560+
"CommandId": {
561+
"title": "CommandId",
562+
"type": "string",
563+
"description": "The unique identifier of the command associated with the transaction."
564+
},
506565
"Network": {
507566
"title": "Network",
508567
"type": "object",
@@ -638,7 +697,6 @@
638697
"enum": ["initialized", "allocated"],
639698
"description": "The status of the wallet."
640699
},
641-
642700
"hint": {
643701
"title": "hint",
644702
"type": "string",

core/wallet-user-rpc-client/src/index.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,21 @@ export interface WalletFilter {
179179
signingProviderIds?: SigningProviderIds
180180
[k: string]: any
181181
}
182+
/**
183+
*
184+
* The transaction data corresponding to the command ID.
185+
*
186+
*/
182187
export type PreparedTransaction = string
188+
/**
189+
*
190+
* The hash of the prepared transaction.
191+
*
192+
*/
183193
export type PreparedTransactionHash = string
184194
/**
185195
*
186-
* The command ID of the transaction to be executed.
196+
* The unique identifier of the command associated with the transaction.
187197
*
188198
*/
189199
export type CommandId = string
@@ -235,7 +245,12 @@ export type Removed = Wallet[]
235245
*
236246
*/
237247
export type AccessToken = string
238-
export type Status = 'connected' | 'disconnected'
248+
/**
249+
*
250+
* The status of the transaction.
251+
*
252+
*/
253+
export type Status = string
239254
/**
240255
*
241256
* The reason for the current status.
@@ -254,6 +269,12 @@ export interface Session {
254269
reason?: Reason
255270
}
256271
export type Sessions = Session[]
272+
/**
273+
*
274+
* Optional payload associated with the transaction.
275+
*
276+
*/
277+
export type Payload = string
257278
export interface AddNetworkParams {
258279
network: Network
259280
[k: string]: any
@@ -308,6 +329,10 @@ export interface AddSessionParams {
308329
networkId: NetworkId
309330
[k: string]: any
310331
}
332+
export interface GetTransactionParams {
333+
commandId: CommandId
334+
[k: string]: any
335+
}
311336
/**
312337
*
313338
* Represents a null value, used in responses where no data is returned.
@@ -369,6 +394,14 @@ export interface ListSessionsResult {
369394
sessions: Sessions
370395
[k: string]: any
371396
}
397+
export interface GetTransactionResult {
398+
commandId: CommandId
399+
status: Status
400+
preparedTransaction: PreparedTransaction
401+
preparedTransactionHash: PreparedTransactionHash
402+
payload?: Payload
403+
[k: string]: any
404+
}
372405
/**
373406
*
374407
* Generated! Represents an alias to any of the provided schemas
@@ -397,6 +430,9 @@ export type Execute = (params: ExecuteParams) => Promise<ExecuteResult>
397430
export type AddSession = (params: AddSessionParams) => Promise<AddSessionResult>
398431
export type RemoveSession = () => Promise<Null>
399432
export type ListSessions = () => Promise<ListSessionsResult>
433+
export type GetTransaction = (
434+
params: GetTransactionParams
435+
) => Promise<GetTransactionResult>
400436

401437
export class SpliceWalletJSONRPCUserAPI {
402438
public transport: RpcTransport
@@ -549,6 +585,15 @@ export class SpliceWalletJSONRPCUserAPI {
549585
...params: Parameters<ListSessions>
550586
): ReturnType<ListSessions>
551587

588+
/**
589+
*
590+
*/
591+
// tslint:disable-next-line:max-line-length
592+
public async request(
593+
method: 'getTransaction',
594+
...params: Parameters<GetTransaction>
595+
): ReturnType<GetTransaction>
596+
552597
public async request(
553598
method: string,
554599
params?: RequestPayload['params']

core/wallet-user-rpc-client/src/openrpc.json

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,7 @@
348348
"type": "string"
349349
},
350350
"commandId": {
351-
"title": "commandId",
352-
"type": "string"
351+
"$ref": "#/components/schemas/CommandId"
353352
},
354353
"partyId": {
355354
"title": "partyId",
@@ -407,8 +406,7 @@
407406
"type": "string"
408407
},
409408
"commandId": {
410-
"title": "commandId",
411-
"type": "string",
409+
"$ref": "#/components/schemas/CommandId",
412410
"description": "The command ID of the transaction to be executed."
413411
},
414412
"signedBy": {
@@ -494,6 +492,62 @@
494492
"required": ["sessions"]
495493
}
496494
}
495+
},
496+
{
497+
"name": "getTransaction",
498+
"params": [
499+
{
500+
"name": "params",
501+
"schema": {
502+
"title": "GetTransactionParams",
503+
"type": "object",
504+
"properties": {
505+
"commandId": {
506+
"$ref": "#/components/schemas/CommandId"
507+
}
508+
},
509+
"required": ["commandId"]
510+
}
511+
}
512+
],
513+
"result": {
514+
"name": "result",
515+
"schema": {
516+
"title": "GetTransactionResult",
517+
"type": "object",
518+
"properties": {
519+
"commandId": {
520+
"$ref": "#/components/schemas/CommandId"
521+
},
522+
"status": {
523+
"title": "status",
524+
"type": "string",
525+
"description": "The status of the transaction."
526+
},
527+
"preparedTransaction": {
528+
"title": "preparedTransaction",
529+
"type": "string",
530+
"description": "The transaction data corresponding to the command ID."
531+
},
532+
"preparedTransactionHash": {
533+
"title": "preparedTransactionHash",
534+
"type": "string",
535+
"description": "The hash of the prepared transaction."
536+
},
537+
"payload": {
538+
"title": "payload",
539+
"type": "string",
540+
"description": "Optional payload associated with the transaction."
541+
}
542+
},
543+
"required": [
544+
"commandId",
545+
"status",
546+
"preparedTransaction",
547+
"preparedTransactionHash"
548+
]
549+
}
550+
}
497551
}
498552
],
499553
"components": {
@@ -503,6 +557,11 @@
503557
"type": "null",
504558
"description": "Represents a null value, used in responses where no data is returned."
505559
},
560+
"CommandId": {
561+
"title": "CommandId",
562+
"type": "string",
563+
"description": "The unique identifier of the command associated with the transaction."
564+
},
506565
"Network": {
507566
"title": "Network",
508567
"type": "object",

wallet-gateway/remote/src/dapp-api/controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export const dappController = (
165165

166166
return {
167167
// TODO: pull user base URL / port from config
168-
userUrl: `http://localhost:3030/approve/index.html?commandId=${commandId}&partyId=${wallet.partyId}&txHash=${encodeURIComponent(preparedTransactionHash)}&tx=${encodeURIComponent(preparedTransaction)}`,
168+
userUrl: `http://localhost:3030/approve/index.html?commandId=${commandId}`,
169169
}
170170
},
171171
prepareReturn: async (params: PrepareReturnParams) => {

wallet-gateway/remote/src/user-api/controller.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
AddIdpParams,
1919
RemoveIdpParams,
2020
CreateWalletParams,
21+
GetTransactionResult,
22+
GetTransactionParams,
2123
Null,
2224
} from './rpc-gen/typings.js'
2325
import {
@@ -664,5 +666,24 @@ export const userController = (
664666
notifier?.emit('accountsChanged', wallets)
665667
return result
666668
},
669+
getTransaction: async (
670+
params: GetTransactionParams
671+
): Promise<GetTransactionResult> => {
672+
const transaction = await store.getTransaction(params.commandId)
673+
if (!transaction) {
674+
throw new Error(
675+
`Transaction not found with commandId: ${params.commandId}`
676+
)
677+
}
678+
return {
679+
commandId: transaction.commandId,
680+
status: transaction.status,
681+
preparedTransaction: transaction.preparedTransaction,
682+
preparedTransactionHash: transaction.preparedTransactionHash,
683+
payload: transaction.payload
684+
? JSON.stringify(transaction.payload)
685+
: '',
686+
}
687+
},
667688
})
668689
}

wallet-gateway/remote/src/user-api/rpc-gen/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { Execute } from './typings.js'
1717
import { AddSession } from './typings.js'
1818
import { RemoveSession } from './typings.js'
1919
import { ListSessions } from './typings.js'
20+
import { GetTransaction } from './typings.js'
2021

2122
export type Methods = {
2223
addNetwork: AddNetwork
@@ -35,6 +36,7 @@ export type Methods = {
3536
addSession: AddSession
3637
removeSession: RemoveSession
3738
listSessions: ListSessions
39+
getTransaction: GetTransaction
3840
}
3941

4042
function buildController(methods: Methods) {
@@ -55,6 +57,7 @@ function buildController(methods: Methods) {
5557
addSession: methods.addSession,
5658
removeSession: methods.removeSession,
5759
listSessions: methods.listSessions,
60+
getTransaction: methods.getTransaction,
5861
}
5962
}
6063

0 commit comments

Comments
 (0)