Skip to content

Commit

Permalink
Settings randomizer
Browse files Browse the repository at this point in the history
hsjoberg committed Nov 28, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent f0678b7 commit 48fd682
Showing 4 changed files with 205 additions and 1 deletion.
6 changes: 6 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
@@ -910,6 +910,12 @@
},
"customInvoicePreimageEnabled": {
"title": "Enable custom invoice preimages"
},
"randomizeSettings": {
"title": "Randomize settings"
},
"randomizeSettingsOnStartup": {
"title": "Randomize settings on startup"
}
},
"experimental": {
160 changes: 159 additions & 1 deletion src/state/Settings.ts
Original file line number Diff line number Diff line change
@@ -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");

@@ -93,6 +94,7 @@ export interface ISettingsModel {
changeLightningBoxServer: Thunk<ISettingsModel, string>;
changeLightningBoxAddress: Thunk<ISettingsModel, string>;
changeLightningBoxLnurlPayDesc: Thunk<ISettingsModel, string>;
changeRandomizeSettingsOnStartup: Thunk<ISettingsModel, boolean>;

setBitcoinUnit: Action<ISettingsModel, keyof IBitcoinUnits>;
setFiatUnit: Action<ISettingsModel, keyof IFiatRates>;
@@ -141,6 +143,7 @@ export interface ISettingsModel {
setLightningBoxServer: Action<ISettingsModel, string>;
setLightningBoxAddress: Action<ISettingsModel, string>;
SetLightningBoxLnurlPayDesc: Action<ISettingsModel, string>;
setRandomizeSettingsOnStartup: Action<ISettingsModel, boolean>;

bitcoinUnit: keyof IBitcoinUnits;
fiatUnit: keyof IFiatRates;
@@ -189,11 +192,22 @@ export interface ISettingsModel {
lightningBoxServer: string;
lightningBoxAddress: string;
lightningBoxLnurlPayDesc: string;
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.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);
@@ -526,6 +540,11 @@ export const settings: ISettingsModel = {
actions.SetLightningBoxLnurlPayDesc(payload);
}),

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

setBitcoinUnit: action((state, payload) => {
state.bitcoinUnit = payload;
}),
@@ -667,6 +686,9 @@ export const settings: ISettingsModel = {
SetLightningBoxLnurlPayDesc: action((state, payload) => {
state.lightningBoxLnurlPayDesc = payload;
}),
setRandomizeSettingsOnStartup: action((state, payload) => {
state.randomizeSettingsOnStartup = payload;
}),

bitcoinUnit: "bitcoin",
fiatUnit: "USD",
@@ -715,4 +737,140 @@ export const settings: ISettingsModel = {
lightningBoxServer: DEFAULT_LIGHTNINGBOX_SERVER,
lightningBoxAddress: "",
lightningBoxLnurlPayDesc: DEFAULT_LIGHTNINGBOX_LNURLPDESC,
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());
}),
};

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
@@ -89,6 +89,7 @@ export enum StorageItem { // const enums not supported in Babel 7...
lightningBoxServer = "lightningBoxServer",
lightningBoxAddress = "lightningBoxAddress",
lightningBoxLnurlPayDesc = "lightningBoxLnurlPayDesc",
randomizeSettingsOnStartup = "randomizeSettingsOnStartup",
}

export const setItem = async (key: StorageItem, value: string) =>
@@ -192,6 +193,7 @@ export const clearApp = async () => {
removeItem(StorageItem.lightningBoxServer),
removeItem(StorageItem.lightningBoxAddress),
removeItem(StorageItem.lightningBoxLnurlPayDesc),
removeItem(StorageItem.randomizeSettingsOnStartup),
]);
};

@@ -283,5 +285,6 @@ export const setupApp = async () => {
setItem(StorageItem.lightningBoxServer, DEFAULT_LIGHTNINGBOX_SERVER),
// setItem(StorageItem.lightningBoxAddress, ""),
setItem(StorageItem.lightningBoxLnurlPayDesc, DEFAULT_LIGHTNINGBOX_LNURLPDESC),
setItemObject<boolean>(StorageItem.randomizeSettingsOnStartup, false),
]);
};
37 changes: 37 additions & 0 deletions src/windows/Settings/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1517,6 +1517,21 @@ ${t("experimental.tor.disabled.msg2")}`;
);
};

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 }}>
@@ -2181,6 +2196,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>

0 comments on commit 48fd682

Please sign in to comment.