Skip to content

Commit

Permalink
[Unified gateway] - Use gateway v3 types (#3)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Daniel Sanchez authored Aug 10, 2021
1 parent 58aa02a commit 6837792
Show file tree
Hide file tree
Showing 5 changed files with 435 additions and 310 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gnosis.pm/safe-react-gateway-sdk",
"version": "1.2.1",
"version": "2.0.0",
"main": "dist/index.min.js",
"types": "dist/index.d.ts",
"files": [
Expand All @@ -13,23 +13,23 @@
"unfetch": "^4.2.0"
},
"devDependencies": {
"@babel/core": "^7.14.6",
"@babel/preset-env": "^7.14.7",
"@babel/preset-typescript": "^7.14.5",
"@typescript-eslint/eslint-plugin": "^4.28.2",
"@typescript-eslint/parser": "^4.28.2",
"@babel/core": "^7.15.0",
"@babel/preset-env": "^7.15.0",
"@babel/preset-typescript": "^7.15.0",
"@typescript-eslint/eslint-plugin": "^4.29.0",
"@typescript-eslint/parser": "^4.29.0",
"babel-jest": "^27.0.6",
"copy-webpack-plugin": "^9.0.1",
"eslint": "^7.30.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-import": "^2.24.0",
"eslint-plugin-prettier": "^3.4.0",
"husky": "^7.0.1",
"jest": "^27.0.6",
"prettier": "^2.3.2",
"ts-loader": "^9.2.3",
"ts-loader": "^9.2.5",
"typescript": "^4.3.5",
"webpack": "^5.43.0",
"webpack": "^5.49.0",
"webpack-cli": "^4.7.2"
},
"scripts": {
Expand Down
37 changes: 26 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ export type GatewayDefinitions = definitions

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

export function getSafeInfo(baseUrl: string, address: string) {
return callEndpoint(baseUrl, '/safes/{address}/', { path: { address } })
export function getSafeInfo(baseUrl: string, chainId: string, address: string) {
return callEndpoint(baseUrl, '/chains/{chainId}/safes/{address}/', { path: { chainId, address } })
}

export function getBalances(
baseUrl: string,
chainId: string,
address: string,
currency = 'usd',
query: operations['safes_balances_list']['parameters']['query'] = {},
) {
return callEndpoint(baseUrl, '/safes/{address}/balances/{currency}/', { path: { address, currency }, query })
return callEndpoint(baseUrl, '/chains/{chainId}/safes/{address}/balances/{currency}/', {
path: { chainId, address, currency },
query,
})
}

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

export function getCollectibles(
baseUrl: string,
chainId: string,
address: string,
query: operations['safes_collectibles_list']['parameters']['query'] = {},
) {
return callEndpoint(baseUrl, '/safes/{address}/collectibles/', { path: { address }, query })
return callEndpoint(baseUrl, '/chains/{chainId}/safes/{address}/collectibles/', { path: { chainId, address }, query })
}

export function getTransactionHistory(baseUrl: string, address: string, pageUrl?: string) {
export function getTransactionHistory(baseUrl: string, chainId: string, address: string, pageUrl?: string) {
return callEndpoint(
baseUrl,
'/safes/{safe_address}/transactions/history',
{ path: { safe_address: address }, query: {} },
'/chains/{chainId}/safes/{safe_address}/transactions/history',
{ path: { chainId, safe_address: address }, query: {} },
pageUrl,
)
}

export function getTransactionQueue(baseUrl: string, address: string, pageUrl?: string) {
export function getTransactionQueue(baseUrl: string, chainId: string, address: string, pageUrl?: string) {
return callEndpoint(
baseUrl,
'/safes/{safe_address}/transactions/queued',
{ path: { safe_address: address }, query: {} },
'/chains/{chainId}/safes/{safe_address}/transactions/queued',
{ path: { chainId, safe_address: address }, query: {} },
pageUrl,
)
}

export function getTransactionDetails(baseUrl: string, chainId: string, transactionId: string) {
return callEndpoint(baseUrl, '/chains/{chainId}/transactions/{transactionId}', {
path: { chainId, transactionId },
})
}

export function postTransaction(
baseUrl: string,
chainId: string,
address: string,
body: operations['post_transaction']['parameters']['body'],
) {
return callEndpoint(baseUrl, '/transactions/{safe_address}/propose', { path: { safe_address: address }, body })
return callEndpoint(baseUrl, '/chains/{chainId}/transactions/{safe_address}/propose', {
path: { chainId, safe_address: address },
body,
})
}

/* eslint-enable @typescript-eslint/explicit-module-boundary-types */
51 changes: 43 additions & 8 deletions src/types/gateway.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { TransactionListItem, MultisigTransactionRequest } from './transactions'
import { TokenType, TransactionListItem, MultisigTransactionRequest, TransactionDetails } from './transactions'

export interface paths {
'/safes/{address}/': {
'/chains/{chainId}/safes/{address}/': {
/** Get status of the safe */
get: operations['safes_read']
parameters: {
path: {
chainId: string
address: string
}
}
}
'/safes/{address}/balances/{currency}/': {
'/chains/{chainId}/safes/{address}/balances/{currency}/': {
get: operations['safes_balances_list']
parameters: {
path: {
chainId: string
address: string
currency: string
}
Expand All @@ -23,36 +25,49 @@ export interface paths {
get: operations['get_supported_fiat']
parameters: null
}
'/safes/{address}/collectibles/': {
'/chains/{chainId}/safes/{address}/collectibles/': {
/** Get collectibles (ERC721 tokens) and information about them */
get: operations['safes_collectibles_list']
parameters: {
path: {
chainId: string
address: string
}
}
}
'/safes/{safe_address}/transactions/history': {
'/chains/{chainId}/safes/{safe_address}/transactions/history': {
get: operations['history_transactions']
parameters: {
path: {
chainId: string
safe_address: string
}
}
}
'/safes/{safe_address}/transactions/queued': {
'/chains/{chainId}/safes/{safe_address}/transactions/queued': {
get: operations['queued_transactions']
parameters: {
path: {
chainId: string
safe_address: string
}
}
}
'/transactions/{safe_address}/propose': {
'/chains/{chainId}/transactions/{transactionId}': {
get: operations['get_transactions']
parameters: {
path: {
chainId: string
transactionId: string
}
}
}
'/chains/{chainId}/transactions/{safe_address}/propose': {
/** This is actually supposed to be POST but it breaks our type paradise */
get: operations['post_transaction']
parameters: {
path: {
chainId: string
safe_address: string
}
}
Expand Down Expand Up @@ -87,7 +102,7 @@ export interface definitions {
FiatCurrencies: string[]

TokenInfo: {
type: 'ERC20' | 'ETHER' | 'NATIVE_TOKEN'
type: TokenType
address: string
decimals: number
symbol: string
Expand Down Expand Up @@ -119,13 +134,15 @@ export interface definitions {

TransactionListItem: TransactionListItem
TransactionListPage: Page<TransactionListItem>
TransactionDetails: TransactionDetails
}

export interface operations {
/** Get status of the safe */
safes_read: {
parameters: {
path: {
chainId: string
address: string
}
}
Expand All @@ -146,6 +163,7 @@ export interface operations {
safes_balances_list: {
parameters: {
path: {
chainId: string
address: string
currency: string
}
Expand Down Expand Up @@ -178,6 +196,7 @@ export interface operations {
safes_collectibles_list: {
parameters: {
path: {
chainId: string
address: string
}
query: {
Expand All @@ -200,6 +219,7 @@ export interface operations {
history_transactions: {
parameters: {
path: {
chainId: string
safe_address: string
}
query: {
Expand All @@ -216,6 +236,7 @@ export interface operations {
queued_transactions: {
parameters: {
path: {
chainId: string
safe_address: string
}
query: {
Expand All @@ -229,9 +250,23 @@ export interface operations {
}
}
}
get_transactions: {
parameters: {
path: {
chainId: string
transactionId: string
}
}
responses: {
200: {
schema: definitions['TransactionDetails']
}
}
}
post_transaction: {
parameters: {
path: {
chainId: string
safe_address: string
}
body: MultisigTransactionRequest
Expand Down
Loading

0 comments on commit 6837792

Please sign in to comment.