-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suite-native): handle pin by state, not button requests (#12889)
* feat(suite-native): handle pin by state, not button requests * refactor(suite-native): simplify conditions in slice
- Loading branch information
Showing
22 changed files
with
111 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "@suite-native/device-authorization", | ||
"version": "1.0.0", | ||
"private": true, | ||
"license": "See LICENSE.md in repo root", | ||
"sideEffects": false, | ||
"main": "src/index", | ||
"scripts": { | ||
"lint:js": "yarn g:eslint '**/*.{ts,tsx,js}'", | ||
"depcheck": "yarn g:depcheck", | ||
"type-check": "yarn g:tsc --build" | ||
}, | ||
"dependencies": { | ||
"@reduxjs/toolkit": "1.9.5", | ||
"@trezor/connect": "workspace:*" | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
suite-native/device-authorization/src/deviceAuthorizationSlice.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,44 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
import { UI } from '@trezor/connect'; | ||
|
||
import { isPinButtonRequestCode } from './utils'; | ||
|
||
type DeviceAuthorizationState = { | ||
hasDeviceRequestedPin: boolean; | ||
}; | ||
|
||
type DeviceAuthorizationRootState = { | ||
deviceAuthorization: DeviceAuthorizationState; | ||
}; | ||
|
||
const deviceAuthorizationInitialState: DeviceAuthorizationState = { | ||
hasDeviceRequestedPin: false, | ||
}; | ||
|
||
export const deviceAuthorizationSlice = createSlice({ | ||
name: 'deviceAuthorization', | ||
initialState: deviceAuthorizationInitialState, | ||
reducers: {}, | ||
extraReducers: builder => { | ||
builder | ||
.addCase(UI.REQUEST_PIN, state => { | ||
state.hasDeviceRequestedPin = true; | ||
}) | ||
.addCase(UI.REQUEST_BUTTON, (state, action) => { | ||
if (isPinButtonRequestCode(action)) { | ||
state.hasDeviceRequestedPin = true; | ||
} else { | ||
state.hasDeviceRequestedPin = false; | ||
} | ||
}) | ||
.addCase(UI.CLOSE_UI_WINDOW, state => { | ||
state.hasDeviceRequestedPin = false; | ||
}); | ||
}, | ||
}); | ||
|
||
export const selectDeviceRequestedPin = (state: DeviceAuthorizationRootState) => | ||
state.deviceAuthorization.hasDeviceRequestedPin; | ||
|
||
export const deviceAuthorizationReducer = deviceAuthorizationSlice.reducer; |
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,2 @@ | ||
export * from './deviceAuthorizationSlice'; | ||
export * from './utils'; |
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,5 @@ | ||
import { AnyAction } from '@reduxjs/toolkit'; | ||
|
||
export const isPinButtonRequestCode = (action: AnyAction) => | ||
action.payload.code === 'ButtonRequest_PinEntry' || // T2 with PIN entry on device | ||
action.payload.code === 'PinMatrixRequestType_Current'; // T1 with PIN matrix in app |
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 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { "outDir": "libDev" }, | ||
"references": [ | ||
{ "path": "../../packages/connect" } | ||
] | ||
} |
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
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
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
Oops, something went wrong.