Skip to content

Commit 22f9955

Browse files
committed
feat: expand geo blocker
1 parent 3ccf81a commit 22f9955

47 files changed

Lines changed: 425 additions & 223 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"editor.defaultFormatter": "vscode.css-language-features"
2121
},
2222
"[json]": {
23-
"editor.defaultFormatter": "vscode.json-language-features"
23+
"editor.defaultFormatter": "biomejs.biome"
2424
},
2525
"[typescript]": {
2626
"editor.defaultFormatter": "biomejs.biome"

apps/evm/src/__mocks__/models/trade.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,21 @@ import fakeAddress, { altAddress } from './address';
66
import { poolData } from './pools';
77

88
const pool = poolData[0];
9-
const xvsAsset = pool.assets[0];
10-
const usdcAsset = pool.assets[1];
11-
const usdtAsset = pool.assets[2];
12-
const busdAsset = pool.assets[3];
9+
const tradePool = {
10+
...pool,
11+
assets: pool.assets.map(asset =>
12+
asset.vToken.address === pool.assets[3].vToken.address
13+
? {
14+
...asset,
15+
isRestricted: false,
16+
}
17+
: asset,
18+
),
19+
};
20+
const xvsAsset = tradePool.assets[0];
21+
const usdcAsset = tradePool.assets[1];
22+
const usdtAsset = tradePool.assets[2];
23+
const busdAsset = tradePool.assets[3];
1324

1425
export const apiTradePositions: ApiTradePosition[] = [
1526
{
@@ -109,7 +120,7 @@ export const apiTradePositions: ApiTradePosition[] = [
109120

110121
export const tradePositions: TradePosition[] = [
111122
formatToTradePosition({
112-
pool,
123+
pool: tradePool,
113124
chainId: busdAsset.vToken.underlyingToken.chainId,
114125
positionAccountAddress: fakeAddress,
115126
dsaVTokenAddress: xvsAsset.vToken.address,
@@ -128,7 +139,7 @@ export const tradePositions: TradePosition[] = [
128139
unrealizedPnlPercentage: 0,
129140
})!,
130141
formatToTradePosition({
131-
pool,
142+
pool: tradePool,
132143
chainId: busdAsset.vToken.underlyingToken.chainId,
133144
positionAccountAddress: altAddress,
134145
dsaVTokenAddress: usdcAsset.vToken.address,
@@ -147,7 +158,7 @@ export const tradePositions: TradePosition[] = [
147158
unrealizedPnlPercentage: 1.2,
148159
})!,
149160
formatToTradePosition({
150-
pool,
161+
pool: tradePool,
151162
chainId: usdtAsset.vToken.underlyingToken.chainId,
152163
positionAccountAddress: altAddress,
153164
dsaVTokenAddress: usdcAsset.vToken.address,

apps/evm/src/clients/api/queries/getPendingRewards/getApiTokenPrice/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import type { ChainId } from 'types';
1+
import type { ApiTokenPrice, ChainId } from 'types';
22
import { restService } from 'utilities';
33
import type { Address } from 'viem';
4-
import type { ApiTokenPrice } from '../../useGetPools/getPools/getApiPools';
54

65
export interface GetApiTokenPriceInput {
76
tokenAddresses: string[];

apps/evm/src/clients/api/queries/getRawTradePositions/__tests__/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import { logError } from 'libs/errors';
1010
import { ChainId } from 'types';
1111
import { formatToTradePosition, restService } from 'utilities';
1212
import { type GetRawTradePositionsInput, getRawTradePositions } from '..';
13-
import { getPools } from '../../useGetPools/getPools';
13+
import { getPools } from '../../useGetPools/useGetPoolsQuery/getPools';
1414

1515
vi.mock('utilities/restService');
16-
vi.mock('../../useGetPools/getPools', () => ({
16+
vi.mock('../../useGetPools/useGetPoolsQuery/getPools', () => ({
1717
getPools: vi.fn(),
1818
}));
1919
vi.mock('libs/errors', async () => {

apps/evm/src/clients/api/queries/getRawTradePositions/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
formatToTradePosition,
99
restService,
1010
} from 'utilities';
11-
import { getPools } from '../useGetPools/getPools';
11+
import { getPools } from '../useGetPools/useGetPoolsQuery/getPools';
1212
import type {
1313
GetApiTradePositionsOutput,
1414
GetRawTradePositionsInput,

apps/evm/src/clients/api/queries/useGetPools/applyCountryCodeToPools/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { ApiTokenMetadata } from '../getPools/getApiPools';
21
import type { GetPoolsOutput } from '../types';
2+
import type { ApiTokenMetadata } from '../useGetPoolsQuery/getPools/getApiPools';
33

44
export const applyCountryCodeToPools = ({
55
countryCode,
@@ -22,10 +22,6 @@ export const applyCountryCodeToPools = ({
2222
const isRestricted = !!tokenMetadata?.restrictedCountries?.includes(countryCode);
2323
const isGated = !!tokenMetadata?.gatedCountries?.includes(countryCode);
2424

25-
if (asset.isRestricted === isRestricted && asset.isGated === isGated) {
26-
return asset;
27-
}
28-
2925
return {
3026
...asset,
3127
isRestricted,

apps/evm/src/clients/api/queries/useGetPools/index.ts

Lines changed: 9 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,21 @@
1-
import { type QueryObserverOptions, useQuery } from '@tanstack/react-query';
21
import { useEffect, useMemo } from 'react';
32

43
import { useGetIpLocation } from 'clients/api/queries/useGetIpLocation';
5-
import FunctionKey from 'constants/functionKey';
6-
import { useGetContractAddress } from 'hooks/useGetContractAddress';
7-
import { useIsFeatureEnabled } from 'hooks/useIsFeatureEnabled';
8-
import { useGetTokens } from 'libs/tokens';
9-
import { useChainId, usePublicClient } from 'libs/wallet';
10-
import type { ChainId } from 'types';
11-
import { generatePseudoRandomRefetchInterval } from 'utilities/generatePseudoRandomRefetchInterval';
124

135
import { logError } from 'libs/errors';
146
import { applyCountryCodeToPools } from './applyCountryCodeToPools';
15-
import { getPools } from './getPools';
16-
import type { GetPoolsQueryOutput } from './getPools';
17-
import type { GetPoolsInput, GetPoolsOutput } from './types';
7+
import type { GetPoolsOutput } from './types';
8+
import {
9+
type TrimmedInput,
10+
type UseGetPoolsQueryOptions,
11+
useGetPoolsQuery,
12+
} from './useGetPoolsQuery';
1813

19-
type TrimmedInput = Omit<
20-
GetPoolsInput,
21-
| 'chainId'
22-
| 'tokens'
23-
| 'publicClient'
24-
| 'primeContractAddress'
25-
| 'poolLensContractAddress'
26-
| 'legacyPoolComptrollerContractAddress'
27-
| 'venusLensContractAddress'
28-
| 'vaiControllerContractAddress'
29-
| 'resilientOracleContractAddress'
30-
| 'isEModeFeatureEnabled'
31-
>;
32-
33-
export type UseGetPoolsQueryKey = [
34-
FunctionKey.GET_POOLS,
35-
TrimmedInput & {
36-
chainId: ChainId;
37-
},
38-
];
39-
40-
type Options = QueryObserverOptions<
41-
GetPoolsQueryOutput,
42-
Error,
43-
GetPoolsQueryOutput,
44-
GetPoolsQueryOutput,
45-
UseGetPoolsQueryKey
46-
>;
47-
48-
const refetchInterval = generatePseudoRandomRefetchInterval();
49-
50-
export const useGetPools = (input?: TrimmedInput, options?: Options) => {
51-
const isPrimeEnabled = useIsFeatureEnabled({
52-
name: 'prime',
53-
});
54-
55-
const isEModeFeatureEnabled = useIsFeatureEnabled({
56-
name: 'eMode',
57-
});
58-
59-
const accountAddress = input?.accountAddress;
60-
const { chainId } = useChainId();
61-
const tokens = useGetTokens();
62-
63-
const { publicClient } = usePublicClient();
64-
65-
const { address: primeContractAddress } = useGetContractAddress({
66-
name: 'Prime',
67-
});
68-
const { address: poolLensContractAddress } = useGetContractAddress({
69-
name: 'PoolLens',
70-
});
71-
const { address: legacyPoolComptrollerContractAddress } = useGetContractAddress({
72-
name: 'LegacyPoolComptroller',
73-
});
74-
const { address: venusLensContractAddress } = useGetContractAddress({
75-
name: 'VenusLens',
76-
});
77-
const { address: vaiControllerContractAddress } = useGetContractAddress({
78-
name: 'VaiController',
79-
});
80-
const { address: resilientOracleContractAddress } = useGetContractAddress({
81-
name: 'ResilientOracle',
82-
});
83-
const isEnabled = options?.enabled !== false;
84-
85-
const poolsQuery = useQuery({
86-
queryKey: [FunctionKey.GET_POOLS, { ...input, chainId, accountAddress }],
87-
queryFn: () =>
88-
getPools({
89-
publicClient,
90-
chainId,
91-
tokens,
92-
legacyPoolComptrollerContractAddress,
93-
venusLensContractAddress,
94-
poolLensContractAddress,
95-
vaiControllerContractAddress,
96-
resilientOracleContractAddress,
97-
primeContractAddress: isPrimeEnabled ? primeContractAddress : undefined,
98-
isEModeFeatureEnabled,
99-
...input,
100-
}),
101-
placeholderData: (previousOutput, previousInput) => {
102-
// Return previous data if chain ID param hasn't changed and user address was undefined
103-
const previousChainId = previousInput?.queryKey[1]?.chainId;
104-
return previousChainId === chainId && !previousInput?.queryKey[1].accountAddress
105-
? previousOutput
106-
: undefined;
107-
},
108-
refetchInterval,
109-
...options,
110-
});
14+
export const useGetPools = (input?: TrimmedInput, options?: UseGetPoolsQueryOptions) => {
15+
const poolsQuery = useGetPoolsQuery(input, options);
11116

11217
const { data: getIpLocationData, error: getIpLocationError } = useGetIpLocation({
113-
enabled: isEnabled,
18+
enabled: options?.enabled !== false,
11419
});
11520

11621
useEffect(() => {

apps/evm/src/clients/api/queries/useGetPools/getPools/appendPrimeSimulationDistributions/index.ts renamed to apps/evm/src/clients/api/queries/useGetPools/useGetPoolsQuery/getPools/appendPrimeSimulationDistributions/index.ts

File renamed without changes.

apps/evm/src/clients/api/queries/useGetPools/getPools/formatOutput/formatDistributions/formatRewardDistribution/index.ts renamed to apps/evm/src/clients/api/queries/useGetPools/useGetPoolsQuery/getPools/formatOutput/formatDistributions/formatRewardDistribution/index.ts

File renamed without changes.

apps/evm/src/clients/api/queries/useGetPools/getPools/formatOutput/formatDistributions/index.ts renamed to apps/evm/src/clients/api/queries/useGetPools/useGetPoolsQuery/getPools/formatOutput/formatDistributions/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { calculateDailyTokenRate } from 'utilities/calculateDailyTokenRate';
55
import findTokenByAddress from 'utilities/findTokenByAddress';
66
import formatRewardDistribution from './formatRewardDistribution';
77

8+
import { convertPriceMantissaToDollars } from 'utilities';
9+
import type { PrimeApy } from '../../../../types';
810
import type {
911
ApiPointsDistribution,
1012
ApiRewardDistributor,
1113
ApiTokenMetadata,
12-
} from 'clients/api/queries/useGetPools/getPools/getApiPools';
13-
import { convertPriceMantissaToDollars } from 'utilities';
14-
import type { PrimeApy } from '../../../types';
14+
} from '../../getApiPools';
1515
import { isDistributingRewards } from './isDistributingRewards';
1616

1717
export type FormatDistributionsInput = {

0 commit comments

Comments
 (0)