Skip to content

Commit 14b436e

Browse files
author
katspaugh
committed
Accept baseUrl
1 parent 0db9370 commit 14b436e

File tree

4 files changed

+18
-30
lines changed

4 files changed

+18
-30
lines changed

src/config.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/endpoint.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import config from './config'
21
import { fetchJson, insertParams, stringifyQuery } from './utils'
32
import { paths } from './types/gateway'
43

@@ -10,15 +9,14 @@ interface Params {
109
}
1110

1211
export function callEndpoint<T extends keyof paths>(
13-
network: string,
12+
baseUrl: string,
1413
path: T,
1514
parameters?: paths[T]['get']['parameters'],
1615
rawUrl?: string,
1716
): Promise<paths[T]['get']['responses'][200]['schema']> {
1817
let url = rawUrl
1918
if (!url) {
2019
const params = parameters as Params
21-
const baseUrl = insertParams(config.baseUrl, { network: network.toLowerCase() })
2220
const pathname = insertParams(path, params?.path)
2321
const search = stringifyQuery(params?.query)
2422
url = `${baseUrl}${pathname}${search}`

src/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,43 @@ export type GatewayDefinitions = definitions
55

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

8-
export function getSafeInfo(network: string, address: string) {
9-
return callEndpoint(network, '/safes/{address}/', { path: { address } })
8+
export function getSafeInfo(baseUrl: string, address: string) {
9+
return callEndpoint(baseUrl, '/safes/{address}/', { path: { address } })
1010
}
1111

1212
export function getBalances(
13-
network: string,
13+
baseUrl: string,
1414
address: string,
1515
currency = 'usd',
1616
query: operations['safes_balances_list']['parameters']['query'] = {},
1717
) {
18-
return callEndpoint(network, '/safes/{address}/balances/{currency}/', { path: { address, currency }, query })
18+
return callEndpoint(baseUrl, '/safes/{address}/balances/{currency}/', { path: { address, currency }, query })
1919
}
2020

21-
export function getFiatCurrencies(network: string) {
22-
return callEndpoint(network, '/balances/supported-fiat-codes')
21+
export function getFiatCurrencies(baseUrl: string) {
22+
return callEndpoint(baseUrl, '/balances/supported-fiat-codes')
2323
}
2424

2525
export function getCollectibles(
26-
network: string,
26+
baseUrl: string,
2727
address: string,
2828
query: operations['safes_collectibles_list']['parameters']['query'] = {},
2929
) {
30-
return callEndpoint(network, '/safes/{address}/collectibles/', { path: { address }, query })
30+
return callEndpoint(baseUrl, '/safes/{address}/collectibles/', { path: { address }, query })
3131
}
3232

33-
export function getTransactionHistory(network: string, address: string, pageUrl?: string) {
33+
export function getTransactionHistory(baseUrl: string, address: string, pageUrl?: string) {
3434
return callEndpoint(
35-
network,
35+
baseUrl,
3636
'/safes/{safe_address}/transactions/history',
3737
{ path: { safe_address: address }, query: {} },
3838
pageUrl,
3939
)
4040
}
4141

42-
export function getTransactionQueue(network: string, address: string, pageUrl?: string) {
42+
export function getTransactionQueue(baseUrl: string, address: string, pageUrl?: string) {
4343
return callEndpoint(
44-
network,
44+
baseUrl,
4545
'/safes/{safe_address}/transactions/queued',
4646
{ path: { safe_address: address }, query: {} },
4747
pageUrl,

tests/endpoint.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,39 @@ jest.mock('unfetch', () => jest.fn(() => {
1111
describe('callEndpoint', () => {
1212
it('should accept just a path', () => {
1313
expect(
14-
callEndpoint('xdai', '/balances/supported-fiat-codes')
14+
callEndpoint('https://safe-client.xdai.staging.gnosisdev.com/v1', '/balances/supported-fiat-codes')
1515
).resolves.toEqual({ success: true })
1616

1717
expect(fetch).toHaveBeenCalledWith('https://safe-client.xdai.staging.gnosisdev.com/v1/balances/supported-fiat-codes')
1818
})
1919

2020
it('should accept a path param', () => {
2121
expect(
22-
callEndpoint('rinkeby', '/safe/{address}', { path: { address: '0x123' } })
22+
callEndpoint('https://safe-client.rinkeby.staging.gnosisdev.com/v1', '/safe/{address}', { path: { address: '0x123' } })
2323
).resolves.toEqual({ success: true })
2424

2525
expect(fetch).toHaveBeenCalledWith('https://safe-client.rinkeby.staging.gnosisdev.com/v1/safe/0x123')
2626
})
2727

2828
it('should accept several path params', () => {
2929
expect(
30-
callEndpoint('rinkeby', '/balances/{address}/{currency}', { path: { address: '0x123', currency: 'usd' } })
30+
callEndpoint('https://safe-client.rinkeby.staging.gnosisdev.com/v1', '/balances/{address}/{currency}', { path: { address: '0x123', currency: 'usd' } })
3131
).resolves.toEqual({ success: true })
3232

3333
expect(fetch).toHaveBeenCalledWith('https://safe-client.rinkeby.staging.gnosisdev.com/v1/balances/0x123/usd')
3434
})
3535

3636
it('should accept query params', () => {
3737
expect(
38-
callEndpoint('rinkeby', '/balances/{address}/{currency}', { path: { address: '0x123', currency: 'usd' }, query: { exclude_spam: true } })
38+
callEndpoint('https://safe-client.rinkeby.staging.gnosisdev.com/v1', '/balances/{address}/{currency}', { path: { address: '0x123', currency: 'usd' }, query: { exclude_spam: true } })
3939
).resolves.toEqual({ success: true })
4040

4141
expect(fetch).toHaveBeenCalledWith('https://safe-client.rinkeby.staging.gnosisdev.com/v1/balances/0x123/usd?exclude_spam=true')
4242
})
4343

4444
it('should accept a raw URL', () => {
4545
expect(
46-
callEndpoint('rinkeby', '/balances/{address}/{currency}', { path: { address: '0x123', currency: 'usd' }, query: { exclude_spam: true } }, '/test-url?raw=true')
46+
callEndpoint('https://safe-client.rinkeby.staging.gnosisdev.com/v1', '/balances/{address}/{currency}', { path: { address: '0x123', currency: 'usd' }, query: { exclude_spam: true } }, '/test-url?raw=true')
4747
).resolves.toEqual({ success: true })
4848

4949
expect(fetch).toHaveBeenCalledWith('/test-url?raw=true')

0 commit comments

Comments
 (0)