forked from MetaMask/metamask-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: re-designs signatures, continue to use old designs when signing …
…with hardware wallets (MetaMask#12976) ## **Description** Render old designs if hardware wallet or WR aware device is used for signing. ## **Related issues** Fixes: MetaMask/MetaMask-planning#3870 ## **Manual testing steps** 1. Enable re-designs locally 2. Try to sign signature request using hardware wallet 3. It should work in old designs ## **Screenshots/Recordings** TODO ## **Pre-merge author checklist** - [X] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [X] I've completed the PR template to the best of my ability - [X] I’ve included tests if applicable - [X] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [X] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
- Loading branch information
Showing
5 changed files
with
144 additions
and
2 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
72 changes: 72 additions & 0 deletions
72
app/components/Views/confirmations/hooks/useConfirmationRedesignEnabled.test.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,72 @@ | ||
// eslint-disable-next-line import/no-namespace | ||
import * as AddressUtils from '../../../../util/address'; | ||
import { renderHookWithProvider } from '../../../../util/test/renderWithProvider'; | ||
import { personalSignatureConfirmationState } from '../../../../util/test/confirm-data-helpers'; | ||
|
||
// eslint-disable-next-line import/no-namespace | ||
import * as QRHardwareAwareness from './useQRHardwareAwareness'; | ||
import useConfirmationRedesignEnabled from './useConfirmationRedesignEnabled'; | ||
|
||
jest.mock('../../../../core/Engine', () => ({ | ||
getTotalFiatAccountBalance: () => ({ tokenFiat: 10 }), | ||
context: { | ||
KeyringController: { | ||
state: { | ||
keyrings: [], | ||
}, | ||
getOrAddQRKeyring: jest.fn(), | ||
}, | ||
}, | ||
controllerMessenger: { | ||
subscribe: jest.fn(), | ||
}, | ||
})); | ||
|
||
describe('useConfirmationRedesignEnabled', () => { | ||
it('return true for personal sign request', async () => { | ||
const { result } = renderHookWithProvider( | ||
() => useConfirmationRedesignEnabled(), | ||
{ | ||
state: personalSignatureConfirmationState, | ||
}, | ||
); | ||
expect(result?.current.isRedesignedEnabled).toBeTruthy(); | ||
}); | ||
|
||
it('return false for external accounts', async () => { | ||
jest.spyOn(AddressUtils, 'isExternalHardwareAccount').mockReturnValue(true); | ||
const { result } = renderHookWithProvider( | ||
() => useConfirmationRedesignEnabled(), | ||
{ | ||
state: personalSignatureConfirmationState, | ||
}, | ||
); | ||
expect(result?.current.isRedesignedEnabled).toBeFalsy(); | ||
}); | ||
|
||
it('return false if QR hardware is syncing', async () => { | ||
jest | ||
.spyOn(QRHardwareAwareness, 'default') | ||
.mockReturnValue({ isSigningQRObject: true, isSyncingQRHardware: false }); | ||
const { result } = renderHookWithProvider( | ||
() => useConfirmationRedesignEnabled(), | ||
{ | ||
state: personalSignatureConfirmationState, | ||
}, | ||
); | ||
expect(result?.current.isRedesignedEnabled).toBeFalsy(); | ||
}); | ||
|
||
it('return false if QR hardware has synced successfully', async () => { | ||
jest | ||
.spyOn(QRHardwareAwareness, 'default') | ||
.mockReturnValue({ isSigningQRObject: false, isSyncingQRHardware: true }); | ||
const { result } = renderHookWithProvider( | ||
() => useConfirmationRedesignEnabled(), | ||
{ | ||
state: personalSignatureConfirmationState, | ||
}, | ||
); | ||
expect(result?.current.isRedesignedEnabled).toBeFalsy(); | ||
}); | ||
}); |
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
38 changes: 38 additions & 0 deletions
38
app/components/Views/confirmations/hooks/useQRHardwareAwareness.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,38 @@ | ||
import { useState, useEffect } from 'react'; | ||
|
||
import Engine from '../../../../core/Engine'; | ||
import { IQRState } from '../../../UI/QRHardware/types'; | ||
|
||
const useQRHardwareAwareness = () => { | ||
const [qrState, setQRState] = useState<IQRState>({ | ||
sync: { | ||
reading: false, | ||
}, | ||
sign: {}, | ||
}); | ||
|
||
const subscribe = (value: IQRState) => { | ||
setQRState(value); | ||
}; | ||
|
||
useEffect(() => { | ||
Engine.context.KeyringController.getOrAddQRKeyring(); | ||
Engine.controllerMessenger.subscribe( | ||
'KeyringController:qrKeyringStateChange', | ||
subscribe, | ||
); | ||
return () => { | ||
Engine.controllerMessenger.unsubscribe( | ||
'KeyringController:qrKeyringStateChange', | ||
subscribe, | ||
); | ||
}; | ||
}, []); | ||
|
||
return { | ||
isSigningQRObject: !!qrState.sign?.request, | ||
isSyncingQRHardware: qrState.sync.reading, | ||
}; | ||
}; | ||
|
||
export default useQRHardwareAwareness; |