-
Notifications
You must be signed in to change notification settings - Fork 61
Add wallet settings #722
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
base: master
Are you sure you want to change the base?
Add wallet settings #722
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,8 @@ import { | |
| EdgeCurrencyTools, | ||
| EdgeCurrencyWallet, | ||
| EdgeTokenMap, | ||
| EdgeWalletInfo | ||
| EdgeWalletInfo, | ||
| JsonObject | ||
| } from '../../../types/types' | ||
| import { makeJsonFile } from '../../../util/file-helpers' | ||
| import { makePeriodicTask, PeriodicTask } from '../../../util/periodic-task' | ||
|
|
@@ -45,9 +46,14 @@ import { | |
| loadSeenTxCheckpointFile, | ||
| loadTokensFile, | ||
| loadTxFileNames, | ||
| loadWalletSettingsFile, | ||
| writeTokensFile | ||
| } from './currency-wallet-files' | ||
| import { CurrencyWalletState, initialTokenIds } from './currency-wallet-reducer' | ||
| import { | ||
| CurrencyWalletState, | ||
| initialTokenIds, | ||
| initialWalletSettings | ||
| } from './currency-wallet-reducer' | ||
| import { tokenIdsToCurrencyCodes, uniqueStrings } from './enabled-tokens' | ||
|
|
||
| export interface CurrencyWalletOutput { | ||
|
|
@@ -118,6 +124,11 @@ export const walletPixie: TamePixie<CurrencyWalletProps> = combinePixies({ | |
| // so the engine can start in the right state: | ||
| await loadTokensFile(input) | ||
|
|
||
| const { hasWalletSettings = false } = walletState.currencyInfo | ||
| if (hasWalletSettings) { | ||
| await loadWalletSettingsFile(input) | ||
| } | ||
|
|
||
| // Start the engine: | ||
| const accountState = state.accounts[accountId] | ||
| const engine = await plugin.makeCurrencyEngine(publicWalletInfo, { | ||
|
|
@@ -138,7 +149,8 @@ export const walletPixie: TamePixie<CurrencyWalletProps> = combinePixies({ | |
| // User settings: | ||
| customTokens: accountState.customTokens[pluginId] ?? {}, | ||
| enabledTokenIds: input.props.walletState.allEnabledTokenIds, | ||
| userSettings: accountState.userSettings[pluginId] ?? {} | ||
| userSettings: accountState.userSettings[pluginId] ?? {}, | ||
| walletSettings: input.props.walletState.walletSettings | ||
| }) | ||
| input.onOutput(engine) | ||
|
|
||
|
|
@@ -462,7 +474,8 @@ export const walletPixie: TamePixie<CurrencyWalletProps> = combinePixies({ | |
|
|
||
| watcher(input: CurrencyWalletInput) { | ||
| let lastState: CurrencyWalletState | undefined | ||
| let lastSettings: object = {} | ||
| let lastUserSettings: object = {} | ||
| let lastWalletSettings: JsonObject = initialWalletSettings | ||
| let lastTokens: EdgeTokenMap = {} | ||
| let lastEnabledTokenIds: string[] = initialTokenIds | ||
|
|
||
|
|
@@ -480,11 +493,12 @@ export const walletPixie: TamePixie<CurrencyWalletProps> = combinePixies({ | |
| lastState = walletState | ||
|
|
||
| // Update engine settings: | ||
| const userSettings = accountState.userSettings[pluginId] ?? lastSettings | ||
| if (lastSettings !== userSettings && engine != null) { | ||
| const userSettings = | ||
| accountState.userSettings[pluginId] ?? lastUserSettings | ||
| if (lastUserSettings !== userSettings && engine != null) { | ||
| await engine.changeUserSettings(userSettings) | ||
| } | ||
| lastSettings = userSettings | ||
| lastUserSettings = userSettings | ||
|
|
||
| // Update the custom tokens: | ||
| const customTokens = accountState.customTokens[pluginId] ?? lastTokens | ||
|
|
@@ -505,6 +519,26 @@ export const walletPixie: TamePixie<CurrencyWalletProps> = combinePixies({ | |
| } | ||
| lastTokens = customTokens | ||
|
|
||
| // Update wallet-scoped settings: | ||
| const { hasWalletSettings = false } = walletState.currencyInfo | ||
| const { walletSettings } = walletState | ||
| const settingsChanged = lastWalletSettings !== walletSettings | ||
|
|
||
| if ( | ||
| settingsChanged && | ||
| engine?.changeWalletSettings != null && | ||
| hasWalletSettings | ||
| ) { | ||
| input.props.log.warn( | ||
| `walletSettings applying: ${JSON.stringify(walletSettings)}` | ||
|
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. 🔒 Agentic Security Review Impact: Sensitive wallet configuration data could be disclosed through logs and any downstream log aggregation. |
||
| ) | ||
| await engine.changeWalletSettings(walletSettings).catch(error => { | ||
| input.props.log.warn(`walletSettings error: ${String(error)}`) | ||
| input.props.onError(error) | ||
|
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. Debug wallet settings warn logsLow Severity The wallet-settings watcher logs every apply and error at Reviewed by Cursor Bugbot for commit f87eace. Configure here. |
||
| }) | ||
| } | ||
| lastWalletSettings = walletSettings | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| // Update enabled tokens: | ||
| const { allEnabledTokenIds } = walletState | ||
| if (lastEnabledTokenIds !== allEnabledTokenIds && engine != null) { | ||
|
|
||


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.
CHANGELOG omits new
importedpublic API propertyLow Severity
The PR adds a new public
importedproperty onEdgeCurrencyWallet(in bothtypes.tsandcurrency-wallet-api.ts), but the CHANGELOG entry only coverswalletSettingsandchangeWalletSettings. Sinceimportedis a newly exposed API onEdgeCurrencyWallet, it warrants its ownadded:entry in the CHANGELOG.Additional Locations (2)
src/types/types.ts#L1334-L1335src/core/currency/wallet/currency-wallet-api.ts#L139-L142Triggered by learned rule: CHANGELOG entries must use correct semantic prefix
Reviewed by Cursor Bugbot for commit f87eace. Configure here.