Skip to content

Commit

Permalink
fix: remove circular dependency (#1255)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessey authored Sep 14, 2024
1 parent 76c1edb commit d85f460
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
12 changes: 12 additions & 0 deletions src/swap/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@ export const UNCAUGHT_SWAP_ERROR_CODE = 'UNCAUGHT_SWAP_ERROR';
export const UNIVERSALROUTER_CONTRACT_ADDRESS =
'0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD';
export const USER_REJECTED_ERROR_CODE = 'USER_REJECTED';
export enum SwapMessage {
BALANCE_ERROR = 'Error fetching token balance',
CONFIRM_IN_WALLET = 'Confirm in wallet',
FETCHING_QUOTE = 'Fetching quote...',
FETCHING_BALANCE = 'Fetching balance...',
INCOMPLETE_FIELD = 'Complete the fields to continue',
INSUFFICIENT_BALANCE = 'Insufficient balance',
LOW_LIQUIDITY = 'Liquidity too low for the token',
SWAP_IN_PROGRESS = 'Swap in progress...',
TOO_MANY_REQUESTS = 'Too many requests. Please try again later.',
USER_REJECTED = 'User rejected the transaction',
}
4 changes: 2 additions & 2 deletions src/swap/utils/getErrorMessage.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { describe, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import {
LOW_LIQUIDITY_ERROR_CODE,
SwapMessage,
TOO_MANY_REQUESTS_ERROR_CODE,
USER_REJECTED_ERROR_CODE,
} from '../constants';
import type { SwapError } from '../types';
import { getErrorMessage } from './getErrorMessage';
import { SwapMessage } from './getSwapMessage';

describe('getSwapError', () => {
it('should return TOO_MANY_REQUESTS when error code is TOO_MANY_REQUESTS_ERROR_CODE', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/swap/utils/getErrorMessage.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
LOW_LIQUIDITY_ERROR_CODE,
SwapMessage,
TOO_MANY_REQUESTS_ERROR_CODE,
USER_REJECTED_ERROR_CODE,
} from '../constants';
import type { SwapError } from '../types';
import { SwapMessage } from './getSwapMessage';

export function getErrorMessage(error: SwapError): string | undefined {
// error states handled below
Expand Down
5 changes: 3 additions & 2 deletions src/swap/utils/getSwapMessage.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { describe, expect, vi } from 'vitest';
import { describe, expect, it, vi } from 'vitest';
import {
LOW_LIQUIDITY_ERROR_CODE,
SwapMessage,
TOO_MANY_REQUESTS_ERROR_CODE,
USER_REJECTED_ERROR_CODE,
} from '../constants';
import { ETH_TOKEN, USDC_TOKEN } from '../mocks';
/**
* @vitest-environment node
*/
import { SwapMessage, getSwapMessage } from './getSwapMessage';
import { getSwapMessage } from './getSwapMessage';

describe('getSwapMessage', () => {
const baseParams = {
Expand Down
14 changes: 1 addition & 13 deletions src/swap/utils/getSwapMessage.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
import { SwapMessage } from '../constants';
import type { GetSwapMessageParams } from '../types';
import { getErrorMessage } from './getErrorMessage';

export enum SwapMessage {
BALANCE_ERROR = 'Error fetching token balance',
CONFIRM_IN_WALLET = 'Confirm in wallet',
FETCHING_QUOTE = 'Fetching quote...',
FETCHING_BALANCE = 'Fetching balance...',
INCOMPLETE_FIELD = 'Complete the fields to continue',
INSUFFICIENT_BALANCE = 'Insufficient balance',
LOW_LIQUIDITY = 'Liquidity too low for the token',
SWAP_IN_PROGRESS = 'Swap in progress...',
TOO_MANY_REQUESTS = 'Too many requests. Please try again later.',
USER_REJECTED = 'User rejected the transaction',
}

export function getSwapMessage({
address,
error,
Expand Down

0 comments on commit d85f460

Please sign in to comment.