-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for ledger wallet in new signature designs
- Loading branch information
Showing
19 changed files
with
515 additions
and
82 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
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
25 changes: 25 additions & 0 deletions
25
...mponents/Views/confirmations/components/Confirm/LedgerSignModal/LedgerSignModal.styles.ts
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,25 @@ | ||
import { StyleSheet } from 'react-native'; | ||
|
||
import { Theme } from '../../../../../../util/theme/models'; | ||
|
||
const styleSheet = (params: { theme: Theme }) => { | ||
const { theme } = params; | ||
|
||
return StyleSheet.create({ | ||
modal: { | ||
height: 600, | ||
margin: 0, | ||
zIndex: 1000, | ||
}, | ||
contentWrapper: { | ||
zIndex: 1000, | ||
paddingHorizontal: 8, | ||
marginHorizontal: 8, | ||
paddingBottom: 32, | ||
borderRadius: 20, | ||
backgroundColor: theme.colors.background.default, | ||
}, | ||
}); | ||
}; | ||
|
||
export default styleSheet; |
85 changes: 85 additions & 0 deletions
85
...omponents/Views/confirmations/components/Confirm/LedgerSignModal/LedgerSignModal.test.tsx
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,85 @@ | ||
import React from 'react'; | ||
import { Button, Text, View } from 'react-native'; | ||
import { fireEvent } from '@testing-library/react-native'; | ||
|
||
// eslint-disable-next-line import/no-namespace | ||
import * as rpcEventsFuncs from '../../../../../../actions/rpcEvents'; | ||
import renderWithProvider from '../../../../../../util/test/renderWithProvider'; | ||
import { personalSignatureConfirmationState } from '../../../../../../util/test/confirm-data-helpers'; | ||
// eslint-disable-next-line import/no-namespace | ||
import * as ConfirmationActions from '../../../hooks/useConfirmActions'; | ||
|
||
import LedgerSignModal from './LedgerSignModal'; | ||
|
||
const mockDeviceId = 'MockDeviceId'; | ||
const mockCloseLedgerSignModal = jest.fn(); | ||
jest.mock('../../../context/LedgerContext', () => ({ | ||
useLedgerContext: () => ({ | ||
deviceId: mockDeviceId, | ||
closeLedgerSignModal: mockCloseLedgerSignModal, | ||
}), | ||
})); | ||
|
||
const MockView = View; | ||
const MockText = Text; | ||
const MockButton = Button; | ||
jest.mock('../../../../../UI/LedgerModals/LedgerConfirmationModal', () => ({ | ||
__esModule: true, | ||
default: ({ | ||
onConfirmation, | ||
onRejection, | ||
deviceId, | ||
}: { | ||
onConfirmation: () => void; | ||
onRejection: () => void; | ||
deviceId: string; | ||
}) => ( | ||
<MockView> | ||
<MockText>Mock LedgerConfirmationModal</MockText> | ||
<MockText>{deviceId}</MockText> | ||
<MockButton onPress={onConfirmation} title="onConfirmation" /> | ||
<MockButton onPress={onRejection} title="onRejection" /> | ||
</MockView> | ||
), | ||
})); | ||
|
||
describe('LedgerMessageSignModal', () => { | ||
it('should render LedgerConfirmationModal correctly', () => { | ||
const { getByText } = renderWithProvider(<LedgerSignModal />, { | ||
state: personalSignatureConfirmationState, | ||
}); | ||
expect(getByText('Mock LedgerConfirmationModal')).toBeTruthy(); | ||
expect(getByText(mockDeviceId)).toBeTruthy(); | ||
}); | ||
|
||
it('should call onConfirm when request is confirmed', () => { | ||
const mockOnConfirm = jest.fn(); | ||
jest.spyOn(ConfirmationActions, 'useConfirmActions').mockReturnValue({ | ||
onConfirm: mockOnConfirm, | ||
onReject: jest.fn(), | ||
}); | ||
const { getByText } = renderWithProvider(<LedgerSignModal />, { | ||
state: personalSignatureConfirmationState, | ||
}); | ||
fireEvent.press(getByText('onConfirmation')); | ||
expect(mockOnConfirm).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should call onReject when request is rejected', () => { | ||
const mockOnReject = jest.fn(); | ||
jest.spyOn(ConfirmationActions, 'useConfirmActions').mockReturnValue({ | ||
onConfirm: jest.fn(), | ||
onReject: mockOnReject, | ||
}); | ||
jest | ||
.spyOn(rpcEventsFuncs, 'resetEventStage') | ||
.mockImplementation(() => ({ rpcName: 'dummy', type: 'DUMMY' })); | ||
const { getByText } = renderWithProvider(<LedgerSignModal />, { | ||
state: personalSignatureConfirmationState, | ||
}); | ||
fireEvent.press(getByText('onRejection')); | ||
expect(mockOnReject).toHaveBeenCalledTimes(1); | ||
expect(rpcEventsFuncs.resetEventStage).toHaveBeenCalledTimes(1); | ||
expect(mockCloseLedgerSignModal).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
68 changes: 68 additions & 0 deletions
68
app/components/Views/confirmations/components/Confirm/LedgerSignModal/LedgerSignModal.tsx
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,68 @@ | ||
import React, { useCallback, useEffect } from 'react'; | ||
import Modal from 'react-native-modal'; | ||
import { View } from 'react-native'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
|
||
import { RootState } from '../../../../../../reducers'; | ||
import { | ||
RPCStageTypes, | ||
iEventGroup, | ||
} from '../../../../../../reducers/rpcEvents'; | ||
import { resetEventStage } from '../../../../../../actions/rpcEvents'; | ||
import LedgerConfirmationModal from '../../../../../UI/LedgerModals/LedgerConfirmationModal'; | ||
import { useStyles } from '../../../../../hooks/useStyles'; | ||
import { useConfirmActions } from '../../../hooks/useConfirmActions'; | ||
import { useLedgerContext } from '../../../context/LedgerContext'; | ||
import styleSheet from './LedgerSignModal.styles'; | ||
|
||
const LedgerSignModal = () => { | ||
const dispatch = useDispatch(); | ||
const { styles } = useStyles(styleSheet, {}); | ||
const { signingEvent }: iEventGroup = useSelector( | ||
(state: RootState) => state.rpcEvents, | ||
); | ||
const { closeLedgerSignModal, deviceId } = useLedgerContext(); | ||
const { onConfirm, onReject } = useConfirmActions(); | ||
|
||
const completeRequest = useCallback(() => { | ||
closeLedgerSignModal(); | ||
dispatch(resetEventStage(signingEvent.rpcName)); | ||
}, [closeLedgerSignModal, dispatch, signingEvent.rpcName]); | ||
|
||
useEffect(() => { | ||
//Close the modal when the signMessageStage is complete or error, error will return the error message to the user | ||
if ( | ||
signingEvent.eventStage === RPCStageTypes.COMPLETE || | ||
signingEvent.eventStage === RPCStageTypes.ERROR | ||
) { | ||
completeRequest(); | ||
} | ||
}, [signingEvent.eventStage, completeRequest]); | ||
|
||
const onConfirmation = useCallback(async () => { | ||
onConfirm(); | ||
}, [onConfirm]); | ||
|
||
const onRejection = useCallback(() => { | ||
onReject(); | ||
completeRequest(); | ||
}, [completeRequest, onReject]); | ||
|
||
if (!deviceId) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Modal isVisible style={styles.modal}> | ||
<View style={styles.contentWrapper}> | ||
<LedgerConfirmationModal | ||
onConfirmation={onConfirmation} | ||
onRejection={onRejection} | ||
deviceId={deviceId} | ||
/> | ||
</View> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default LedgerSignModal; |
1 change: 1 addition & 0 deletions
1
app/components/Views/confirmations/components/Confirm/LedgerSignModal/index.ts
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 @@ | ||
export { default } from './LedgerSignModal'; |
Oops, something went wrong.