Skip to content

Commit

Permalink
Feat: tx preview and tx notes (#209)
Browse files Browse the repository at this point in the history
* Feat: tx preview and tx notes

* Fix tests

* Rm | null
  • Loading branch information
katspaugh authored Jan 20, 2025
1 parent 7b53ccf commit 06d0901
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@safe-global/safe-gateway-typescript-sdk",
"version": "3.22.6",
"version": "3.22.7-beta.2",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
Expand Down
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnyConfirmationView> {
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 },
})
}

Expand All @@ -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<TransactionPreview> {
return postEndpoint(baseUrl, '/v1/chains/{chainId}/transactions/{safe_address}/preview', {
path: { chainId, safe_address: safeAddress },
body: { data, to, value },
body: { operation, data, to, value },
})
}

Expand Down Expand Up @@ -374,12 +376,13 @@ export function getMasterCopies(chainId: string): Promise<MasterCopyReponse> {
*/
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<DecodedDataResponse> {
return postEndpoint(baseUrl, '/v1/chains/{chainId}/data-decoder', {
path: { chainId: chainId },
body: { data: encodedData, to },
body: { operation, data: encodedData, to },
})
}

Expand Down
1 change: 1 addition & 0 deletions src/types/decoded-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum ConfirmationViewTypes {
}

export type DecodedDataRequest = {
operation: 0 | 1
data: string
to?: string
value?: string
Expand Down
1 change: 1 addition & 0 deletions src/types/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ export type TransactionDetails = {
detailedExecutionInfo?: DetailedExecutionInfo
txHash?: string
safeAppInfo?: SafeAppInfo
note?: string | null
}

/* Transaction details types end */
Expand Down
27 changes: 5 additions & 22 deletions tests/endpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down

0 comments on commit 06d0901

Please sign in to comment.