Skip to content

Commit

Permalink
[particl] Allow selecting (in the UI) between test and regtest networ…
Browse files Browse the repository at this point in the history
…ks when the app is in testing mode.
  • Loading branch information
zaSmilingIdiot committed Apr 7, 2023
1 parent ee9fe4d commit 418d036
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class NetworkComponent implements OnInit, OnDestroy {


private destroy$: Subject<void> = new Subject();
private allowEditingNetwork: boolean = false;
private allowMainNetwork: boolean = false;
private controlNetworkPrefix: NetworkPrefix = '';


Expand All @@ -59,7 +59,7 @@ export class NetworkComponent implements OnInit, OnDestroy {

ngOnInit(): void {

this.allowEditingNetwork = !this._store.selectSnapshot<ApplicationConfigStateModel>(ApplicationConfigState).requestedTestingNetworks;
this.allowMainNetwork = !this._store.selectSnapshot<ApplicationConfigStateModel>(ApplicationConfigState).requestedTestingNetworks;

const settings$ = this._coreConfigService.getSettings().pipe(
filter(settings => settings !== null),
Expand Down Expand Up @@ -131,27 +131,27 @@ export class NetworkComponent implements OnInit, OnDestroy {
private loadSettings(settings: Settings): void {

let selectedNetwork: NetworkPrefixType = '';
if (this.allowEditingNetwork) {
if (settings[Controls.network_main] || settings[Controls.network_test] || settings[Controls.network_regtest]) {
switch (true) {
case settings[Controls.network_main] && settings[Controls.network_main].value: selectedNetwork = 'mainnet'; break;
case settings[Controls.network_test] && settings[Controls.network_test].value: selectedNetwork = 'testnet'; break;
case settings[Controls.network_regtest] && settings[Controls.network_regtest].value: selectedNetwork = 'regtest'; break;
}
if (settings[Controls.network_main] || settings[Controls.network_test] || settings[Controls.network_regtest]) {
switch (true) {
case this.allowMainNetwork && settings[Controls.network_main] && settings[Controls.network_main].value:
selectedNetwork = 'mainnet';
this.networkLabel = TextContent.NETWORK_LABEL_MAINNET;
break;
case settings[Controls.network_test] && settings[Controls.network_test].value:
selectedNetwork = 'testnet';
this.networkLabel = TextContent.NETWORK_LABEL_TESTNET;
break;
case settings[Controls.network_regtest] && settings[Controls.network_regtest].value:
selectedNetwork = 'regtest';
this.networkLabel = TextContent.NETWORK_LABEL_REGTEST;
break;
default:
this.networkLabel = '';
}
} else {
selectedNetwork = 'testnet';
}

this.controlNetworkPrefix = selectedNetwork.length > 0 ? `${selectedNetwork}.` : '';

switch (selectedNetwork) {
case 'mainnet': this.networkLabel = TextContent.NETWORK_LABEL_MAINNET; break;
case 'testnet': this.networkLabel = TextContent.NETWORK_LABEL_TESTNET; break;
case 'regtest': this.networkLabel = TextContent.NETWORK_LABEL_REGTEST; break;
default: this.networkLabel = '';
}

for (const field of [Controls.rpcIP, Controls.rpcPort, Controls.zmqIP, Controls.zmqPort]) {
const fieldName = `${this.controlNetworkPrefix}${field}`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ <h4 class="option">
</h4>
<p class="desc">Allows for selecting which network to connect to when starting a new Particl Core node.</p>
<p class="desc">Note that this selection only applies when starting a new Particl Core node. If Particl Core is already running, it will need to be stopped or disconnected from, and a new node started afterwards, in order to to take effect.</p>
<p class="message --info" *ngIf="!allowEditingNetwork">This is currently disabled since the application has been forced into a testing state, in which case the relevant testing network will be enforced (this helps to ensure that testing builds do not result in real funds being used).</p>
<p class="message --warning" *ngIf="allowEditingNetwork">This should only typically be changed away from the main network when wanting to test functionality!</p>
<p class="message --info" *ngIf="!allowMainNetwork">The main network is currently disabled since the application has been forced into a testing state, in which case the relevant testing network will be enforced (this helps to ensure that testing builds do not result in real funds being used).</p>
<p class="message --warning" *ngIf="allowMainNetwork">This should only typically be changed away from the main network when wanting to test functionality!</p>

<mat-radio-group class="from-balance-type block-radio"
fxLayout="column"
fxLayoutGap="10px"
[formControl]="controlNetwork">
<mat-radio-button class="balance" fxFlex value="main"><div class="name">Main</div></mat-radio-button>
<mat-radio-button class="balance" fxFlex value="main" [disabled]="!allowMainNetwork"><div class="name">Main</div></mat-radio-button>
<mat-radio-button class="balance" fxFlex value="test"><div class="name">Test</div></mat-radio-button>
<mat-radio-button class="balance" fxFlex value="regtest"><div class="name">RegTest</div></mat-radio-button>
</mat-radio-group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class StartupComponent implements OnInit, OnDestroy {
controlNetwork: FormControl = new FormControl({ value: '', disabled: true});
controlDataDir: FormControl = new FormControl({ value: '', disabled: true});

allowEditingNetwork: boolean = false;
allowMainNetwork: boolean = false;

private destroy$: Subject<void> = new Subject();

Expand All @@ -52,7 +52,7 @@ export class StartupComponent implements OnInit, OnDestroy {

ngOnInit(): void {

this.allowEditingNetwork = !this._store.selectSnapshot<ApplicationConfigStateModel>(ApplicationConfigState).requestedTestingNetworks;
this.allowMainNetwork = !this._store.selectSnapshot<ApplicationConfigStateModel>(ApplicationConfigState).requestedTestingNetworks;

const settings$ = this._coreConfigService.getSettings().pipe(
filter(settings => settings !== null),
Expand Down Expand Up @@ -98,7 +98,11 @@ export class StartupComponent implements OnInit, OnDestroy {
[Controls.network_regtest]: false,
};
switch (value) {
case 'main': updatedValue[Controls.network_main] = true; break;
case 'main':
if (this.allowMainNetwork) {
updatedValue[Controls.network_main] = true;
}
break;
case 'test': updatedValue[Controls.network_test] = true; break;
case 'regtest': updatedValue[Controls.network_regtest] = true; break;
}
Expand Down Expand Up @@ -187,22 +191,18 @@ export class StartupComponent implements OnInit, OnDestroy {
this.controlStartNew.enable({emitEvent: false});
}

let networkSelection = 'main';
if (!this.allowEditingNetwork) {
networkSelection = 'test';
} else {
if (settings[Controls.network_main] || settings[Controls.network_test] || settings[Controls.network_regtest]) {
switch (true) {
case settings[Controls.network_main] && settings[Controls.network_main].value: networkSelection = 'main'; break;
case settings[Controls.network_test] && settings[Controls.network_test].value: networkSelection = 'test'; break;
case settings[Controls.network_regtest] && settings[Controls.network_regtest].value: networkSelection = 'regtest'; break;
}
let networkSelection = this.allowMainNetwork ? 'main' : 'test';

if (settings[Controls.network_main] || settings[Controls.network_test] || settings[Controls.network_regtest]) {
switch (true) {
case this.allowMainNetwork && settings[Controls.network_main] && settings[Controls.network_main].value: networkSelection = 'main'; break;
case settings[Controls.network_test] && settings[Controls.network_test].value: networkSelection = 'test'; break;
case settings[Controls.network_regtest] && settings[Controls.network_regtest].value: networkSelection = 'regtest'; break;
}
}

this.controlNetwork.setValue(networkSelection, {onlySelf: true, emitEvent: false});
if (this.allowEditingNetwork) {
this.controlNetwork.enable({emitEvent: false});
}
this.controlNetwork.enable({emitEvent: false});

if (settings[Controls.datadir]) {
this.controlDataDir.setValue(settings[Controls.datadir].value, {onlySelf: true, emitEvent: false});
Expand Down

0 comments on commit 418d036

Please sign in to comment.