-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add stakeSdkProvider and context with stake-sdk
- Loading branch information
Showing
11 changed files
with
4,657 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useContext } from "react"; | ||
import { Stake, StakeContext } from "../sdk/stakeSdkProvider"; | ||
|
||
export const useStakeContext = () => { | ||
const context = useContext(StakeContext); | ||
return context as Stake; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { | ||
ChainId, | ||
PooledStakingContract, | ||
StakingType, | ||
} from '@metamask/stake-sdk'; | ||
import renderWithProvider from '../../../../util/test/renderWithProvider'; | ||
import { createStackNavigator } from '@react-navigation/stack'; | ||
import { backgroundState } from '../../../../util/test/initial-root-state'; | ||
import { Stake } from '../sdk/stakeSdkProvider'; | ||
import * as useStakeContextHook from '../hooks/useStakeContext'; | ||
import { Contract } from '@ethersproject/contracts'; | ||
import { StakeModalStack, StakeScreenStack } from '../routes'; | ||
|
||
const mockPooledStakingContractService: PooledStakingContract = { | ||
chainId: ChainId.ETHEREUM, | ||
connectSignerOrProvider: jest.fn(), | ||
contract: new Contract('0x0000000000000000000000000000000000000000', []), | ||
convertToShares: jest.fn(), | ||
encodeClaimExitedAssetsTransactionData: jest.fn(), | ||
encodeDepositTransactionData: jest.fn(), | ||
encodeEnterExitQueueTransactionData: jest.fn(), | ||
encodeMulticallTransactionData: jest.fn(), | ||
estimateClaimExitedAssetsGas: jest.fn(), | ||
estimateDepositGas: jest.fn(), | ||
estimateEnterExitQueueGas: jest.fn(), | ||
estimateMulticallGas: jest.fn(), | ||
}; | ||
|
||
const mockSDK: Stake = { | ||
sdkService: mockPooledStakingContractService, | ||
sdkType: StakingType.POOLED, | ||
setSdkType: jest.fn(), | ||
}; | ||
|
||
jest.mock('../../Stake/constants', () => ({ | ||
isPooledStakingFeatureEnabled: jest.fn().mockReturnValue(true), | ||
})); | ||
|
||
describe('Stake Modals With Stake Sdk Provider', () => { | ||
const initialState = { | ||
engine: { | ||
backgroundState, | ||
}, | ||
}; | ||
|
||
it('should render correctly stake screen with stake sdk provider and resolve the stake context', () => { | ||
const useStakeContextSpy = jest | ||
.spyOn(useStakeContextHook, 'useStakeContext') | ||
.mockReturnValue(mockSDK); | ||
|
||
const { toJSON } = renderWithProvider(StakeScreenStack(), { | ||
state: initialState, | ||
}); | ||
|
||
expect(toJSON()).toMatchSnapshot(); | ||
expect(useStakeContextSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should render correctly stake modal with stake sdk provider and resolve the stake context', () => { | ||
const useStakeContextSpy = jest | ||
.spyOn(useStakeContextHook, 'useStakeContext') | ||
.mockReturnValue(mockSDK); | ||
|
||
const { toJSON } = renderWithProvider(StakeModalStack(), { | ||
state: initialState, | ||
}); | ||
|
||
expect(toJSON()).toMatchSnapshot(); | ||
expect(useStakeContextSpy).toHaveBeenCalledTimes(0); | ||
|
||
}); | ||
}); |
Oops, something went wrong.