Skip to content

Commit 5b7a487

Browse files
authored
feat: add tx filter endpoints (#73)
* feat: add tx filter endpoints * fix: add `rawUrl` * fix: add missing query param * fix: query types * fix: add `executed` param * fix: bump version
1 parent c06ff3a commit 5b7a487

File tree

6 files changed

+218
-9
lines changed

6 files changed

+218
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gnosis.pm/safe-react-gateway-sdk",
3-
"version": "3.0.1",
3+
"version": "3.1.1",
44
"main": "dist/index.min.js",
55
"types": "dist/index.d.ts",
66
"files": [

src/index.ts

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import { callEndpoint } from './endpoint'
22
import { operations } from './types/api'
33
import { SafeTransactionEstimation, TransactionDetails, TransactionListPage } from './types/transactions'
4-
import { FiatCurrencies, OwnedSafes, SafeBalanceResponse, SafeCollectibleResponse, SafeInfo } from './types/common'
4+
import {
5+
FiatCurrencies,
6+
OwnedSafes,
7+
SafeBalanceResponse,
8+
SafeCollectibleResponse,
9+
SafeIncomingTransfersResponse,
10+
SafeInfo,
11+
SafeModuleTransactionsResponse,
12+
SafeMultisigTransactionsResponse,
13+
} from './types/common'
514
import { ChainListResponse, ChainInfo } from './types/chains'
615
import { SafeAppsResponse } from './types/safe-apps'
716
import { MasterCopyReponse } from './types/master-copies'
@@ -33,6 +42,66 @@ export function getSafeInfo(chainId: string, address: string): Promise<SafeInfo>
3342
return callEndpoint(baseUrl, '/v1/chains/{chainId}/safes/{address}', { path: { chainId, address } })
3443
}
3544

45+
/**
46+
* Get filterable list of incoming transactions
47+
*/
48+
export function getIncomingTransfers(
49+
chainId: string,
50+
address: string,
51+
query?: operations['incoming_transfers']['parameters']['query'],
52+
pageUrl?: string,
53+
): Promise<SafeIncomingTransfersResponse> {
54+
return callEndpoint(
55+
baseUrl,
56+
'/v1/chains/{chainId}/safes/{address}/incoming-transfers/',
57+
{
58+
path: { chainId, address },
59+
query,
60+
},
61+
pageUrl,
62+
)
63+
}
64+
65+
/**
66+
* Get filterable list of module transactions
67+
*/
68+
export function getModuleTransactions(
69+
chainId: string,
70+
address: string,
71+
query?: operations['module_transactions']['parameters']['query'],
72+
pageUrl?: string,
73+
): Promise<SafeModuleTransactionsResponse> {
74+
return callEndpoint(
75+
baseUrl,
76+
'/v1/chains/{chainId}/safes/{address}/module-transactions/',
77+
{
78+
path: { chainId, address },
79+
query,
80+
},
81+
pageUrl,
82+
)
83+
}
84+
85+
/**
86+
* Get filterable list of multisig transactions
87+
*/
88+
export function getMultisigTransactions(
89+
chainId: string,
90+
address: string,
91+
query?: operations['multisig_transactions']['parameters']['query'],
92+
pageUrl?: string,
93+
): Promise<SafeMultisigTransactionsResponse> {
94+
return callEndpoint(
95+
baseUrl,
96+
'/v1/chains/{chainId}/safes/{address}/multisig-transactions/',
97+
{
98+
path: { chainId, address },
99+
query,
100+
},
101+
pageUrl,
102+
)
103+
}
104+
36105
/**
37106
* Get the total balance and all assets stored in a Safe
38107
*/

src/types/api.ts

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import { FiatCurrencies, OwnedSafes, SafeBalanceResponse, SafeCollectibleResponse, SafeInfo } from './common'
1+
import {
2+
FiatCurrencies,
3+
OwnedSafes,
4+
SafeBalanceResponse,
5+
SafeCollectibleResponse,
6+
SafeIncomingTransfersResponse,
7+
SafeInfo,
8+
SafeModuleTransactionsResponse,
9+
SafeMultisigTransactionsResponse,
10+
} from './common'
211
import {
312
MultisigTransactionRequest,
413
TransactionDetails,
@@ -32,6 +41,36 @@ export interface paths {
3241
}
3342
}
3443
}
44+
'/v1/chains/{chainId}/safes/{address}/incoming-transfers/': {
45+
get: operations['incoming_transfers']
46+
parameters: {
47+
path: {
48+
chainId: string
49+
address: string
50+
currency: string
51+
}
52+
}
53+
}
54+
'/v1/chains/{chainId}/safes/{address}/module-transactions/': {
55+
get: operations['module_transactions']
56+
parameters: {
57+
path: {
58+
chainId: string
59+
address: string
60+
currency: string
61+
}
62+
}
63+
}
64+
'/v1/chains/{chainId}/safes/{address}/multisig-transactions/': {
65+
get: operations['multisig_transactions']
66+
parameters: {
67+
path: {
68+
chainId: string
69+
address: string
70+
currency: string
71+
}
72+
}
73+
}
3574
'/v1/balances/supported-fiat-codes': {
3675
get: operations['get_supported_fiat']
3776
parameters: null
@@ -193,6 +232,79 @@ export interface operations {
193232
422: unknown
194233
}
195234
}
235+
/** Get filterable incoming transfers */
236+
incoming_transfers: {
237+
parameters: {
238+
path: {
239+
chainId: string
240+
address: string
241+
}
242+
query?: {
243+
execution_date__gte?: string
244+
execution_date__lte?: string
245+
to?: string
246+
token_address?: string
247+
value?: string
248+
}
249+
}
250+
responses: {
251+
200: {
252+
schema: SafeIncomingTransfersResponse
253+
}
254+
/** Safe not found */
255+
404: unknown
256+
/** Safe address checksum not valid */
257+
422: unknown
258+
}
259+
}
260+
/** Get filterable module transactions */
261+
module_transactions: {
262+
parameters: {
263+
path: {
264+
chainId: string
265+
address: string
266+
}
267+
query?: {
268+
module?: string
269+
to?: string
270+
}
271+
}
272+
responses: {
273+
200: {
274+
schema: SafeModuleTransactionsResponse
275+
}
276+
/** Safe not found */
277+
404: unknown
278+
/** Safe address checksum not valid */
279+
422: unknown
280+
}
281+
}
282+
/** Get filterable multisig transactions */
283+
multisig_transactions: {
284+
parameters: {
285+
path: {
286+
chainId: string
287+
address: string
288+
}
289+
query?: {
290+
execution_date__gte?: string
291+
execution_date__lte?: string
292+
to?: string
293+
value?: string
294+
nonce?: string
295+
executed?: string
296+
}
297+
}
298+
responses: {
299+
200: {
300+
schema: SafeMultisigTransactionsResponse
301+
}
302+
/** Safe not found */
303+
404: unknown
304+
/** Safe address checksum not valid */
305+
422: unknown
306+
}
307+
}
196308
get_supported_fiat: {
197309
parameters: null
198310
responses: {

src/types/chains.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Page } from './transactions'
2+
13
export enum RPC_AUTHENTICATION {
24
API_KEY_PATH = 'API_KEY_PATH',
35
NO_AUTHENTICATION = 'NO_AUTHENTICATION',
@@ -82,8 +84,4 @@ export type ChainInfo = {
8284
features: FEATURES[]
8385
}
8486

85-
export type ChainListResponse = {
86-
next: string | null
87-
previous: string | null
88-
results: ChainInfo[]
89-
}
87+
export type ChainListResponse = Page<ChainInfo>

src/types/common.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { IncomingTransfer, ModuleTransaction, MultisigTransaction, Page } from '..'
2+
13
export type AddressEx = {
24
value: string
35
name: string | null
@@ -49,6 +51,12 @@ export type SafeBalanceResponse = {
4951
}>
5052
}
5153

54+
export type SafeIncomingTransfersResponse = Page<IncomingTransfer>
55+
56+
export type SafeModuleTransactionsResponse = Page<ModuleTransaction>
57+
58+
export type SafeMultisigTransactionsResponse = Page<MultisigTransaction>
59+
5260
export type SafeCollectibleResponse = {
5361
address: string
5462
tokenName: string

src/types/transactions.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,28 @@ export type Transaction = {
228228
type: 'TRANSACTION'
229229
}
230230

231+
// WIP types:
232+
233+
export type IncomingTransfer = Omit<Transaction, 'transaction'> & {
234+
transaction: Omit<TransactionSummary, 'txInfo' | 'executionInfo'> & {
235+
txInfo: Omit<Transfer, 'direction'> & { direction: TransferDirection.INCOMING }
236+
}
237+
}
238+
239+
export type ModuleTransaction = Omit<Transaction, 'transaction'> & {
240+
transaction: Omit<TransactionSummary, 'txInfo' | 'executionInfo'> & {
241+
txInfo: Transfer
242+
executionInfo?: ModuleExecutionInfo
243+
}
244+
}
245+
246+
export type MultisigTransaction = Omit<Transaction, 'transaction'> & {
247+
transaction: Omit<TransactionSummary, 'txInfo' | 'executionInfo'> & {
248+
txInfo: Omit<Transfer, 'direction'> & { direction: TransferDirection.OUTGOING }
249+
executionInfo?: MultisigExecutionInfo
250+
}
251+
}
252+
231253
export type DateLabel = {
232254
timestamp: number
233255
type: 'DATE_LABEL'
@@ -253,7 +275,7 @@ export type ConflictHeader = {
253275

254276
export type TransactionListItem = Transaction | Label | ConflictHeader
255277

256-
type Page<T> = {
278+
export type Page<T> = {
257279
next?: string
258280
previous?: string
259281
results: Array<T>

0 commit comments

Comments
 (0)