-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add StakeSdkProvider with stake-sdk #11668
Open
siibars
wants to merge
11
commits into
main
Choose a base branch
from
feat/stake-799
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,427
−21
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d85c30d
feat: add stakeSdkProvider and context with stake-sdk
siibars d6bc8bf
fix: unit test
siibars d5060e6
chore: yarn lint and fix test
siibars 7dc741b
fix: unit test stakeinputview
siibars f27c825
chore: remove stake analytic event mock
siibars e2f793b
fix: update snapshot usesdkprovider test
siibars f267187
chore: add stake provider on screen stack
siibars 65c72c8
chore: remove comment from metametrics event file
siibars 9a565f7
Revert "chore: remove comment from metametrics event file"
siibars 7c4957c
chore: remove duplicate comment
siibars 56ecea8
chore: remove comment
siibars File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
siibars marked this conversation as resolved.
Show resolved
Hide resolved
|
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,71 @@ | ||
import { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: This file is testing the hook |
||
ChainId, | ||
PooledStakingContract, | ||
StakingType, | ||
} from '@metamask/stake-sdk'; | ||
import renderWithProvider from '../../../../util/test/renderWithProvider'; | ||
import { backgroundState } from '../../../../util/test/initial-root-state'; | ||
import { Stake } from '../sdk/stakeSdkProvider'; | ||
// eslint-disable-next-line import/no-namespace | ||
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure a navigation needs to be wrapped on a useCallback, since it's not an high resources computational function, we could remove the useCallback, and also the disable of eslint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi, the eslint react-hooks/exhaustive-deps exclude comment is only about the sdkService being added in the dependency list and not used yet, but will as soon as this pr is merged