Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove RELAY_NATIVE_SWAPS feature #4304

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/tx/SignOrExecuteForm/ExecuteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const ExecuteForm = ({

// SC wallets can relay fully signed transactions
const [walletCanRelay] = useWalletCanRelay(safeTx)
const relays = useRelaysBySafe(origin)
const relays = useRelaysBySafe()
// The transaction can/will be relayed
const canRelay = walletCanRelay && hasRemainingRelays(relays[0])
const willRelay = canRelay && executionMethod === ExecutionMethod.RELAY
Expand Down
40 changes: 0 additions & 40 deletions src/hooks/__tests__/useRemainingRelays.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,46 +52,6 @@ describe('fetch remaining relays hooks', () => {

expect(mockFetch).toHaveBeenCalledTimes(2)
})

it('should not do a network request if only swaps are supported but the tx is not a swap', () => {
jest.spyOn(useChains, 'useCurrentChain').mockReturnValue(
chainBuilder()
// @ts-expect-error - using local FEATURES enum
.with({ features: [FEATURES.RELAY_NATIVE_SWAPS] })
.build(),
)

const mockFetch = jest.spyOn(gateway, 'getRelayCount')

renderHook(() => useRelaysBySafe(JSON.stringify({ url: 'https://some.url', name: 'Some app' })))
expect(mockFetch).toHaveBeenCalledTimes(0)
})

it('should do a network request if only swaps are supported and the tx is a swap', async () => {
jest.spyOn(useChains, 'useCurrentChain').mockReturnValue(
chainBuilder()
// @ts-expect-error - using local FEATURES enum
.with({ features: [FEATURES.RELAY_NATIVE_SWAPS] })
.build(),
)

const mockFetch = jest.spyOn(gateway, 'getRelayCount').mockResolvedValue({
limit: 5,
remaining: 3,
})

const { result } = renderHook(() =>
useRelaysBySafe(JSON.stringify({ url: 'https://some.url', name: 'Safe Swap' })),
)

await waitFor(() => {
expect(mockFetch).toHaveBeenCalledTimes(1)
expect(result.current[0]).toEqual({
limit: 5,
remaining: 3,
})
})
})
})

describe('useLeastRemainingRelays hook', () => {
Expand Down
7 changes: 2 additions & 5 deletions src/hooks/useRemainingRelays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ import { getRelayCount } from '@safe-global/safe-gateway-typescript-sdk'

export const MAX_HOUR_RELAYS = 5

export const useRelaysBySafe = (txOrigin?: string) => {
export const useRelaysBySafe = () => {
const chain = useCurrentChain()
const { safe, safeAddress } = useSafeInfo()

return useAsync(() => {
if (!safeAddress || !chain) return
if (
hasFeature(chain, FEATURES.RELAYING) ||
(hasFeature(chain, FEATURES.RELAY_NATIVE_SWAPS) && txOrigin && JSON.parse(txOrigin).name === 'Safe Swap')
) {
if (hasFeature(chain, FEATURES.RELAYING)) {
return getRelayCount(chain.chainId, safeAddress)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
1 change: 0 additions & 1 deletion src/utils/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export enum FEATURES {
NATIVE_SWAPS = 'NATIVE_SWAPS',
NATIVE_SWAPS_USE_COW_STAGING_SERVER = 'NATIVE_SWAPS_USE_COW_STAGING_SERVER',
NATIVE_SWAPS_FEE_ENABLED = 'NATIVE_SWAPS_FEE_ENABLED',
RELAY_NATIVE_SWAPS = 'RELAY_NATIVE_SWAPS',
ZODIAC_ROLES = 'ZODIAC_ROLES',
SAFE_141 = 'SAFE_141',
STAKING = 'STAKING',
Expand Down
Loading