Skip to content

Commit

Permalink
fix: use existing utils function
Browse files Browse the repository at this point in the history
  • Loading branch information
schmanu committed Nov 14, 2023
1 parent 3d5e88f commit e5bda7c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
19 changes: 1 addition & 18 deletions src/services/recovery/__tests__/recovery-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import { JsonRpcProvider } from '@ethersproject/providers'
import type { Delay, TransactionAddedEvent } from '@gnosis.pm/zodiac/dist/cjs/types/Delay'
import type { TransactionReceipt } from '@ethersproject/abstract-provider'

import {
getRecoveryState,
normalizeTxServiceUrl,
_getRecoveryQueueItem,
_getSafeCreationReceipt,
} from '../recovery-state'
import { getRecoveryState, _getRecoveryQueueItem, _getSafeCreationReceipt } from '../recovery-state'
import { useWeb3ReadOnly } from '@/hooks/wallets/web3'
import { cloneDeep } from 'lodash'

Expand Down Expand Up @@ -296,16 +291,4 @@ describe('recovery-state', () => {
expect(queryFilterMock).not.toHaveBeenCalled()
})
})

describe('normalizeTxServiceUrl', () => {
it('should append slash if missing', () => {
const urlWithoutSlash = faker.internet.url({ appendSlash: false })
expect(normalizeTxServiceUrl(urlWithoutSlash)).toEqual(urlWithoutSlash + '/')
})

it('should not change urls with ending slash ', () => {
const urlWithSlash = faker.internet.url({ appendSlash: true })
expect(normalizeTxServiceUrl(urlWithSlash)).toEqual(urlWithSlash)
})
})
})
5 changes: 2 additions & 3 deletions src/services/recovery/recovery-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import type { TransactionReceipt } from '@ethersproject/abstract-provider'

import type { RecoveryQueueItem, RecoveryState } from '@/store/recoverySlice'
import { hexZeroPad } from 'ethers/lib/utils'
import { trimTrailingSlash } from '@/utils/url'

const MAX_PAGE_SIZE = 100

export const normalizeTxServiceUrl = (url: string): string => (url.endsWith('/') ? url : `${url}/`)

export const _getRecoveryQueueItem = async (
transactionAdded: TransactionAddedEvent,
txCooldown: BigNumber,
Expand Down Expand Up @@ -43,7 +42,7 @@ export const _getSafeCreationReceipt = memoize(
safeAddress: string
provider: JsonRpcProvider
}): Promise<TransactionReceipt> => {
const url = `${normalizeTxServiceUrl(transactionService)}api/v1/safes/${safeAddress}/creation/`
const url = `${trimTrailingSlash(transactionService)}/api/v1/safes/${safeAddress}/creation/`

const { transactionHash } = await fetch(url).then((res) => {
if (res.ok && res.status === 200) {
Expand Down

0 comments on commit e5bda7c

Please sign in to comment.