Skip to content

Commit

Permalink
fix: changes based on code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt561 committed Oct 24, 2024
1 parent 01fe4a2 commit 4a839dd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
10 changes: 10 additions & 0 deletions app/components/UI/Stake/__mocks__/mockData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ChainId,
StakingApiService,
StakingType,
type PooledStakes,
type VaultData,
Expand Down Expand Up @@ -94,6 +95,14 @@ export const MOCK_REWARD_DATA = {
},
};

export const MOCK_STAKING_API_SERVICE: Partial<StakingApiService> = {
fetchFromApi: jest.fn(),
getPooledStakes: jest.fn(),
getVaultData: jest.fn(),
getPooledStakingEligibility: jest.fn(),
baseUrl: 'https://staking.api.com',
};

const MOCK_POOLED_STAKING_CONTRACT_SERVICE = {
chainId: ChainId.ETHEREUM,
connectSignerOrProvider: jest.fn(),
Expand All @@ -111,6 +120,7 @@ const MOCK_POOLED_STAKING_CONTRACT_SERVICE = {

export const MOCK_POOL_STAKING_SDK: Stake = {
stakingContract: MOCK_POOLED_STAKING_CONTRACT_SERVICE,
stakingApiService: MOCK_STAKING_API_SERVICE as StakingApiService,
sdkType: StakingType.POOLED,
setSdkType: jest.fn(),
};
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ jest.mock('../../../../hooks/usePoolStakedUnstake', () => ({
}),
}));

jest.mock('../../../../hooks/usePooledStakes', () => ({
__esModule: true,
default: () => ({
refreshPooledStakes: jest.fn(),
}),
}));

describe('FooterButtonGroup', () => {
beforeEach(() => {
jest.resetAllMocks();
Expand Down
10 changes: 3 additions & 7 deletions app/components/UI/Stake/sdk/stakeSdkProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
PooledStakingContract,
type StakingApiService,
isSupportedChain,
ChainId,
} from '@metamask/stake-sdk';
import React, {
useState,
Expand All @@ -15,10 +14,7 @@ import React, {
import { getProviderByChainId } from '../../../../util/notifications';
import { useSelector } from 'react-redux';
import { selectChainId } from '../../../../selectors/networkController';
import { hexToDecimal } from '../../../../util/conversions';

const hexToChainId = (hex: `0x${string}`): ChainId =>
hexToDecimal(hex).toString() as unknown as ChainId;
import { getDecimalChainId } from '../../../../util/networks';

export const SDK = StakeSdk.create({ stakingType: StakingType.POOLED });

Expand All @@ -42,7 +38,7 @@ export const StakeSDKProvider: React.FC<
const chainId = useSelector(selectChainId);

const sdkService = useMemo(() => {
if (!chainId || !isSupportedChain(hexToChainId(chainId))) {
if (!chainId || !isSupportedChain(getDecimalChainId(chainId))) {
console.error(
'Failed to initialize Staking SDK Service: chainId unsupported',
);
Expand All @@ -59,7 +55,7 @@ export const StakeSDKProvider: React.FC<
}

const sdk = StakeSdk.create({
chainId: parseInt(hexToChainId(chainId).toString()),
chainId: getDecimalChainId(chainId),
stakingType: sdkType,
});

Expand Down

0 comments on commit 4a839dd

Please sign in to comment.