diff --git a/locales/en.json b/locales/en.json index c09cd4724..7ecf35e48 100644 --- a/locales/en.json +++ b/locales/en.json @@ -925,6 +925,12 @@ }, "customInvoicePreimageEnabled": { "title": "Enable custom invoice preimages" + }, + "randomizeSettings": { + "title": "Randomize settings" + }, + "randomizeSettingsOnStartup": { + "title": "Randomize settings on startup" } }, "experimental": { diff --git a/src/state/Settings.ts b/src/state/Settings.ts index aea51237f..686a0211e 100644 --- a/src/state/Settings.ts +++ b/src/state/Settings.ts @@ -23,12 +23,13 @@ import { } from "../storage/app"; import { Chain } from "../utils/build"; -import { IBitcoinUnits } from "../utils/bitcoin-units"; +import { BitcoinUnits, IBitcoinUnits } from "../utils/bitcoin-units"; import { IFiatRates } from "./Fiat"; import { IStoreModel } from "./index"; import { MapStyle } from "../utils/google-maps"; import { i18n } from "../i18n/i18n"; import logger from "./../utils/log"; +import { languages } from "../i18n/i18n.constants"; const log = logger("Settings"); @@ -94,6 +95,7 @@ export interface ISettingsModel { changeLightningBoxAddress: Thunk; changeLightningBoxLnurlPayDesc: Thunk; changeHideAmountsEnabled: Thunk; + changeRandomizeSettingsOnStartup: Thunk; setBitcoinUnit: Action; setFiatUnit: Action; @@ -143,6 +145,7 @@ export interface ISettingsModel { setLightningBoxAddress: Action; SetLightningBoxLnurlPayDesc: Action; setHideAmountsEnabled: Action; + setRandomizeSettingsOnStartup: Action; bitcoinUnit: keyof IBitcoinUnits; fiatUnit: keyof IFiatRates; @@ -192,11 +195,23 @@ export interface ISettingsModel { lightningBoxAddress: string; lightningBoxLnurlPayDesc: string; hideAmountsEnabled: boolean; + randomizeSettingsOnStartup: boolean; + + randomize: Thunk; } export const settings: ISettingsModel = { initialize: thunk(async (actions) => { log.d("Initializing"); + const randomizeSettingsOnStartup = + (await getItemObject(StorageItem.randomizeSettingsOnStartup)) ?? false; + if (randomizeSettingsOnStartup) { + actions.setRandomizeSettingsOnStartup(randomizeSettingsOnStartup); + actions.randomize(); + return; + } + actions.setRandomizeSettingsOnStartup(randomizeSettingsOnStartup); + actions.setBitcoinUnit((await getItemObject(StorageItem.bitcoinUnit)) || "bitcoin"); actions.setFiatUnit((await getItemObject(StorageItem.fiatUnit)) || "USD"); actions.setName((await getItemObject(StorageItem.name)) || null); @@ -537,6 +552,11 @@ export const settings: ISettingsModel = { actions.setHideAmountsEnabled(payload); }), + changeRandomizeSettingsOnStartup: thunk(async (actions, payload) => { + await setItemObject(StorageItem.randomizeSettingsOnStartup, payload); + actions.setRandomizeSettingsOnStartup(payload); + }), + setBitcoinUnit: action((state, payload) => { state.bitcoinUnit = payload; }), @@ -682,6 +702,10 @@ export const settings: ISettingsModel = { state.hideAmountsEnabled = payload; }), + setRandomizeSettingsOnStartup: action((state, payload) => { + state.randomizeSettingsOnStartup = payload; + }), + bitcoinUnit: "bitcoin", fiatUnit: "USD", name: null, @@ -730,4 +754,141 @@ export const settings: ISettingsModel = { lightningBoxAddress: "", lightningBoxLnurlPayDesc: DEFAULT_LIGHTNINGBOX_LNURLPDESC, hideAmountsEnabled: false, + randomizeSettingsOnStartup: false, + + randomize: thunk((state, _, { getStoreState, dispatch }) => { + const bitcoinUnits = Object.keys(BitcoinUnits); + state.setBitcoinUnit(getRandomFromArray(bitcoinUnits)); + + const fiatUnits = Object.keys(getStoreState().fiat.fiatRates); + state.setFiatUnit(getRandomFromArray(fiatUnits)); + + state.setName(getRandomFromArray(funnyNames)); + + const language = getRandomFromArray(Object.keys(languages)); + state.setLanguage(getRandomFromArray(language)); + i18n.changeLanguage(language); + + const autopilotEnabled = rand(0, 1) === 1; + state.setAutopilotEnabled(autopilotEnabled); + dispatch.lightning.setupAutopilot(autopilotEnabled); + + state.setPushNotificationsEnabled(rand(0, 1) === 1); + state.setClipboardInvoiceCheckInvoicesEnabled(rand(0, 1) === 1); + // state.scheduledSyncEnabled; + // state.scheduledGossipSyncEnabled; + state.setDebugShowStartupInfo(rand(0, 1) === 1); + // state.googleDriveBackupEnabled; + state.setPreferFiat(rand(0, 1) === 1); + // state.transactionGeolocationEnabled; + // state.transactionGeolocationMapStyle; + const onchainExplorers = Object.keys(OnchainExplorer); + state.setOnchainExplorer(getRandomFromArray(onchainExplorers)); + state.setMultiPathPaymentsEnabled(rand(0, 1) === 1); + // state.torEnabled; + state.setHideExpiredInvoices(rand(0, 1) === 1); + state.setScreenTransitionsEnabled(rand(0, 1) === 1); + // state.iCloudBackupEnabled; + // state.lndChainBackend; + // state.neutrinoPeers; + // state.bitcoindRpcHost; + // state.bitcoindRpcUser; + // state.bitcoindRpcPassword; + // state.bitcoindPubRawBlock; + // state.bitcoindPubRawTx; + // state.dunderServer; + state.setRequireGraphSync(rand(0, 1) === 1); + state.setDunderEnabled(rand(0, 1) === 1); + // state.lndNoGraphCache; + state.setInvoiceExpiry(rand(0, 1000)); // TODO + // state.rescanWallet; + // state.strictGraphPruningEnabled; + // state.lndPathfindingAlgorithm; + state.setMaxLNFeePercentage(rand(0, 100) / 10); + // state.lndLogLevel; + // state.lndCompactDb; + // state.zeroConfPeers; + // state.enforceSpeedloaderOnStartup; + // state.persistentServicesEnabled; + // state.persistentServicesWarningShown; + // state.customInvoicePreimageEnabled; + state.setCustomInvoicePreimageEnabled(rand(0, 1) === 1); + // state.speedloaderServer; + // state.lightningBoxServer; + // state.lightningBoxAddress; + state.SetLightningBoxLnurlPayDesc(generateGarbageText()); + state.setHideAmountsEnabled(rand(0, 1) === 1); + }), }; + +function rand(min: number, max: number): number { + return Math.floor(Math.random() * (max - min + 1)) + min; +} + +function getRandomFromArray(arr: any[]) { + return arr[rand(0, arr.length - 1)]; +} + +function generateGarbageText(): string { + // Add any weird characters you want to this string + const characters = + 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~`!@#$%^&*()_-+={[}]|\\:;"<,>.?/⊙△ΩβφÇ'; + const length = Math.floor(Math.random() * 20) + 4; // This will give a random number between 4 and 16 + + return [...Array(length)] + .map(() => characters[Math.floor(Math.random() * characters.length)]) + .join(""); +} + +const funnyNames = [ + "Binky", + "Fido", + "Peaches", + "Puddles", + "Snickers", + "Wiggles", + "Twinkle", + "Pickles", + "Muffin", + "Giggles", + "Bubbles", + "Ziggy", + "Noodle", + "Doodle", + "Pookie", + "Fluffy", + "Sprinkles", + "Jingles", + "Boogie", + "Winky", + "Tootsie", + "Fuzzy", + "Spunky", + "Goober", + "Snuggles", + "Scrappy", + "Puddin'", + "Biscuit", + "Doogie", + "Waffle", + "Zippy", + "Jolly", + "Sassy", + "Rascal", + "Boppy", + "Cuddles", + "Dinky", + "Fiddle", + "Gadget", + "Hopper", + "Jester", + "Kiki", + "Lollipop", + "Mimi", + "Nibbles", + "Oreo", + "Peppy", + "Quirky", + "Roo", + "Sprout", +]; diff --git a/src/storage/app.ts b/src/storage/app.ts index ee1a53707..3c37d2daf 100644 --- a/src/storage/app.ts +++ b/src/storage/app.ts @@ -90,6 +90,7 @@ export enum StorageItem { // const enums not supported in Babel 7... lightningBoxAddress = "lightningBoxAddress", lightningBoxLnurlPayDesc = "lightningBoxLnurlPayDesc", hideAmountsEnabled = "hideAmountsEnabled", + randomizeSettingsOnStartup = "randomizeSettingsOnStartup", } export const setItem = async (key: StorageItem, value: string) => @@ -194,6 +195,7 @@ export const clearApp = async () => { removeItem(StorageItem.lightningBoxAddress), removeItem(StorageItem.lightningBoxLnurlPayDesc), removeItem(StorageItem.hideAmountsEnabled), + removeItem(StorageItem.randomizeSettingsOnStartup), ]); }; @@ -286,5 +288,6 @@ export const setupApp = async () => { // setItem(StorageItem.lightningBoxAddress, ""), setItem(StorageItem.lightningBoxLnurlPayDesc, DEFAULT_LIGHTNINGBOX_LNURLPDESC), setItemObject(StorageItem.hideAmountsEnabled, false), + setItemObject(StorageItem.randomizeSettingsOnStartup, false), ]); }; diff --git a/src/windows/Settings/Settings.tsx b/src/windows/Settings/Settings.tsx index 3648aea76..782b5bd19 100644 --- a/src/windows/Settings/Settings.tsx +++ b/src/windows/Settings/Settings.tsx @@ -1559,6 +1559,22 @@ ${t("experimental.tor.disabled.msg2")}`; await changeLndChainBackend("neutrino"); }; + // Randomize settings + const randomize = useStoreActions((store) => store.settings.randomize); + const onPressRandomize = async () => { + await randomize(); + }; + + const randomizeSettingsOnStartup = useStoreState( + (store) => store.settings.randomizeSettingsOnStartup, + ); + const changeRandomizeSettingsOnStartup = useStoreActions( + (store) => store.settings.changeRandomizeSettingsOnStartup, + ); + const onToggleRandomizeSettingsOnStartup = async () => { + await changeRandomizeSettingsOnStartup(!randomizeSettingsOnStartup); + }; + return ( @@ -2237,6 +2253,28 @@ ${t("experimental.tor.disabled.msg2")}`; /> + + + + + + {t("miscelaneous.randomizeSettings.title")} + + + + + + + + {t("miscelaneous.randomizeSettingsOnStartup.title")} + + + + + {/*