Skip to content

Commit

Permalink
Settings randomizer
Browse files Browse the repository at this point in the history
  • Loading branch information
hsjoberg committed Nov 27, 2023
1 parent f0678b7 commit d0cfaee
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 1 deletion.
6 changes: 6 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,12 @@
},
"customInvoicePreimageEnabled": {
"title": "Enable custom invoice preimages"
},
"randomizeSettings": {
"title": "Randomize settings"
},
"randomizeSettingsOnStartup": {
"title": "Randomize settings on startup"
}
},
"experimental": {
Expand Down
161 changes: 160 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 @@ -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>;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -189,11 +192,23 @@ 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);
Expand Down Expand Up @@ -526,6 +541,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;
}),
Expand Down Expand Up @@ -667,6 +687,9 @@ export const settings: ISettingsModel = {
SetLightningBoxLnurlPayDesc: action((state, payload) => {
state.lightningBoxLnurlPayDesc = payload;
}),
setRandomizeSettingsOnStartup: action((state, payload) => {
state.randomizeSettingsOnStartup = payload;
}),

bitcoinUnit: "bitcoin",
fiatUnit: "USD",
Expand Down Expand Up @@ -715,4 +738,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
Expand Up @@ -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) =>
Expand Down Expand Up @@ -192,6 +193,7 @@ export const clearApp = async () => {
removeItem(StorageItem.lightningBoxServer),
removeItem(StorageItem.lightningBoxAddress),
removeItem(StorageItem.lightningBoxLnurlPayDesc),
removeItem(StorageItem.randomizeSettingsOnStartup),
]);
};

Expand Down Expand Up @@ -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
Expand Up @@ -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 }}>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit d0cfaee

Please sign in to comment.