From 6ca9f7d5cc6df65883c30d6efe9ebe0d38f065d0 Mon Sep 17 00:00:00 2001 From: Daniel Dimitrov Date: Mon, 22 Apr 2024 18:10:27 +0200 Subject: [PATCH] feat: add confirmation view endpoint types (#163) --- src/index.ts | 15 +++++++++++++++ src/types/api.ts | 32 +++++++++++++++++++++++++++++++- src/types/decoded-data.ts | 9 +++++++++ src/types/transactions.ts | 2 +- tests/endpoint.test.ts | 16 ++++++++++++++++ 5 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4d5e529f..ec450df4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -294,6 +294,21 @@ export function proposeTransaction( }) } +/** + * Returns decoded data + */ +export function getConfirmationView( + chainId: string, + safeAddress: string, + encodedData: operations['data_decoder']['parameters']['body']['data'], + to?: operations['data_decoder']['parameters']['body']['to'], +): Promise { + return postEndpoint(baseUrl, '/v1/chains/{chainId}/safes/{safe_address}/views/transaction-confirmation', { + path: { chainId: chainId, safe_address: safeAddress }, + body: { data: encodedData, to }, + }) +} + /** * Returns all defined chain configs */ diff --git a/src/types/api.ts b/src/types/api.ts index 20d34511..eaa249f5 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -20,7 +20,12 @@ import type { import type { SafeInfo, SafeOverview } from './safe-info' import type { ChainListResponse, ChainInfo } from './chains' import type { SafeAppsResponse } from './safe-apps' -import type { DecodedDataRequest, DecodedDataResponse } from './decoded-data' +import type { + BaselineConfirmationView, + CowSwapConfirmationView, + DecodedDataRequest, + DecodedDataResponse, +} from './decoded-data' import type { MasterCopyReponse } from './master-copies' import type { ConfirmSafeMessageRequest, @@ -54,6 +59,7 @@ interface BodyParams extends Params { interface Responses { 200: { schema: unknown } + [key: number]: { schema: unknown } | unknown } @@ -237,6 +243,15 @@ export interface paths extends PathRegistry { } } } + '/v1/chains/{chainId}/safes/{safe_address}/views/transaction-confirmation': { + post: operations['get_transaction_confirmation_view'] + parameters: { + path: { + chainId: string + safe_address: string + } + } + } '/v1/chains/{chainId}/owners/{address}/safes': { get: operations['get_owned_safes'] parameters: { @@ -738,6 +753,21 @@ export interface operations { 422: unknown } } + get_transaction_confirmation_view: { + parameters: { + path: { + /** A unique value identifying this chain. */ + chainId: string + safe_address: string + } + body: DecodedDataRequest + } + responses: { + 200: { + schema: BaselineConfirmationView | CowSwapConfirmationView + } + } + } get_owned_safes: { parameters: { path: { diff --git a/src/types/decoded-data.ts b/src/types/decoded-data.ts index 1ebe99d4..739cb0bf 100644 --- a/src/types/decoded-data.ts +++ b/src/types/decoded-data.ts @@ -1,3 +1,5 @@ +import type { SwapOrder } from './transactions' + export type DecodedDataRequest = { data: string to?: string @@ -30,3 +32,10 @@ export type DecodedDataResponse = { method: string parameters: DecodedDataParameter[] } + +export type BaselineConfirmationView = { + type: 'GENERIC' +} & DecodedDataResponse + +export type CowSwapConfirmationView = { type: 'COW_SWAP_ORDER' } & DecodedDataResponse & + Omit diff --git a/src/types/transactions.ts b/src/types/transactions.ts index d0c87e57..b2b1beed 100644 --- a/src/types/transactions.ts +++ b/src/types/transactions.ts @@ -260,7 +260,7 @@ export type SwapOrder = { uid: string status: OrderStatuses kind: OrderKind - class: OrderClass + orderClass: OrderClass /** @description The timestamp when the order expires */ validUntil: number /** @description The sell token raw amount (no decimals) */ diff --git a/tests/endpoint.test.ts b/tests/endpoint.test.ts index fc029231..3b9b2a52 100644 --- a/tests/endpoint.test.ts +++ b/tests/endpoint.test.ts @@ -118,6 +118,22 @@ describe('getEndpoint', () => { ) }) + 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', { + path: { chainId: '4', safe_address: '0x123' }, + body: { data: '0x456' }, + }), + ).resolves.toEqual({ success: true }) + + expect(fetchData).toHaveBeenCalledWith( + 'https://test.test/v1/chains/4/safes/0x123/views/transaction-confirmation', + 'POST', + { data: '0x456' }, + undefined, + ) + }) + it('should accept PUT request with body', async () => { const body = { emailAddress: 'test@test.com',