@@ -23,12 +23,13 @@ import {
23
23
} from "../storage/app" ;
24
24
25
25
import { Chain } from "../utils/build" ;
26
- import { IBitcoinUnits } from "../utils/bitcoin-units" ;
26
+ import { BitcoinUnits , IBitcoinUnits } from "../utils/bitcoin-units" ;
27
27
import { IFiatRates } from "./Fiat" ;
28
28
import { IStoreModel } from "./index" ;
29
29
import { MapStyle } from "../utils/google-maps" ;
30
30
import { i18n } from "../i18n/i18n" ;
31
31
import logger from "./../utils/log" ;
32
+ import { languages } from "../i18n/i18n.constants" ;
32
33
33
34
const log = logger ( "Settings" ) ;
34
35
@@ -93,6 +94,7 @@ export interface ISettingsModel {
93
94
changeLightningBoxServer : Thunk < ISettingsModel , string > ;
94
95
changeLightningBoxAddress : Thunk < ISettingsModel , string > ;
95
96
changeLightningBoxLnurlPayDesc : Thunk < ISettingsModel , string > ;
97
+ changeRandomizeSettingsOnStartup : Thunk < ISettingsModel , boolean > ;
96
98
97
99
setBitcoinUnit : Action < ISettingsModel , keyof IBitcoinUnits > ;
98
100
setFiatUnit : Action < ISettingsModel , keyof IFiatRates > ;
@@ -141,6 +143,7 @@ export interface ISettingsModel {
141
143
setLightningBoxServer : Action < ISettingsModel , string > ;
142
144
setLightningBoxAddress : Action < ISettingsModel , string > ;
143
145
SetLightningBoxLnurlPayDesc : Action < ISettingsModel , string > ;
146
+ setRandomizeSettingsOnStartup : Action < ISettingsModel , boolean > ;
144
147
145
148
bitcoinUnit : keyof IBitcoinUnits ;
146
149
fiatUnit : keyof IFiatRates ;
@@ -189,11 +192,23 @@ export interface ISettingsModel {
189
192
lightningBoxServer : string ;
190
193
lightningBoxAddress : string ;
191
194
lightningBoxLnurlPayDesc : string ;
195
+ randomizeSettingsOnStartup : boolean ;
196
+
197
+ randomize : Thunk < ISettingsModel , void , any , IStoreModel > ;
192
198
}
193
199
194
200
export const settings : ISettingsModel = {
195
201
initialize : thunk ( async ( actions ) => {
196
202
log . d ( "Initializing" ) ;
203
+ const randomizeSettingsOnStartup = await getItemObject (
204
+ StorageItem . randomizeSettingsOnStartup || false ,
205
+ ) ;
206
+ if ( randomizeSettingsOnStartup ) {
207
+ actions . randomize ( ) ;
208
+ return ;
209
+ }
210
+ actions . setRandomizeSettingsOnStartup ( randomizeSettingsOnStartup ) ;
211
+
197
212
actions . setBitcoinUnit ( ( await getItemObject ( StorageItem . bitcoinUnit ) ) || "bitcoin" ) ;
198
213
actions . setFiatUnit ( ( await getItemObject ( StorageItem . fiatUnit ) ) || "USD" ) ;
199
214
actions . setName ( ( await getItemObject ( StorageItem . name ) ) || null ) ;
@@ -526,6 +541,11 @@ export const settings: ISettingsModel = {
526
541
actions . SetLightningBoxLnurlPayDesc ( payload ) ;
527
542
} ) ,
528
543
544
+ changeRandomizeSettingsOnStartup : thunk ( async ( actions , payload ) => {
545
+ await setItemObject < boolean > ( StorageItem . randomizeSettingsOnStartup , payload ) ;
546
+ actions . setRandomizeSettingsOnStartup ( payload ) ;
547
+ } ) ,
548
+
529
549
setBitcoinUnit : action ( ( state , payload ) => {
530
550
state . bitcoinUnit = payload ;
531
551
} ) ,
@@ -667,6 +687,9 @@ export const settings: ISettingsModel = {
667
687
SetLightningBoxLnurlPayDesc : action ( ( state , payload ) => {
668
688
state . lightningBoxLnurlPayDesc = payload ;
669
689
} ) ,
690
+ setRandomizeSettingsOnStartup : action ( ( state , payload ) => {
691
+ state . randomizeSettingsOnStartup = payload ;
692
+ } ) ,
670
693
671
694
bitcoinUnit : "bitcoin" ,
672
695
fiatUnit : "USD" ,
@@ -715,4 +738,140 @@ export const settings: ISettingsModel = {
715
738
lightningBoxServer : DEFAULT_LIGHTNINGBOX_SERVER ,
716
739
lightningBoxAddress : "" ,
717
740
lightningBoxLnurlPayDesc : DEFAULT_LIGHTNINGBOX_LNURLPDESC ,
741
+ randomizeSettingsOnStartup : false ,
742
+
743
+ randomize : thunk ( ( state , _ , { getStoreState, dispatch } ) => {
744
+ const bitcoinUnits = Object . keys ( BitcoinUnits ) ;
745
+ state . setBitcoinUnit ( getRandomFromArray ( bitcoinUnits ) ) ;
746
+
747
+ const fiatUnits = Object . keys ( getStoreState ( ) . fiat . fiatRates ) ;
748
+ state . setFiatUnit ( getRandomFromArray ( fiatUnits ) ) ;
749
+
750
+ state . setName ( getRandomFromArray ( funnyNames ) ) ;
751
+
752
+ const language = getRandomFromArray ( Object . keys ( languages ) ) ;
753
+ state . setLanguage ( getRandomFromArray ( language ) ) ;
754
+ i18n . changeLanguage ( language ) ;
755
+
756
+ const autopilotEnabled = rand ( 0 , 1 ) === 1 ;
757
+ state . setAutopilotEnabled ( autopilotEnabled ) ;
758
+ dispatch . lightning . setupAutopilot ( autopilotEnabled ) ;
759
+
760
+ state . setPushNotificationsEnabled ( rand ( 0 , 1 ) === 1 ) ;
761
+ state . setClipboardInvoiceCheckInvoicesEnabled ( rand ( 0 , 1 ) === 1 ) ;
762
+ // state.scheduledSyncEnabled;
763
+ // state.scheduledGossipSyncEnabled;
764
+ state . setDebugShowStartupInfo ( rand ( 0 , 1 ) === 1 ) ;
765
+ // state.googleDriveBackupEnabled;
766
+ state . setPreferFiat ( rand ( 0 , 1 ) === 1 ) ;
767
+ // state.transactionGeolocationEnabled;
768
+ // state.transactionGeolocationMapStyle;
769
+ const onchainExplorers = Object . keys ( OnchainExplorer ) ;
770
+ state . setOnchainExplorer ( getRandomFromArray ( onchainExplorers ) ) ;
771
+ state . setMultiPathPaymentsEnabled ( rand ( 0 , 1 ) === 1 ) ;
772
+ // state.torEnabled;
773
+ state . setHideExpiredInvoices ( rand ( 0 , 1 ) === 1 ) ;
774
+ state . setScreenTransitionsEnabled ( rand ( 0 , 1 ) === 1 ) ;
775
+ // state.iCloudBackupEnabled;
776
+ // state.lndChainBackend;
777
+ // state.neutrinoPeers;
778
+ // state.bitcoindRpcHost;
779
+ // state.bitcoindRpcUser;
780
+ // state.bitcoindRpcPassword;
781
+ // state.bitcoindPubRawBlock;
782
+ // state.bitcoindPubRawTx;
783
+ // state.dunderServer;
784
+ state . setRequireGraphSync ( rand ( 0 , 1 ) === 1 ) ;
785
+ state . setDunderEnabled ( rand ( 0 , 1 ) === 1 ) ;
786
+ // state.lndNoGraphCache;
787
+ state . setInvoiceExpiry ( rand ( 0 , 1000 ) ) ; // TODO
788
+ // state.rescanWallet;
789
+ // state.strictGraphPruningEnabled;
790
+ // state.lndPathfindingAlgorithm;
791
+ state . setMaxLNFeePercentage ( rand ( 0 , 100 ) / 10 ) ;
792
+ // state.lndLogLevel;
793
+ // state.lndCompactDb;
794
+ // state.zeroConfPeers;
795
+ // state.enforceSpeedloaderOnStartup;
796
+ // state.persistentServicesEnabled;
797
+ // state.persistentServicesWarningShown;
798
+ // state.customInvoicePreimageEnabled;
799
+ state . setCustomInvoicePreimageEnabled ( rand ( 0 , 1 ) === 1 ) ;
800
+ // state.speedloaderServer;
801
+ // state.lightningBoxServer;
802
+ // state.lightningBoxAddress;
803
+ state . SetLightningBoxLnurlPayDesc ( generateGarbageText ( ) ) ;
804
+ } ) ,
718
805
} ;
806
+
807
+ function rand ( min : number , max : number ) : number {
808
+ return Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ;
809
+ }
810
+
811
+ function getRandomFromArray ( arr : any [ ] ) {
812
+ return arr [ rand ( 0 , arr . length - 1 ) ] ;
813
+ }
814
+
815
+ function generateGarbageText ( ) : string {
816
+ // Add any weird characters you want to this string
817
+ const characters =
818
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~`!@#$%^&*()_-+={[}]|\\:;"<,>.?/⊙△ΩβφÇ' ;
819
+ const length = Math . floor ( Math . random ( ) * 13 ) + 4 ; // This will give a random number between 4 and 16
820
+
821
+ return [ ...Array ( length ) ]
822
+ . map ( ( ) => characters [ Math . floor ( Math . random ( ) * characters . length ) ] )
823
+ . join ( "" ) ;
824
+ }
825
+
826
+ const funnyNames = [
827
+ "Binky" ,
828
+ "Fido" ,
829
+ "Peaches" ,
830
+ "Puddles" ,
831
+ "Snickers" ,
832
+ "Wiggles" ,
833
+ "Twinkle" ,
834
+ "Pickles" ,
835
+ "Muffin" ,
836
+ "Giggles" ,
837
+ "Bubbles" ,
838
+ "Ziggy" ,
839
+ "Noodle" ,
840
+ "Doodle" ,
841
+ "Pookie" ,
842
+ "Fluffy" ,
843
+ "Sprinkles" ,
844
+ "Jingles" ,
845
+ "Boogie" ,
846
+ "Winky" ,
847
+ "Tootsie" ,
848
+ "Fuzzy" ,
849
+ "Spunky" ,
850
+ "Goober" ,
851
+ "Snuggles" ,
852
+ "Scrappy" ,
853
+ "Puddin'" ,
854
+ "Biscuit" ,
855
+ "Doogie" ,
856
+ "Waffle" ,
857
+ "Zippy" ,
858
+ "Jolly" ,
859
+ "Sassy" ,
860
+ "Rascal" ,
861
+ "Boppy" ,
862
+ "Cuddles" ,
863
+ "Dinky" ,
864
+ "Fiddle" ,
865
+ "Gadget" ,
866
+ "Hopper" ,
867
+ "Jester" ,
868
+ "Kiki" ,
869
+ "Lollipop" ,
870
+ "Mimi" ,
871
+ "Nibbles" ,
872
+ "Oreo" ,
873
+ "Peppy" ,
874
+ "Quirky" ,
875
+ "Roo" ,
876
+ "Sprout" ,
877
+ ] ;
0 commit comments