Skip to content

Commit c84f332

Browse files
authored
Added Safe Apps List endpoint (#41)
* Added Safe Apps List endpoint and fixed e2e tests * Added new 2.6.0 version
1 parent a01ad0b commit c84f332

9 files changed

+81
-6
lines changed

e2e/get-chains-config.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('getChainsConfig & getChainConfig tests', () => {
3333

3434
expect(mainnetConfig).toBeDefined()
3535
expect(mainnetConfig.chainId).toBe(mainnetChainId)
36-
expect(mainnetConfig.chainName).toBe('Mainnet')
36+
expect(mainnetConfig.chainName).toBe('Ethereum')
3737
expect(mainnetConfig.shortName).toBe('eth')
3838
expect(mainnetConfig.l2).toBe(false)
3939

e2e/get-owned-safes.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getOwnedSafes } from '../src'
22
import config from './config'
33

4-
describe('getOwnedSages tests', () => {
4+
describe('getOwnedSafes tests', () => {
55
it('should get owned safes on rinkeby', async () => {
66
const data = await getOwnedSafes(config.baseUrl, '4', '0x661E1CF4aAAf6a95C89EA8c81D120E6c62adDFf9')
77

@@ -18,6 +18,6 @@ describe('getOwnedSages tests', () => {
1818

1919
it('should throw for bad addresses', async () => {
2020
const req = getOwnedSafes(config.baseUrl, '4', '0x661E1CF4aAAf6a95C89EA8c81D120E6c62adDfF9')
21-
await expect(req).rejects.toThrow('1: Checksum address validation failed')
21+
await expect(req).rejects.toThrow(/Checksum address validation failed/)
2222
})
2323
})

e2e/get-safe-apps.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { getSafeApps } from '../src'
2+
import config from './config'
3+
4+
const rinkebyChainId = '4'
5+
6+
describe('getSafeApps tests', () => {
7+
it('Returns Safe Apps List', async () => {
8+
const safeAppsList = await getSafeApps(config.baseUrl, rinkebyChainId)
9+
10+
expect(safeAppsList).toBeDefined()
11+
expect(Array.isArray(safeAppsList)).toBe(true)
12+
13+
// safe app WalletConnect should be present
14+
const walletConnectSafeApp = safeAppsList.find((safeApp) => safeApp.name === 'WalletConnect')
15+
expect(walletConnectSafeApp).toBeDefined()
16+
17+
// safe app Transaction Builder should be present
18+
const transactionBuilder = safeAppsList.find((safeApp) => safeApp.name === 'Transaction Builder')
19+
expect(transactionBuilder).toBeDefined()
20+
21+
// safe app Drain Safe should be present
22+
const drainSafeApp = safeAppsList.find((safeApp) => safeApp.name === 'Drain Account')
23+
expect(drainSafeApp).toBeDefined()
24+
})
25+
})

e2e/post-safe-gas-estimation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('postSafeGasEstimation tests', () => {
1010
operation: 0,
1111
})
1212

13-
expect(result.safeTxGas).toBe('43663')
13+
expect(result.safeTxGas).toBe('45006')
1414
// Nonce should match any positive integer number over 0
1515
expect(result.latestNonce).toBeGreaterThanOrEqual(0)
1616
})

e2e/propose-transaction.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { proposeTransaction } from '../src'
22
import config from './config'
33

44
describe('proposeTransaction tests', () => {
5-
it('should propose a transaction and fail', async () => {
5+
// Skipping this test, see https://github.com/gnosis/safe-client-gateway/issues/745
6+
it.skip('should propose a transaction and fail', async () => {
67
const req = proposeTransaction(config.baseUrl, '4', '0x4f9BD57BCC68Bf7770429F137922B3afD23d83E7', {
78
to: '0x49d4450977E2c95362C13D3a31a09311E0Ea26A6',
89
value: '0',

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": "2.5.8",
3+
"version": "2.6.0",
44
"main": "dist/index.min.js",
55
"types": "dist/index.d.ts",
66
"files": [

src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { operations } from './types/api'
33
import { SafeTransactionEstimation, TransactionDetails, TransactionListPage } from './types/transactions'
44
import { FiatCurrencies, OwnedSafes, SafeBalanceResponse, SafeCollectibleResponse, SafeInfo } from './types/common'
55
import { ChainListResponse, ChainInfo } from './types/chains'
6+
import { SafeAppsResponse } from './types/safe-apps'
7+
export * from './types/safe-apps'
68
export * from './types/transactions'
79
export * from './types/chains'
810
export * from './types/common'
@@ -156,4 +158,13 @@ export function getChainConfig(baseUrl: string, chainId: string): Promise<ChainI
156158
})
157159
}
158160

161+
/**
162+
* Returns Safe Apps List
163+
*/
164+
export function getSafeApps(baseUrl: string, chainId: string): Promise<SafeAppsResponse> {
165+
return callEndpoint(baseUrl, '/chains/{chainId}/safe-apps', {
166+
path: { chainId: chainId },
167+
})
168+
}
169+
159170
/* eslint-enable @typescript-eslint/explicit-module-boundary-types */

src/types/api.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
TransactionListPage,
88
} from './transactions'
99
import { ChainListResponse, ChainInfo } from './chains'
10+
import { SafeAppsResponse } from './safe-apps'
1011

1112
export interface paths {
1213
'/chains/{chainId}/safes/{address}/': {
@@ -117,6 +118,14 @@ export interface paths {
117118
}
118119
}
119120
}
121+
'/chains/{chainId}/safe-apps': {
122+
get: operations['safe_apps_read']
123+
parameters: {
124+
path: {
125+
chainId: string
126+
}
127+
}
128+
}
120129
}
121130

122131
export interface operations {
@@ -324,4 +333,17 @@ export interface operations {
324333
}
325334
}
326335
}
336+
safe_apps_read: {
337+
parameters: {
338+
path: {
339+
/** A unique value identifying this chain. */
340+
chainId: string
341+
}
342+
}
343+
responses: {
344+
200: {
345+
schema: SafeAppsResponse
346+
}
347+
}
348+
}
327349
}

src/types/safe-apps.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export type SafeAppProvider = {
2+
url: string
3+
name: string
4+
}
5+
6+
export type SafeAppData = {
7+
id: number
8+
url: string
9+
name: string
10+
iconUrl: string
11+
description: string
12+
chainIds: string[]
13+
provider?: SafeAppProvider
14+
}
15+
16+
export type SafeAppsResponse = [SafeAppData]

0 commit comments

Comments
 (0)