Skip to content

Commit a0cb558

Browse files
authored
Breaking: set the base URL for entire API (#68)
* Breaking: set the base URL for entire API * Update the readme * Add comment block language * Add usage policy
1 parent e86f9bd commit a0cb558

13 files changed

+124
-57
lines changed

README.md

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,46 @@
22

33
[![npm](https://img.shields.io/npm/v/@gnosis.pm/safe-react-gateway-sdk?label=%40gnosis.pm%2Fsafe-react-gateway-sdk)](https://www.npmjs.com/package/@gnosis.pm/safe-react-gateway-sdk)
44

5-
A TypeScript SDK for the [Safe Gateway](https://github.com/gnosis/safe-client-gateway)
5+
A TypeScript SDK for the [Safe Client Gateway](https://github.com/gnosis/safe-client-gateway)
66

7-
## Links
7+
📖 [API reference](https://gnosis.github.io/safe-react-gateway-sdk/modules.html#getBalances)
88

9-
- [Gateway API docs](https://gnosis.github.io/safe-client-gateway/docs/routes/index.html)
10-
- [SDK typedoc](https://gnosis.github.io/safe-react-gateway-sdk/modules.html#getBalances)
9+
## Usage policy
10+
11+
NB: Safe Client Gateway isn't meant for public use.
12+
Please _do not_ use this SDK if you're building, e.g., a Safe App.
13+
14+
## Using the SDK
15+
16+
Install:
17+
18+
```shell
19+
yarn add @gnosis.pm/safe-react-gateway-sdk
20+
```
21+
22+
Import:
23+
24+
```ts
25+
import { getChainsConfig, type ChainListResponse } from '@gnosis.pm/safe-react-gateway-sdk'
26+
```
27+
28+
Use:
29+
30+
```ts
31+
const chains = await getChainsConfig()
32+
```
33+
34+
The SDK needs no initialization unless you want to override the base URL, which defaults to https://safe-client.gnosis.io.
35+
You can set an alternative base URL like so:
36+
37+
```ts
38+
import { setBaseUrl } from '@gnosis.pm/safe-react-gateway-sdk'
39+
40+
// Switch the SDK to dev mode
41+
setBaseUrl('https://safe-client.staging.gnosisdev.com')
42+
```
43+
44+
The full SDK reference can be found [here](https://gnosis.github.io/safe-react-gateway-sdk/modules.html#getBalances).
1145

1246
## Adding an endpoint
1347

@@ -26,16 +60,21 @@ To add a new endpoint, follow the pattern set by the existing endpoints.
2660

2761
This command will run before every commit:
2862

29-
```
63+
```shell
3064
yarn eslint:fix
3165
```
3266

3367
## Tests
3468

3569
To run the unit and e2e tests locally:
3670

37-
```
71+
```shell
3872
yarn test
3973
```
4074

4175
N.B.: the e2e tests make actual API calls on staging.
76+
77+
78+
## Gateway API docs
79+
80+
The TypeScript types in this SDK are based on [Rust types](https://gnosis.github.io/safe-client-gateway/docs/routes/index.html) from the Gateway API.

e2e/get-chains-config.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
import { getChainsConfig, getChainConfig } from '../src'
1+
import { getChainsConfig, getChainConfig, setBaseUrl } from '../src'
22
import config from './config'
33

44
const mainnetChainId = '1'
55
const rinkebyChainId = '4'
66
const polygonChainId = '137'
77

88
describe('getChainsConfig & getChainConfig tests', () => {
9+
beforeAll(() => {
10+
setBaseUrl(config.baseUrl)
11+
})
12+
913
describe('getChainsConfig tests', () => {
1014
it('Returns all chains config', async () => {
11-
const chainConfig = await getChainsConfig(config.baseUrl)
15+
const chainConfig = await getChainsConfig()
1216

1317
expect(chainConfig.results).toBe
1418
expect(chainConfig.results).toBeDefined()
@@ -29,7 +33,7 @@ describe('getChainsConfig & getChainConfig tests', () => {
2933

3034
describe('getChainConfig/{chainId} tests', () => {
3135
it('Returns Mainnet config', async () => {
32-
const mainnetConfig = await getChainConfig(config.baseUrl, mainnetChainId)
36+
const mainnetConfig = await getChainConfig(mainnetChainId)
3337

3438
expect(mainnetConfig).toBeDefined()
3539
expect(mainnetConfig.chainId).toBe(mainnetChainId)
@@ -52,7 +56,7 @@ describe('getChainsConfig & getChainConfig tests', () => {
5256
})
5357

5458
it('Returns Rinkeby config', async () => {
55-
const rinkebyConfig = await getChainConfig(config.baseUrl, rinkebyChainId)
59+
const rinkebyConfig = await getChainConfig(rinkebyChainId)
5660

5761
expect(rinkebyConfig).toBeDefined()
5862
expect(rinkebyConfig.chainId).toBe(rinkebyChainId)
@@ -70,7 +74,7 @@ describe('getChainsConfig & getChainConfig tests', () => {
7074
})
7175

7276
it('Returns Polygon config', async () => {
73-
const polygonConfig = await getChainConfig(config.baseUrl, polygonChainId)
77+
const polygonConfig = await getChainConfig(polygonChainId)
7478

7579
expect(polygonConfig).toBeDefined()
7680
expect(polygonConfig.chainId).toBe(polygonChainId)

e2e/get-decoded-data.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import { getDecodedData } from '../src'
1+
import { getDecodedData, setBaseUrl } from '../src'
22
import config from './config'
33

44
describe('getDecodedData tests', () => {
5+
beforeAll(() => {
6+
setBaseUrl(config.baseUrl)
7+
})
8+
59
it('should post getDecodedData', async () => {
610
const result = await getDecodedData(
7-
config.baseUrl,
811
'4',
912
'0x095ea7b3000000000000000000000000ae9844f89d98c150f5e61bfc676d68b4921559900000000000000000000000000000000000000000000000000001c6bf52634000',
1013
)

e2e/get-master-copy.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import { getMasterCopies } from '../src'
1+
import { getMasterCopies, setBaseUrl } from '../src'
22
import config from './config'
33

44
describe('get mastercopy tests', () => {
5+
beforeAll(() => {
6+
setBaseUrl(config.baseUrl)
7+
})
8+
59
it('should get master copy response', async () => {
6-
const masterCopies = await getMasterCopies(config.baseUrl, '4')
10+
const masterCopies = await getMasterCopies('4')
711

812
expect(Array.isArray(masterCopies)).toBe(true)
913

e2e/get-owned-safes.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
import { getOwnedSafes } from '../src'
1+
import { getOwnedSafes, setBaseUrl } from '../src'
22
import config from './config'
33

44
describe('getOwnedSafes tests', () => {
5+
beforeAll(() => {
6+
setBaseUrl(config.baseUrl)
7+
})
8+
59
it('should get owned safes on rinkeby', async () => {
6-
const data = await getOwnedSafes(config.baseUrl, '4', '0x661E1CF4aAAf6a95C89EA8c81D120E6c62adDFf9')
10+
const data = await getOwnedSafes('4', '0x661E1CF4aAAf6a95C89EA8c81D120E6c62adDFf9')
711

812
expect(data.safes).toContain('0x9B5dc27B104356516B05b02F6166a54F6D74e40B')
913
expect(data.safes).toContain('0xb3b83bf204C458B461de9B0CD2739DB152b4fa5A')
1014
})
1115

1216
it('should return an empty array if no owned safes', async () => {
13-
const data = await getOwnedSafes(config.baseUrl, '1', '0x661E1CF4aAAf6a95C89EA8c81D120E6c62adDFf9')
17+
const data = await getOwnedSafes('1', '0x661E1CF4aAAf6a95C89EA8c81D120E6c62adDFf9')
1418
expect(data).toEqual({ safes: [] })
1519
})
1620

1721
it('should throw for bad addresses', async () => {
18-
const req = getOwnedSafes(config.baseUrl, '4', '0x661E1CF4aAAf6a95C89EA8c81D120E6c62adDfF9')
22+
const req = getOwnedSafes('4', '0x661E1CF4aAAf6a95C89EA8c81D120E6c62adDfF9')
1923
await expect(req).rejects.toThrow(/Checksum address validation failed/)
2024
})
2125
})

e2e/get-safe-apps.test.ts

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

44
const rinkebyChainId = '4'
55

66
describe('getSafeApps tests', () => {
7+
beforeAll(() => {
8+
setBaseUrl(config.baseUrl)
9+
})
10+
711
it('Returns Safe Apps List', async () => {
8-
const safeAppsList = await getSafeApps(config.baseUrl, rinkebyChainId)
12+
const safeAppsList = await getSafeApps(rinkebyChainId)
913

1014
expect(safeAppsList).toBeDefined()
1115
expect(Array.isArray(safeAppsList)).toBe(true)

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import { postSafeGasEstimation } from '../src'
1+
import { postSafeGasEstimation, setBaseUrl } from '../src'
22
import config from './config'
33

44
describe('postSafeGasEstimation tests', () => {
5+
beforeAll(() => {
6+
setBaseUrl(config.baseUrl)
7+
})
8+
59
it('should post a safe gas estimation', async () => {
6-
const result = await postSafeGasEstimation(config.baseUrl, '4', '0x4f9BD57BCC68Bf7770429F137922B3afD23d83E7', {
10+
const result = await postSafeGasEstimation('4', '0x4f9BD57BCC68Bf7770429F137922B3afD23d83E7', {
711
to: '0x4f9BD57BCC68Bf7770429F137922B3afD23d83E7',
812
value: '1',
913
data: '0x',

e2e/propose-transaction.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { proposeTransaction } from '../src'
1+
import { proposeTransaction, setBaseUrl } from '../src'
22
import config from './config'
33

44
describe('proposeTransaction tests', () => {
5+
beforeAll(() => {
6+
setBaseUrl(config.baseUrl)
7+
})
8+
59
// Skipping this test, see https://github.com/gnosis/safe-client-gateway/issues/745
610
it('should propose a transaction and fail', async () => {
7-
const req = proposeTransaction(config.baseUrl, '4', '0x4f9BD57BCC68Bf7770429F137922B3afD23d83E7', {
11+
const req = proposeTransaction('4', '0x4f9BD57BCC68Bf7770429F137922B3afD23d83E7', {
812
to: '0x49d4450977E2c95362C13D3a31a09311E0Ea26A6',
913
value: '0',
1014
data: '0xe8dde2320000000000000000000000000000000000000000000000000000000000000000',

e2e/safe-collectibles-list.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { getCollectibles } from '../src'
1+
import { getCollectibles, setBaseUrl } from '../src'
22
import config from './config'
33

44
describe('getCollectibles tests', () => {
5+
beforeAll(() => {
6+
setBaseUrl(config.baseUrl)
7+
})
8+
59
it('should fetch collectibles', async () => {
610
const address = '0xb3b83bf204C458B461de9B0CD2739DB152b4fa5A'
7-
const data = await getCollectibles(config.baseUrl, '4', address)
11+
const data = await getCollectibles('4', address)
812

913
expect(data.length).toBeGreaterThanOrEqual(1)
1014
expect(typeof data[1].address).toBe('string')

e2e/safes-read.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { getSafeInfo } from '../src'
1+
import { getSafeInfo, setBaseUrl } from '../src'
22
import config from './config'
33

44
describe('getSafeInfo tests', () => {
5+
beforeAll(() => {
6+
setBaseUrl(config.baseUrl)
7+
})
8+
59
it('should get safe info on rinkeby', async () => {
610
const address = '0x9B5dc27B104356516B05b02F6166a54F6D74e40B'
7-
const data = await getSafeInfo(config.baseUrl, '4', address)
11+
const data = await getSafeInfo('4', address)
812

913
expect(data.address.value).toBe(address)
1014
expect(data.chainId).toBe('4')

0 commit comments

Comments
 (0)