-
-
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: permissions system within sdk redux store (#8785)
## **Description** - Migrate away from Default Preferences to manage persisted session state. - Migrate walletconnect to permission system - Connection flow optimization for ios mobile Grouped within a single PR as these features are tightly integrated together. ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've clearly explained what problem this PR is solving and how it is solved. - [x] I've linked related issues - [x] I've included manual testing steps - [x] I've included screenshots/recordings if applicable - [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. - [x] I’ve properly set the pull request status: - [x] In case it's not yet "ready for review", I've set it to "draft". - [x] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **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
1 parent
1097298
commit 8299ec9
Showing
47 changed files
with
608 additions
and
673 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
import type { Action as ReduxAction } from 'redux'; | ||
import { ConnectionProps } from '../../core/SDKConnect/Connection'; | ||
import { ApprovedHosts, SDKSessions } from '../../core/SDKConnect/SDKConnect'; | ||
import { WC2Metadata } from './state'; | ||
|
||
export enum ActionType { | ||
WC2_METADATA = 'WC2_METADATA', | ||
RESET_CONNECTIONS = 'RESET_CONNECTIONS', | ||
UPDATE_CONNECTION = 'UPDATE_CONNECTION', | ||
REMOVE_CONNECTION = 'REMOVE_CONNECTION', | ||
ADD_CONNECTION = 'ADD_CONNECTION', | ||
DISCONNECT_ALL = 'DISCONNECT_ALL', | ||
REMOVE_APPROVED_HOST = 'REMOVE_APPROVWED_HOST', | ||
SET_APPROVED_HOST = 'SET_APPROVED_HOST', | ||
RESET_APPROVED_HOSTS = 'RESET_APPROVED_HOSTS', | ||
SET_CONNECTED = 'SET_CONNECTED', | ||
UPDATE_ANDROID_CONNECTION = 'UPDATE_ANDROID_CONNECTION', | ||
REMOVE_ANDROID_CONNECTION = 'REMOVE_ANDROID_CONNECTION', | ||
RESET_ANDROID_CONNECTIONS = 'RESET_ANDROID_CONNECTIONS', | ||
} | ||
|
||
export type DisconnectAll = ReduxAction<ActionType.DISCONNECT_ALL>; | ||
|
||
export interface UpdateConnection | ||
extends ReduxAction<ActionType.UPDATE_CONNECTION> { | ||
channelId: string; | ||
connection: ConnectionProps; | ||
} | ||
|
||
export interface ResetConnection | ||
extends ReduxAction<ActionType.RESET_CONNECTIONS> { | ||
connections: SDKSessions; | ||
} | ||
|
||
export interface RemoveConnection | ||
extends ReduxAction<ActionType.REMOVE_CONNECTION> { | ||
channelId: string; | ||
} | ||
|
||
export interface AddConnection extends ReduxAction<ActionType.ADD_CONNECTION> { | ||
channelId: string; | ||
connection: ConnectionProps; | ||
} | ||
|
||
export interface RemoveApprovedHost | ||
extends ReduxAction<ActionType.REMOVE_APPROVED_HOST> { | ||
channelId: string; | ||
} | ||
|
||
export interface SetApprovedHost | ||
extends ReduxAction<ActionType.SET_APPROVED_HOST> { | ||
channelId: string; | ||
validUntil: number; | ||
} | ||
|
||
export interface ResetApprovedHosts | ||
extends ReduxAction<ActionType.RESET_APPROVED_HOSTS> { | ||
approvedHosts: ApprovedHosts; | ||
} | ||
|
||
export interface UpdateAndroidConnection | ||
extends ReduxAction<ActionType.UPDATE_ANDROID_CONNECTION> { | ||
channelId: string; | ||
connection: ConnectionProps; | ||
} | ||
|
||
export interface RemoveAndroidConnection | ||
extends ReduxAction<ActionType.REMOVE_ANDROID_CONNECTION> { | ||
channelId: string; | ||
} | ||
|
||
export interface ResetAndroidConnections | ||
extends ReduxAction<ActionType.RESET_ANDROID_CONNECTIONS> { | ||
connections: SDKSessions; | ||
} | ||
|
||
export interface SetConnected extends ReduxAction<ActionType.SET_CONNECTED> { | ||
channelId: string; | ||
connected: boolean; | ||
} | ||
|
||
export interface UpdateWC2Metadata | ||
extends ReduxAction<ActionType.WC2_METADATA> { | ||
metadata?: WC2Metadata; | ||
} | ||
|
||
export type Action = | ||
| UpdateConnection | ||
| DisconnectAll | ||
| RemoveConnection | ||
| AddConnection | ||
| ResetConnection | ||
| RemoveApprovedHost | ||
| SetApprovedHost | ||
| ResetApprovedHosts | ||
| UpdateWC2Metadata | ||
| UpdateAndroidConnection | ||
| RemoveAndroidConnection | ||
| ResetAndroidConnections | ||
| SetConnected; | ||
|
||
export const disconnectAll = (): DisconnectAll => ({ | ||
type: ActionType.DISCONNECT_ALL, | ||
}); | ||
|
||
export const updateWC2Metadata = ( | ||
metadata: WC2Metadata, | ||
): UpdateWC2Metadata => ({ | ||
type: ActionType.WC2_METADATA, | ||
metadata, | ||
}); | ||
|
||
export const updateConnection = ( | ||
channelId: string, | ||
connection: ConnectionProps, | ||
): UpdateConnection => ({ | ||
type: ActionType.UPDATE_CONNECTION, | ||
channelId, | ||
connection, | ||
}); | ||
|
||
export const removeConnection = (channelId: string): RemoveConnection => ({ | ||
type: ActionType.REMOVE_CONNECTION, | ||
channelId, | ||
}); | ||
|
||
export const addConnection = ( | ||
channelId: string, | ||
connection: ConnectionProps, | ||
): AddConnection => ({ | ||
type: ActionType.ADD_CONNECTION, | ||
channelId, | ||
connection, | ||
}); | ||
|
||
export const resetConnections = ( | ||
connections: SDKSessions, | ||
): ResetConnection => ({ | ||
type: ActionType.RESET_CONNECTIONS, | ||
connections, | ||
}); | ||
|
||
export const removeApprovedHost = (channelId: string): RemoveApprovedHost => ({ | ||
type: ActionType.REMOVE_APPROVED_HOST, | ||
channelId, | ||
}); | ||
|
||
export const setApprovedHost = ( | ||
channelId: string, | ||
validUntil: number, | ||
): SetApprovedHost => ({ | ||
type: ActionType.SET_APPROVED_HOST, | ||
channelId, | ||
validUntil, | ||
}); | ||
|
||
export const resetApprovedHosts = ( | ||
approvedHosts: ApprovedHosts, | ||
): ResetApprovedHosts => ({ | ||
type: ActionType.RESET_APPROVED_HOSTS, | ||
approvedHosts, | ||
}); | ||
|
||
export const updateAndroidConnection = ( | ||
channelId: string, | ||
connection: ConnectionProps, | ||
): UpdateAndroidConnection => ({ | ||
type: ActionType.UPDATE_ANDROID_CONNECTION, | ||
channelId, | ||
connection, | ||
}); | ||
|
||
export const removeAndroidConnection = ( | ||
channelId: string, | ||
): RemoveAndroidConnection => ({ | ||
type: ActionType.REMOVE_ANDROID_CONNECTION, | ||
channelId, | ||
}); | ||
|
||
export const resetAndroidConnections = ( | ||
connections: SDKSessions, | ||
): ResetAndroidConnections => ({ | ||
type: ActionType.RESET_ANDROID_CONNECTIONS, | ||
connections, | ||
}); | ||
|
||
export const setConnected = ( | ||
channelId: string, | ||
connected: boolean, | ||
): SetConnected => ({ | ||
type: ActionType.SET_CONNECTED, | ||
channelId, | ||
connected, | ||
}); |
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,14 @@ | ||
import { ApprovedHosts, SDKSessions } from '../../core/SDKConnect/SDKConnect'; | ||
export interface WC2Metadata { | ||
id: string; | ||
url: string; | ||
name: string; | ||
icon: string; | ||
} | ||
export interface SDKState { | ||
connections: SDKSessions; | ||
approvedHosts: ApprovedHosts; | ||
androidConnections: SDKSessions; | ||
// Link to metadata of last created wallet connect session. | ||
wc2Metadata?: WC2Metadata; | ||
} |
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
4 changes: 2 additions & 2 deletions
4
app/components/Views/SDKSessionsManager/SDKSessionAccountListItem.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
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.