Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -5721,7 +5721,6 @@ describe('PredictController', () => {
const mockAccountState = {
address: '0xProxyAddress' as `0x${string}`,
isDeployed: true,
hasAllowances: true,
balance: 100.5,
};

Expand Down
6 changes: 3 additions & 3 deletions app/components/UI/Predict/controllers/PredictController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import { GEO_BLOCKED_COUNTRIES } from '../constants/geoblock';
import { PREDICT_BALANCE_PLACEHOLDER_ADDRESS } from '../constants/transactions';
import { PolymarketProvider } from '../providers/polymarket/PolymarketProvider';
import {
MATIC_CONTRACTS,
MATIC_CONTRACTS_V2,
POLYMARKET_PROVIDER_ID,
} from '../providers/polymarket/constants';
import { Signer } from '../providers/types';
Expand Down Expand Up @@ -1453,7 +1453,7 @@ export class PredictController extends BaseController<
disableHook: true,
disableSequential: true,
// Temporarily breaking abstraction, can instead be abstracted via provider.
gasFeeToken: MATIC_CONTRACTS.collateral as Hex,
gasFeeToken: MATIC_CONTRACTS_V2.collateral as Hex,
transactions,
});

Expand Down Expand Up @@ -2564,7 +2564,7 @@ export class PredictController extends BaseController<
disableSequential: true,
requireApproval: true,
// Temporarily breaking abstraction, can instead be abstracted via provider.
gasFeeToken: MATIC_CONTRACTS.collateral as Hex,
gasFeeToken: MATIC_CONTRACTS_V2.collateral as Hex,
transactions: [transaction],
});

Expand Down
20 changes: 0 additions & 20 deletions app/components/UI/Predict/hooks/usePredictAccountState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ describe('usePredictAccountState', () => {
const mockAccountState = {
address: '0x1234567890abcdef1234567890abcdef12345678',
isDeployed: true,
hasAllowances: true,
};

beforeEach(() => {
Expand Down Expand Up @@ -117,7 +116,6 @@ describe('usePredictAccountState', () => {
expect(mockGetAccountState).toHaveBeenCalledWith({});
expect(result.current.data?.address).toEqual(mockAccountState.address);
expect(result.current.data?.isDeployed).toBe(true);
expect(result.current.data?.hasAllowances).toBe(true);
expect(result.current.error).toBeNull();
});

Expand Down Expand Up @@ -215,24 +213,6 @@ describe('usePredictAccountState', () => {
expect(result.current.data?.isDeployed).toBe(false);
});

it('returns hasAllowances as false when account lacks allowances', async () => {
const { Wrapper } = createWrapper();
mockGetAccountState.mockResolvedValue({
...mockAccountState,
hasAllowances: false,
});

const { result } = renderHook(() => usePredictAccountState(), {
wrapper: Wrapper,
});

await waitFor(() => {
expect(result.current.data).toBeDefined();
});

expect(result.current.data?.hasAllowances).toBe(false);
});

it('has undefined data when query is disabled', () => {
const { Wrapper } = createWrapper();
const { result } = renderHook(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface UsePredictAccountStateOptions {
}

/**
* Fetches the Predict account state (address, deployment status, allowances).
* Fetches the Predict account state (address and deployment status).
*/
export function usePredictAccountState(
options: UsePredictAccountStateOptions = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ jest.mock('../../../Views/confirmations/utils/transaction', () => ({
hasTransactionType: jest.fn(),
}));

jest.mock('../../../../util/networks', () => ({
getNetworkImageSource: jest.fn(() => 'polygon-network-badge'),
}));

const mockHasTransactionType = hasTransactionType as jest.MockedFunction<
typeof hasTransactionType
>;
Expand Down Expand Up @@ -85,7 +81,7 @@ describe('usePredictBalanceTokenFilter', () => {
mockPredictBalance = 100;
mockTransactionMeta = null;
mockHasTransactionType.mockReturnValue(false);
mockUseSelector.mockReturnValue({ image: 'usdce-token-image' });
mockUseSelector.mockReturnValue({ image: 'pusd-token-image' });
mockNavigate.mockReset();
});

Expand Down Expand Up @@ -165,19 +161,19 @@ describe('usePredictBalanceTokenFilter', () => {
expect((filteredTokens[0] as HighlightedItem).fiat).toBe('$42.50');
});

it('shows name_description as USDC.e on the Predict balance row', () => {
it('shows name_description as pUSD on the Predict balance row', () => {
mockHasTransactionType.mockReturnValue(true);
const tokens = [createMockToken()];

const { result } = renderHook(() => usePredictBalanceTokenFilter());
const filteredTokens = result.current(tokens);

expect((filteredTokens[0] as HighlightedItem).name_description).toBe(
'USDC.e',
'pUSD',
);
});

it('uses empty string for icon when usdceToken is null', () => {
it('uses empty string for icon when pusdToken is null', () => {
mockHasTransactionType.mockReturnValue(true);
mockUseSelector.mockReturnValue(null);
const tokens = [createMockToken()];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { TransactionType } from '@metamask/transaction-controller';
import { BigNumber } from 'bignumber.js';
import { useCallback } from 'react';
import { useNavigation } from '@react-navigation/native';
import { useSelector } from 'react-redux';
import { strings } from '../../../../../locales/i18n';
import Routes from '../../../../constants/navigation/Routes';
import { RootState } from '../../../../reducers';
import { selectSingleTokenByAddressAndChainId } from '../../../../selectors/tokensController';
import useFiatFormatter from '../../SimulationDetails/FiatDisplay/useFiatFormatter';
import { POLYGON_USDCE } from '../../../Views/confirmations/constants/predict';
import { TransactionType } from '@metamask/transaction-controller';
import { POLYGON_PUSD } from '../../../Views/confirmations/constants/predict';
import { useTransactionMetadataRequest } from '../../../Views/confirmations/hooks/transactions/useTransactionMetadataRequest';
import {
AssetType,
Expand All @@ -17,8 +19,6 @@ import { hasTransactionType } from '../../../Views/confirmations/utils/transacti
import { PREDICT_BALANCE_CHAIN_ID } from '../constants/transactions';
import { usePredictBalance } from './usePredictBalance';
import { usePredictPaymentToken } from './usePredictPaymentToken';
import { strings } from '../../../../../locales/i18n';
import Routes from '../../../../constants/navigation/Routes';

export function usePredictBalanceTokenFilter(
forceEnabled = false,
Expand All @@ -29,10 +29,10 @@ export function usePredictBalanceTokenFilter(
const { isPredictBalanceSelected } = usePredictPaymentToken();
const { data: predictBalance = 0 } = usePredictBalance();
const formatFiat = useFiatFormatter({ currency: 'usd' });
const usdceToken = useSelector((state: RootState) =>
const pusdToken = useSelector((state: RootState) =>
selectSingleTokenByAddressAndChainId(
state,
POLYGON_USDCE.address,
POLYGON_PUSD.address,
PREDICT_BALANCE_CHAIN_ID,
),
);
Expand Down Expand Up @@ -60,9 +60,9 @@ export function usePredictBalanceTokenFilter(

const predictBalanceHighlightedItem: HighlightedItem = {
position: 'in_asset_list',
icon: usdceToken?.image ?? '',
icon: pusdToken?.image ?? '',
name: strings('predict.payment.predict_balance'),
name_description: POLYGON_USDCE.symbol,
name_description: POLYGON_PUSD.symbol,
fiat: balanceFormatted,
isSelected: isPredictBalanceSelected,
action: onSelect ?? (() => undefined),
Expand Down Expand Up @@ -90,7 +90,7 @@ export function usePredictBalanceTokenFilter(
isPredictBalanceSelected,
predictBalance,
formatFiat,
usdceToken,
pusdToken,
handleAddFunds,
onSelect,
],
Expand Down
8 changes: 4 additions & 4 deletions app/components/UI/Predict/hooks/usePredictRewards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Logger from '../../../../util/Logger';
import { getFormattedAddressFromInternalAccount } from '../../../../core/Multichain/utils';
import {
POLYGON_MAINNET_CAIP_CHAIN_ID,
POLYGON_USDC_CAIP_ASSET_ID,
POLYGON_PUSD_CAIP_ASSET_ID,
} from '../providers/polymarket/constants';

jest.mock('react-redux', () => ({
Expand Down Expand Up @@ -47,8 +47,8 @@ jest.mock('../constants/errors', () => ({

jest.mock('../providers/polymarket/constants', () => ({
POLYGON_MAINNET_CAIP_CHAIN_ID: 'eip155:137',
POLYGON_USDC_CAIP_ASSET_ID:
'eip155:137/erc20:0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
POLYGON_PUSD_CAIP_ASSET_ID:
'eip155:137/erc20:0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB',
COLLATERAL_TOKEN_DECIMALS: 6,
}));

Expand Down Expand Up @@ -185,7 +185,7 @@ describe('usePredictRewards', () => {
activityContext: {
predictContext: {
feeAsset: {
id: POLYGON_USDC_CAIP_ASSET_ID,
id: POLYGON_PUSD_CAIP_ASSET_ID,
amount: expect.any(String),
},
},
Expand Down
6 changes: 3 additions & 3 deletions app/components/UI/Predict/hooks/usePredictRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { selectSelectedInternalAccountByScope } from '../../../../selectors/mult
import { getFormattedAddressFromInternalAccount } from '../../../../core/Multichain/utils';
import {
POLYGON_MAINNET_CAIP_CHAIN_ID,
POLYGON_USDC_CAIP_ASSET_ID,
POLYGON_PUSD_CAIP_ASSET_ID,
COLLATERAL_TOKEN_DECIMALS,
} from '../providers/polymarket/constants';
import { parseUnits } from 'ethers/lib/utils';
Expand Down Expand Up @@ -186,9 +186,9 @@ export const usePredictRewards = (
}

// Prepare fee asset
// Convert USD amount to atomic units (6 decimals for USDC)
// Convert USD amount to atomic units (6 decimals for pUSD)
const feeAsset: EstimateAssetDto = {
id: POLYGON_USDC_CAIP_ASSET_ID,
id: POLYGON_PUSD_CAIP_ASSET_ID,
amount: parseUnits(
totalFeeAmountUsd.toString(),
COLLATERAL_TOKEN_DECIMALS,
Expand Down
Loading
Loading