From d71fb4e5a5f2b695690d005223fcd01dd6ec8a24 Mon Sep 17 00:00:00 2001 From: katspaugh <381895+katspaugh@users.noreply.github.com> Date: Fri, 17 Jan 2025 14:33:02 +0100 Subject: [PATCH 1/3] Feat: tx preview and tx notes --- package.json | 2 +- src/index.ts | 9 ++++++--- src/types/decoded-data.ts | 1 + src/types/transactions.ts | 13 +++++++------ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 2f092e8c..d64c3d2b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@safe-global/safe-gateway-typescript-sdk", - "version": "3.22.6", + "version": "3.22.7-beta.1", "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ diff --git a/src/index.ts b/src/index.ts index 4a0b7059..0ade6438 100644 --- a/src/index.ts +++ b/src/index.ts @@ -303,13 +303,14 @@ export function proposeTransaction( export function getConfirmationView( chainId: string, safeAddress: string, + operation: operations['data_decoder']['parameters']['body']['operation'], data: operations['data_decoder']['parameters']['body']['data'], to?: operations['data_decoder']['parameters']['body']['to'], value?: operations['data_decoder']['parameters']['body']['value'], ): Promise { return postEndpoint(baseUrl, '/v1/chains/{chainId}/safes/{safe_address}/views/transaction-confirmation', { path: { chainId, safe_address: safeAddress }, - body: { data, to, value }, + body: { operation, data, to, value }, }) } @@ -319,13 +320,14 @@ export function getConfirmationView( export function getTxPreview( chainId: string, safeAddress: string, + operation: operations['data_decoder']['parameters']['body']['operation'], data: operations['data_decoder']['parameters']['body']['data'], to?: operations['data_decoder']['parameters']['body']['to'], value?: operations['data_decoder']['parameters']['body']['value'], ): Promise { return postEndpoint(baseUrl, '/v1/chains/{chainId}/transactions/{safe_address}/preview', { path: { chainId, safe_address: safeAddress }, - body: { data, to, value }, + body: { operation, data, to, value }, }) } @@ -374,12 +376,13 @@ export function getMasterCopies(chainId: string): Promise { */ export function getDecodedData( chainId: string, + operation: operations['data_decoder']['parameters']['body']['operation'], encodedData: operations['data_decoder']['parameters']['body']['data'], to?: operations['data_decoder']['parameters']['body']['to'], ): Promise { return postEndpoint(baseUrl, '/v1/chains/{chainId}/data-decoder', { path: { chainId: chainId }, - body: { data: encodedData, to }, + body: { operation, data: encodedData, to }, }) } diff --git a/src/types/decoded-data.ts b/src/types/decoded-data.ts index d5ae5d04..dc594556 100644 --- a/src/types/decoded-data.ts +++ b/src/types/decoded-data.ts @@ -11,6 +11,7 @@ export enum ConfirmationViewTypes { } export type DecodedDataRequest = { + operation: 0 | 1 data: string to?: string value?: string diff --git a/src/types/transactions.ts b/src/types/transactions.ts index 0918ec6c..88259acf 100644 --- a/src/types/transactions.ts +++ b/src/types/transactions.ts @@ -518,13 +518,14 @@ export type DetailedExecutionInfo = ModuleExecutionDetails | MultisigExecutionDe export type TransactionDetails = { safeAddress: string txId: string - executedAt?: number + executedAt?: number | null txStatus: TransactionStatus - txInfo: TransactionInfo - txData?: TransactionData - detailedExecutionInfo?: DetailedExecutionInfo - txHash?: string - safeAppInfo?: SafeAppInfo + txInfo: TransactionInfo | null + txData?: TransactionData | null + detailedExecutionInfo?: DetailedExecutionInfo | null + txHash?: string | null + safeAppInfo?: SafeAppInfo | null + note?: string | null } /* Transaction details types end */ From cb5c61402ef230f2e6a6a4108053af0cc21e5322 Mon Sep 17 00:00:00 2001 From: katspaugh <381895+katspaugh@users.noreply.github.com> Date: Fri, 17 Jan 2025 14:42:41 +0100 Subject: [PATCH 2/3] Fix tests --- tests/endpoint.test.ts | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/tests/endpoint.test.ts b/tests/endpoint.test.ts index bcb1805b..6dbbe81c 100644 --- a/tests/endpoint.test.ts +++ b/tests/endpoint.test.ts @@ -104,35 +104,18 @@ describe('getEndpoint', () => { expect(getData).toHaveBeenCalledWith('/test-url?raw=true', undefined, undefined) }) - it('should call a data decoder POST endpoint', async () => { + it('should call a tx preview POST endpoint', async () => { await expect( - postEndpoint('https://test.test', '/v1/chains/{chainId}/data-decoder', { - path: { chainId: '4' }, - body: { data: '0x123' }, - }), - ).resolves.toEqual({ success: true }) - - expect(fetchData).toHaveBeenCalledWith( - 'https://test.test/v1/chains/4/data-decoder', - 'POST', - { data: '0x123' }, - undefined, - undefined, - ) - }) - - it('should call a data decoder confirmation view POST endpoint', async () => { - await expect( - postEndpoint('https://test.test', '/v1/chains/{chainId}/safes/{safe_address}/views/transaction-confirmation', { + postEndpoint('https://test.test', '/v1/chains/{chainId}/transactions/{safe_address}/preview', { path: { chainId: '4', safe_address: '0x123' }, - body: { data: '0x456' }, + body: { data: '0x456', operation: 0 }, }), ).resolves.toEqual({ success: true }) expect(fetchData).toHaveBeenCalledWith( - 'https://test.test/v1/chains/4/safes/0x123/views/transaction-confirmation', + 'https://test.test/v1/chains/4/transactions/0x123/preview', 'POST', - { data: '0x456' }, + { data: '0x456', operation: 0 }, undefined, undefined, ) From 3e2b42be19bb52755cb6d978069937c709faa984 Mon Sep 17 00:00:00 2001 From: katspaugh <381895+katspaugh@users.noreply.github.com> Date: Fri, 17 Jan 2025 15:08:19 +0100 Subject: [PATCH 3/3] Rm | null --- package.json | 2 +- src/types/transactions.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index d64c3d2b..dff120df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@safe-global/safe-gateway-typescript-sdk", - "version": "3.22.7-beta.1", + "version": "3.22.7-beta.2", "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ diff --git a/src/types/transactions.ts b/src/types/transactions.ts index 88259acf..71a10c39 100644 --- a/src/types/transactions.ts +++ b/src/types/transactions.ts @@ -518,13 +518,13 @@ export type DetailedExecutionInfo = ModuleExecutionDetails | MultisigExecutionDe export type TransactionDetails = { safeAddress: string txId: string - executedAt?: number | null + executedAt?: number txStatus: TransactionStatus - txInfo: TransactionInfo | null - txData?: TransactionData | null - detailedExecutionInfo?: DetailedExecutionInfo | null - txHash?: string | null - safeAppInfo?: SafeAppInfo | null + txInfo: TransactionInfo + txData?: TransactionData + detailedExecutionInfo?: DetailedExecutionInfo + txHash?: string + safeAppInfo?: SafeAppInfo note?: string | null }