Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: tx preview and tx notes #209

Merged
merged 3 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -525,6 +525,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
Loading