Skip to content
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

Settings randomizer #1384

Merged
merged 1 commit into from
Jun 24, 2024
Merged
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
6 changes: 6 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,12 @@
},
"customInvoicePreimageEnabled": {
"title": "Enable custom invoice preimages"
},
"randomizeSettings": {
"title": "Randomize settings"
},
"randomizeSettingsOnStartup": {
"title": "Randomize settings on startup"
}
},
"experimental": {
Expand Down
163 changes: 162 additions & 1 deletion src/state/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -94,6 +95,7 @@ export interface ISettingsModel {
changeLightningBoxAddress: Thunk<ISettingsModel, string>;
changeLightningBoxLnurlPayDesc: Thunk<ISettingsModel, string>;
changeHideAmountsEnabled: Thunk<ISettingsModel, boolean>;
changeRandomizeSettingsOnStartup: Thunk<ISettingsModel, boolean>;

setBitcoinUnit: Action<ISettingsModel, keyof IBitcoinUnits>;
setFiatUnit: Action<ISettingsModel, keyof IFiatRates>;
Expand Down Expand Up @@ -143,6 +145,7 @@ export interface ISettingsModel {
setLightningBoxAddress: Action<ISettingsModel, string>;
SetLightningBoxLnurlPayDesc: Action<ISettingsModel, string>;
setHideAmountsEnabled: Action<ISettingsModel, boolean>;
setRandomizeSettingsOnStartup: Action<ISettingsModel, boolean>;

bitcoinUnit: keyof IBitcoinUnits;
fiatUnit: keyof IFiatRates;
Expand Down Expand Up @@ -192,11 +195,23 @@ export interface ISettingsModel {
lightningBoxAddress: string;
lightningBoxLnurlPayDesc: string;
hideAmountsEnabled: boolean;
randomizeSettingsOnStartup: boolean;

randomize: Thunk<ISettingsModel, void, any, IStoreModel>;
}

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);
Expand Down Expand Up @@ -537,6 +552,11 @@ export const settings: ISettingsModel = {
actions.setHideAmountsEnabled(payload);
}),

changeRandomizeSettingsOnStartup: thunk(async (actions, payload) => {
await setItemObject<boolean>(StorageItem.randomizeSettingsOnStartup, payload);
actions.setRandomizeSettingsOnStartup(payload);
}),

setBitcoinUnit: action((state, payload) => {
state.bitcoinUnit = payload;
}),
Expand Down Expand Up @@ -682,6 +702,10 @@ export const settings: ISettingsModel = {
state.hideAmountsEnabled = payload;
}),

setRandomizeSettingsOnStartup: action((state, payload) => {
state.randomizeSettingsOnStartup = payload;
}),

bitcoinUnit: "bitcoin",
fiatUnit: "USD",
name: null,
Expand Down Expand Up @@ -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",
];
3 changes: 3 additions & 0 deletions src/storage/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -194,6 +195,7 @@ export const clearApp = async () => {
removeItem(StorageItem.lightningBoxAddress),
removeItem(StorageItem.lightningBoxLnurlPayDesc),
removeItem(StorageItem.hideAmountsEnabled),
removeItem(StorageItem.randomizeSettingsOnStartup),
]);
};

Expand Down Expand Up @@ -286,5 +288,6 @@ export const setupApp = async () => {
// setItem(StorageItem.lightningBoxAddress, ""),
setItem(StorageItem.lightningBoxLnurlPayDesc, DEFAULT_LIGHTNINGBOX_LNURLPDESC),
setItemObject<boolean>(StorageItem.hideAmountsEnabled, false),
setItemObject<boolean>(StorageItem.randomizeSettingsOnStartup, false),
]);
};
38 changes: 38 additions & 0 deletions src/windows/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Container>
<Content style={{ padding: 10 }}>
Expand Down Expand Up @@ -2237,6 +2253,28 @@ ${t("experimental.tor.disabled.msg2")}`;
/>
</Right>
</ListItem>
<ListItem style={style.listItem} icon={true} onPress={onPressRandomize}>
<Left>
<Icon style={style.icon} type="MaterialCommunityIcons" name="emoticon-cool" />
</Left>
<Body>
<Text>{t("miscelaneous.randomizeSettings.title")}</Text>
</Body>
</ListItem>
<ListItem style={style.listItem} icon={true} onPress={onToggleRandomizeSettingsOnStartup}>
<Left>
<Icon style={style.icon} type="MaterialCommunityIcons" name="emoticon-cool" />
</Left>
<Body>
<Text>{t("miscelaneous.randomizeSettingsOnStartup.title")}</Text>
</Body>
<Right>
<CheckBox
checked={randomizeSettingsOnStartup}
onPress={onToggleRandomizeSettingsOnStartup}
/>
</Right>
</ListItem>

{/* <ListItem style={style.listItem} icon={true} onPress={onPressDeleteWallet}>
<Left><Icon style={style.icon} type="FontAwesome5" name="file-signature" /></Left>
Expand Down
Loading