Skip to content

Commit

Permalink
chore: remove 'no-cache' from API requests (#2538)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomiir authored Jul 15, 2024
1 parent 9d6d4b1 commit 45c68d3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/controllers/BlockchainApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ export const BlockchainApiController = {
projectId,
cursor,
onramp,
signal
signal,
cache
}: BlockchainApiTransactionsRequest) {
const queryParams = cursor ? { cursor } : {}

Expand All @@ -138,7 +139,8 @@ export const BlockchainApiController = {
onramp ? `&onramp=${onramp}` : ''
}`,
params: queryParams,
signal
signal,
cache
})
},

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/controllers/TransactionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export const TransactionsController = {
account: accountAddress,
projectId,
cursor: state.next,
onramp
onramp,
// Coinbase transaction history state updates require the latest data
cache: onramp === 'coinbase' ? 'no-cache' : undefined
})

const nonSpamTransactions = this.filterSpamTransactions(response.data)
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/utils/FetchUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface RequestArguments {
path: string
headers?: HeadersInit
params?: Record<string, string | undefined>
cache?: RequestCache
signal?: AbortSignal
}

Expand Down Expand Up @@ -35,9 +36,9 @@ export class FetchUtil {
this.baseUrl = baseUrl
}

public async get<T>({ headers, signal, ...args }: RequestArguments) {
public async get<T>({ headers, signal, cache, ...args }: RequestArguments) {
const url = this.createUrl(args)
const response = await fetchData(url, { method: 'GET', headers, signal, cache: 'no-cache' })
const response = await fetchData(url, { method: 'GET', headers, signal, cache })

return response.json() as T
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils/TypeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export interface BlockchainApiTransactionsRequest {
cursor?: string
onramp?: 'coinbase'
signal?: AbortSignal
cache?: RequestCache
}

export interface BlockchainApiTransactionsResponse {
Expand Down
24 changes: 16 additions & 8 deletions packages/core/tests/controllers/TransactionsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ describe('TransactionsController', () => {
account: accountAddress,
projectId,
onramp: 'coinbase',
cursor: undefined
cursor: undefined,
cache: 'no-cache'
})

expect(TransactionsController.state.transactions).toEqual([])
Expand Down Expand Up @@ -80,7 +81,8 @@ describe('TransactionsController', () => {
account: accountAddress,
projectId,
onramp: 'coinbase',
cursor: undefined
cursor: undefined,
cache: 'no-cache'
})

expect(TransactionsController.state.transactions).toEqual([])
Expand All @@ -105,7 +107,8 @@ describe('TransactionsController', () => {
account: accountAddress,
projectId,
onramp: 'coinbase',
cursor: undefined
cursor: undefined,
cache: 'no-cache'
})

// Transaction should be replaced
Expand Down Expand Up @@ -140,7 +143,8 @@ describe('TransactionsController', () => {
account: accountAddress,
projectId,
onramp: 'coinbase',
cursor: undefined
cursor: undefined,
cache: 'no-cache'
})

expect(TransactionsController.state.transactions).toEqual([])
Expand All @@ -165,7 +169,8 @@ describe('TransactionsController', () => {
account: accountAddress,
projectId,
onramp: 'coinbase',
cursor: undefined
cursor: undefined,
cache: 'no-cache'
})

// Transaction should be replaced
Expand Down Expand Up @@ -200,7 +205,8 @@ describe('TransactionsController', () => {
account: accountAddress,
projectId,
onramp: 'coinbase',
cursor: undefined
cursor: undefined,
cache: 'no-cache'
})

expect(TransactionsController.state.transactions).toEqual([])
Expand All @@ -225,7 +231,8 @@ describe('TransactionsController', () => {
account: accountAddress,
projectId,
onramp: 'coinbase',
cursor: undefined
cursor: undefined,
cache: 'no-cache'
})

// Transaction should be replaced
Expand Down Expand Up @@ -261,7 +268,8 @@ describe('TransactionsController', () => {
account: '0x123',
projectId,
cursor: undefined,
onramp: undefined
onramp: undefined,
cache: undefined
})
expect(TransactionsController.state.next).toBe('cursor')
})
Expand Down

0 comments on commit 45c68d3

Please sign in to comment.