Skip to content

Commit 6837792

Browse files
author
Daniel Sanchez
authored
[Unified gateway] - Use gateway v3 types (#3)
* Create TransactionInfoType enum * Add chainId for endpoints in SDK * Add transaction details types and function * Set v2.0.0 * Bump dependencies * Add type to transaction information
1 parent 58aa02a commit 6837792

File tree

5 files changed

+435
-310
lines changed

5 files changed

+435
-310
lines changed

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gnosis.pm/safe-react-gateway-sdk",
3-
"version": "1.2.1",
3+
"version": "2.0.0",
44
"main": "dist/index.min.js",
55
"types": "dist/index.d.ts",
66
"files": [
@@ -13,23 +13,23 @@
1313
"unfetch": "^4.2.0"
1414
},
1515
"devDependencies": {
16-
"@babel/core": "^7.14.6",
17-
"@babel/preset-env": "^7.14.7",
18-
"@babel/preset-typescript": "^7.14.5",
19-
"@typescript-eslint/eslint-plugin": "^4.28.2",
20-
"@typescript-eslint/parser": "^4.28.2",
16+
"@babel/core": "^7.15.0",
17+
"@babel/preset-env": "^7.15.0",
18+
"@babel/preset-typescript": "^7.15.0",
19+
"@typescript-eslint/eslint-plugin": "^4.29.0",
20+
"@typescript-eslint/parser": "^4.29.0",
2121
"babel-jest": "^27.0.6",
2222
"copy-webpack-plugin": "^9.0.1",
23-
"eslint": "^7.30.0",
23+
"eslint": "^7.32.0",
2424
"eslint-config-prettier": "^8.3.0",
25-
"eslint-plugin-import": "^2.23.4",
25+
"eslint-plugin-import": "^2.24.0",
2626
"eslint-plugin-prettier": "^3.4.0",
2727
"husky": "^7.0.1",
2828
"jest": "^27.0.6",
2929
"prettier": "^2.3.2",
30-
"ts-loader": "^9.2.3",
30+
"ts-loader": "^9.2.5",
3131
"typescript": "^4.3.5",
32-
"webpack": "^5.43.0",
32+
"webpack": "^5.49.0",
3333
"webpack-cli": "^4.7.2"
3434
},
3535
"scripts": {

src/index.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@ export type GatewayDefinitions = definitions
66

77
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
88

9-
export function getSafeInfo(baseUrl: string, address: string) {
10-
return callEndpoint(baseUrl, '/safes/{address}/', { path: { address } })
9+
export function getSafeInfo(baseUrl: string, chainId: string, address: string) {
10+
return callEndpoint(baseUrl, '/chains/{chainId}/safes/{address}/', { path: { chainId, address } })
1111
}
1212

1313
export function getBalances(
1414
baseUrl: string,
15+
chainId: string,
1516
address: string,
1617
currency = 'usd',
1718
query: operations['safes_balances_list']['parameters']['query'] = {},
1819
) {
19-
return callEndpoint(baseUrl, '/safes/{address}/balances/{currency}/', { path: { address, currency }, query })
20+
return callEndpoint(baseUrl, '/chains/{chainId}/safes/{address}/balances/{currency}/', {
21+
path: { chainId, address, currency },
22+
query,
23+
})
2024
}
2125

2226
export function getFiatCurrencies(baseUrl: string) {
@@ -25,36 +29,47 @@ export function getFiatCurrencies(baseUrl: string) {
2529

2630
export function getCollectibles(
2731
baseUrl: string,
32+
chainId: string,
2833
address: string,
2934
query: operations['safes_collectibles_list']['parameters']['query'] = {},
3035
) {
31-
return callEndpoint(baseUrl, '/safes/{address}/collectibles/', { path: { address }, query })
36+
return callEndpoint(baseUrl, '/chains/{chainId}/safes/{address}/collectibles/', { path: { chainId, address }, query })
3237
}
3338

34-
export function getTransactionHistory(baseUrl: string, address: string, pageUrl?: string) {
39+
export function getTransactionHistory(baseUrl: string, chainId: string, address: string, pageUrl?: string) {
3540
return callEndpoint(
3641
baseUrl,
37-
'/safes/{safe_address}/transactions/history',
38-
{ path: { safe_address: address }, query: {} },
42+
'/chains/{chainId}/safes/{safe_address}/transactions/history',
43+
{ path: { chainId, safe_address: address }, query: {} },
3944
pageUrl,
4045
)
4146
}
4247

43-
export function getTransactionQueue(baseUrl: string, address: string, pageUrl?: string) {
48+
export function getTransactionQueue(baseUrl: string, chainId: string, address: string, pageUrl?: string) {
4449
return callEndpoint(
4550
baseUrl,
46-
'/safes/{safe_address}/transactions/queued',
47-
{ path: { safe_address: address }, query: {} },
51+
'/chains/{chainId}/safes/{safe_address}/transactions/queued',
52+
{ path: { chainId, safe_address: address }, query: {} },
4853
pageUrl,
4954
)
5055
}
5156

57+
export function getTransactionDetails(baseUrl: string, chainId: string, transactionId: string) {
58+
return callEndpoint(baseUrl, '/chains/{chainId}/transactions/{transactionId}', {
59+
path: { chainId, transactionId },
60+
})
61+
}
62+
5263
export function postTransaction(
5364
baseUrl: string,
65+
chainId: string,
5466
address: string,
5567
body: operations['post_transaction']['parameters']['body'],
5668
) {
57-
return callEndpoint(baseUrl, '/transactions/{safe_address}/propose', { path: { safe_address: address }, body })
69+
return callEndpoint(baseUrl, '/chains/{chainId}/transactions/{safe_address}/propose', {
70+
path: { chainId, safe_address: address },
71+
body,
72+
})
5873
}
5974

6075
/* eslint-enable @typescript-eslint/explicit-module-boundary-types */

src/types/gateway.ts

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
import { TransactionListItem, MultisigTransactionRequest } from './transactions'
1+
import { TokenType, TransactionListItem, MultisigTransactionRequest, TransactionDetails } from './transactions'
22

33
export interface paths {
4-
'/safes/{address}/': {
4+
'/chains/{chainId}/safes/{address}/': {
55
/** Get status of the safe */
66
get: operations['safes_read']
77
parameters: {
88
path: {
9+
chainId: string
910
address: string
1011
}
1112
}
1213
}
13-
'/safes/{address}/balances/{currency}/': {
14+
'/chains/{chainId}/safes/{address}/balances/{currency}/': {
1415
get: operations['safes_balances_list']
1516
parameters: {
1617
path: {
18+
chainId: string
1719
address: string
1820
currency: string
1921
}
@@ -23,36 +25,49 @@ export interface paths {
2325
get: operations['get_supported_fiat']
2426
parameters: null
2527
}
26-
'/safes/{address}/collectibles/': {
28+
'/chains/{chainId}/safes/{address}/collectibles/': {
2729
/** Get collectibles (ERC721 tokens) and information about them */
2830
get: operations['safes_collectibles_list']
2931
parameters: {
3032
path: {
33+
chainId: string
3134
address: string
3235
}
3336
}
3437
}
35-
'/safes/{safe_address}/transactions/history': {
38+
'/chains/{chainId}/safes/{safe_address}/transactions/history': {
3639
get: operations['history_transactions']
3740
parameters: {
3841
path: {
42+
chainId: string
3943
safe_address: string
4044
}
4145
}
4246
}
43-
'/safes/{safe_address}/transactions/queued': {
47+
'/chains/{chainId}/safes/{safe_address}/transactions/queued': {
4448
get: operations['queued_transactions']
4549
parameters: {
4650
path: {
51+
chainId: string
4752
safe_address: string
4853
}
4954
}
5055
}
51-
'/transactions/{safe_address}/propose': {
56+
'/chains/{chainId}/transactions/{transactionId}': {
57+
get: operations['get_transactions']
58+
parameters: {
59+
path: {
60+
chainId: string
61+
transactionId: string
62+
}
63+
}
64+
}
65+
'/chains/{chainId}/transactions/{safe_address}/propose': {
5266
/** This is actually supposed to be POST but it breaks our type paradise */
5367
get: operations['post_transaction']
5468
parameters: {
5569
path: {
70+
chainId: string
5671
safe_address: string
5772
}
5873
}
@@ -87,7 +102,7 @@ export interface definitions {
87102
FiatCurrencies: string[]
88103

89104
TokenInfo: {
90-
type: 'ERC20' | 'ETHER' | 'NATIVE_TOKEN'
105+
type: TokenType
91106
address: string
92107
decimals: number
93108
symbol: string
@@ -119,13 +134,15 @@ export interface definitions {
119134

120135
TransactionListItem: TransactionListItem
121136
TransactionListPage: Page<TransactionListItem>
137+
TransactionDetails: TransactionDetails
122138
}
123139

124140
export interface operations {
125141
/** Get status of the safe */
126142
safes_read: {
127143
parameters: {
128144
path: {
145+
chainId: string
129146
address: string
130147
}
131148
}
@@ -146,6 +163,7 @@ export interface operations {
146163
safes_balances_list: {
147164
parameters: {
148165
path: {
166+
chainId: string
149167
address: string
150168
currency: string
151169
}
@@ -178,6 +196,7 @@ export interface operations {
178196
safes_collectibles_list: {
179197
parameters: {
180198
path: {
199+
chainId: string
181200
address: string
182201
}
183202
query: {
@@ -200,6 +219,7 @@ export interface operations {
200219
history_transactions: {
201220
parameters: {
202221
path: {
222+
chainId: string
203223
safe_address: string
204224
}
205225
query: {
@@ -216,6 +236,7 @@ export interface operations {
216236
queued_transactions: {
217237
parameters: {
218238
path: {
239+
chainId: string
219240
safe_address: string
220241
}
221242
query: {
@@ -229,9 +250,23 @@ export interface operations {
229250
}
230251
}
231252
}
253+
get_transactions: {
254+
parameters: {
255+
path: {
256+
chainId: string
257+
transactionId: string
258+
}
259+
}
260+
responses: {
261+
200: {
262+
schema: definitions['TransactionDetails']
263+
}
264+
}
265+
}
232266
post_transaction: {
233267
parameters: {
234268
path: {
269+
chainId: string
235270
safe_address: string
236271
}
237272
body: MultisigTransactionRequest

0 commit comments

Comments
 (0)