Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,12 @@ export default [
'src/actions/FioAddressActions.ts',
'src/actions/FirstOpenActions.tsx',
'src/actions/LoanWelcomeActions.tsx',
'src/actions/LocalSettingsActions.ts',

'src/actions/LoginActions.tsx',
'src/actions/NotificationActions.ts',
'src/actions/PaymentProtoActions.tsx',
'src/actions/ReceiveDropdown.tsx',
'src/actions/RecoveryReminderActions.tsx',
'src/actions/RequestReviewActions.tsx',

'src/actions/ScamWarningActions.tsx',
'src/actions/ScanActions.tsx',

Expand Down Expand Up @@ -290,10 +288,9 @@ export default [
'src/components/scenes/OtpSettingsScene.tsx',
'src/components/scenes/PasswordRecoveryScene.tsx',
'src/components/scenes/PromotionSettingsScene.tsx',
'src/components/scenes/ReviewTriggerTestScene.tsx',

'src/components/scenes/SecurityAlertsScene.tsx',

'src/components/scenes/SettingsScene.tsx',
'src/components/scenes/SpendingLimitsScene.tsx',
'src/components/scenes/Staking/EarnScene.tsx',
'src/components/scenes/Staking/StakeModifyScene.tsx',
Expand All @@ -311,7 +308,7 @@ export default [
'src/components/scenes/TransactionListScene.tsx',
'src/components/scenes/TransactionsExportScene.tsx',
'src/components/scenes/UpgradeUsernameScreen.tsx',
'src/components/scenes/WalletListScene.tsx',

'src/components/scenes/WalletRestoreScene.tsx',
'src/components/scenes/WcConnectionsScene.tsx',
'src/components/scenes/WcConnectScene.tsx',
Expand Down Expand Up @@ -487,9 +484,7 @@ export default [
'src/plugins/stake-plugins/util/builder.ts',
'src/reducers/ExchangeInfoReducer.ts',
'src/reducers/NetworkReducer.ts',
'src/reducers/PasswordReminderReducer.ts',

'src/reducers/SpendingLimitsReducer.ts',
'src/selectors/getCreateWalletList.ts',
'src/selectors/SettingsSelectors.ts',
'src/state/createStateProvider.tsx',
Expand Down
10 changes: 8 additions & 2 deletions src/__tests__/actions/RequestReviewActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { makeMemoryDisklet } from 'disklet'
import type { EdgeAccount } from 'edge-core-js'
import type { Action, Dispatch } from 'redux'

import { LOCAL_SETTINGS_FILENAME } from '../../actions/LocalSettingsActions'
import {
LOCAL_SETTINGS_FILENAME,
LOCAL_SETTINGS_FILENAME_OPTIMIZED
} from '../../actions/LocalSettingsActions'
import {
DEPOSIT_AMOUNT_THRESHOLD,
FIAT_PURCHASE_COUNT_THRESHOLD,
Expand Down Expand Up @@ -321,7 +324,10 @@ describe('RequestReviewActions', () => {
expect(readData.swapCount).toBe(7)

// Also verify that the data was written to settings file
const settingsJson = await testDisklet.getText(LOCAL_SETTINGS_FILENAME)
// Note: writeLocalAccountSettings writes to the optimized filename
const settingsJson = await testDisklet.getText(
LOCAL_SETTINGS_FILENAME_OPTIMIZED
)
const settings = JSON.parse(settingsJson) as LocalAccountSettings
expect(settings.reviewTrigger?.swapCount).toBe(7)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ exports[`initialState 1`] = `
"defaultFiat": "USD",
"defaultIsoFiat": "iso:USD",
"denominationSettings": {},
"denominationSettingsOptimized": false,
"developerModeOn": false,
"isAccountBalanceVisible": true,
"isTouchEnabled": false,
"isTouchSupported": false,
"mostRecentWallets": [],
"notifState": {},
"passwordRecoveryRemindersShown": {
Expand All @@ -134,7 +133,6 @@ exports[`initialState 1`] = `
"nonPasswordLoginsLimit": 4,
"passwordUseCount": 0,
},
"pinLoginEnabled": false,
"preferredSwapPluginId": undefined,
"preferredSwapPluginType": undefined,
"rampLastCryptoSelection": undefined,
Expand Down
12 changes: 7 additions & 5 deletions src/__tests__/spendingLimits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ describe('spendingLimits', () => {
describe('when logging in', () => {
it('should update', () => {
const actual = spendingLimits(initialState, {
type: 'ACCOUNT_INIT_COMPLETE',
type: 'LOGIN',
data: {
spendingLimits: {
transaction: {
isEnabled: false,
amount: 150
localSettings: {
spendingLimits: {
transaction: {
isEnabled: false,
amount: 150
}
}
}
} as any
Expand Down
29 changes: 25 additions & 4 deletions src/actions/LocalSettingsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
import { logActivity } from '../util/logger'

export const LOCAL_SETTINGS_FILENAME = 'Settings.json'
// TODO: Remove before merging PR - used for performance testing only
export const LOCAL_SETTINGS_FILENAME_OPTIMIZED = 'Settings-optimized.json'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Test code with alternate filenames not removed before merge

The code introduces alternate settings filenames (Settings-optimized.json instead of Settings.json) that are explicitly marked with TODO comments stating "Remove before merging PR - used for performance testing only". The writeLocalAccountSettings and writeSyncedSettings functions write to these alternate files, while the read functions try the optimized file first. This will cause settings to be written to different files than existing users expect, potentially losing user settings or creating inconsistent state between old and new settings files.

Additional Locations (2)

Fix in Cursor Fix in Web


let localAccountSettings: LocalAccountSettings = asLocalAccountSettings({})
const [watchAccountSettings, emitAccountSettings] =
Expand All @@ -33,7 +35,7 @@ export const getLocalAccountSettings = async (
return settings
}

export function useAccountSettings() {
export function useAccountSettings(): LocalAccountSettings {
const [accountSettings, setAccountSettings] =
React.useState(localAccountSettings)
React.useEffect(() => watchAccountSettings(setAccountSettings), [])
Expand Down Expand Up @@ -261,16 +263,34 @@ export const writeTokenWarningsShown = async (
export const readLocalAccountSettings = async (
account: EdgeAccount
): Promise<LocalAccountSettings> => {
// TODO: Remove LOCAL_SETTINGS_FILENAME_OPTIMIZED logic before merging PR
// Try optimized file first, then fall back to original file
try {
const text = await account.localDisklet.getText(
LOCAL_SETTINGS_FILENAME_OPTIMIZED
)
const json = JSON.parse(text)
const settings = asLocalAccountSettings(json)
emitAccountSettings(settings)
readSettingsFromDisk = true
return settings
} catch (error: unknown) {
// Optimized file doesn't exist, try original file
}

try {
const text = await account.localDisklet.getText(LOCAL_SETTINGS_FILENAME)
const json = JSON.parse(text)
const settings = asLocalAccountSettings(json)
emitAccountSettings(settings)
readSettingsFromDisk = true
return settings
} catch (e) {
} catch (error: unknown) {
// If Settings.json doesn't exist yet, return defaults without writing.
// Defaults can be derived from cleaners. Only write when values change.
const defaults = asLocalAccountSettings({})
return await writeLocalAccountSettings(account, defaults)
emitAccountSettings(defaults)
return defaults
}
}

Expand All @@ -282,7 +302,8 @@ export const writeLocalAccountSettings = async (
emitAccountSettings(settings)

const text = JSON.stringify(settings)
await account.localDisklet.setText(LOCAL_SETTINGS_FILENAME, text)
// TODO: Change back to LOCAL_SETTINGS_FILENAME before merging PR
await account.localDisklet.setText(LOCAL_SETTINGS_FILENAME_OPTIMIZED, text)

return settings
}
Loading
Loading