Skip to content

Commit

Permalink
feat: add confirmation view endpoint types (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
compojoom authored Apr 22, 2024
1 parent 60cd289 commit 6ca9f7d
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DecodedDataResponse> {
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
*/
Expand Down
32 changes: 31 additions & 1 deletion src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -54,6 +59,7 @@ interface BodyParams extends Params {

interface Responses {
200: { schema: unknown }

[key: number]: { schema: unknown } | unknown
}

Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down
9 changes: 9 additions & 0 deletions src/types/decoded-data.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { SwapOrder } from './transactions'

export type DecodedDataRequest = {
data: string
to?: string
Expand Down Expand Up @@ -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<SwapOrder, 'type' | 'humanDescription' | 'richDecodedInfo'>
2 changes: 1 addition & 1 deletion src/types/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down
16 changes: 16 additions & 0 deletions tests/endpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
Expand Down

0 comments on commit 6ca9f7d

Please sign in to comment.