Skip to content

Commit

Permalink
Merge branch 'dev' into 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
zaSmilingIdiot committed Apr 7, 2023
2 parents b74a9b2 + 2848be8 commit 47d4907
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- run: sudo apt-get update && sudo apt-get install python3-pip && sudo pip3 install codespell
- run:
name: CodeSpell Checking
command: codespell --version && codespell -S=node_modules,dist,packages,.git,./src/assets,*mock-data,*terms-txt.ts,*yarn.lock,*package.json -L=datas,sortings,Ether,iif,inflight --ignore-regex "\W\'data\:image\/.*"
command: codespell --version && codespell -S=node_modules,dist,packages,.git,./src/assets,*mock-data,*terms-txt.ts,*yarn.lock,*package.json -L=datas,sortings,Ether,iif,inflight,forin --ignore-regex "\W\'data\:image\/.*"
no_output_timeout: 2m
- run:
name: Lint Codebase
Expand Down
21 changes: 15 additions & 6 deletions modules/particl-core/particlcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ module.exports = class ParticlCore extends CoreInstance {
#binaryPath;

#isDevelopmentEnvironment = false;
#forceTestnet = false;
#blockMainnet = false;

// holds a reference to the spawned pacticl core process (if one is spawned)
#startedDaemon = undefined;
Expand Down Expand Up @@ -321,7 +321,7 @@ module.exports = class ParticlCore extends CoreInstance {

this.#appVersion = appConfig.VERSIONS.app;
this.#binaryPath = _path.join(appConfig.PATHS.binaries, 'particl');
this.#forceTestnet = appConfig.TESTING_MODE === true;
this.#blockMainnet = appConfig.TESTING_MODE === true;
this.#isDevelopmentEnvironment = appConfig.MODE === 'developer';
}

Expand Down Expand Up @@ -984,7 +984,7 @@ module.exports = class ParticlCore extends CoreInstance {

let netSettings = this.#settingsValues.mainnet;

if (this.#settingsValues.network.testnet || this.#forceTestnet) {
if (this.#settingsValues.network.testnet) {
netSettings = this.#settingsValues.testnet;
deamonArgs.push('-testnet');
}
Expand All @@ -994,6 +994,11 @@ module.exports = class ParticlCore extends CoreInstance {
deamonArgs.push('-regtest');
}

if (this.#settingsValues.network.mainnet && this.#blockMainnet) {
netSettings = this.#settingsValues.testnet;
deamonArgs.push('-testnet');
}

if ((netSettings.coreHost !== 'localhost') && !netSettings.coreHost.startsWith('127.0.0.1')) {
deamonArgs.push(`-rpcbind=${netSettings.coreHost}`);
deamonArgs.push(`-rpcallowip=${netSettings.coreHost}`);
Expand Down Expand Up @@ -1229,11 +1234,14 @@ module.exports = class ParticlCore extends CoreInstance {
try {
if (_fs.existsSync(defaultDataDir) && _fs.statSync(defaultDataDir).isDirectory()) {
const segments = [defaultDataDir];
if (this.#settingsValues.network.testnet || this.#forceTestnet) {
if (this.#settingsValues.network.testnet) {
segments.push('testnet');
} else if (this.#settingsValues.network.regtest) {
segments.push('regtest');
} else if (this.#settingsValues.network.mainnet && this.#blockMainnet) {
segments.push('testnet');
}

segments.push('.cookie');
const cookiePath = _path.join(...segments);

Expand Down Expand Up @@ -1346,8 +1354,9 @@ module.exports = class ParticlCore extends CoreInstance {


#getRpcUrl() {
return this.#settingsValues.network.testnet || this.#forceTestnet ?
`http://${this.#settingsValues.testnet.coreHost}:${this.#settingsValues.testnet.corePort}` : (
const forceTestnet = this.#settingsValues.network.mainnet && this.#blockMainnet;
return this.#settingsValues.network.testnet || forceTestnet
? `http://${this.#settingsValues.testnet.coreHost}:${this.#settingsValues.testnet.corePort}` : (
this.#settingsValues.network.regtest
? `http://${this.#settingsValues.regtest.coreHost}:${this.#settingsValues.regtest.corePort}`
: `http://${this.#settingsValues.mainnet.coreHost}:${this.#settingsValues.mainnet.corePort}`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
"@ngx-gallery/gallerize": "^5.0.0-beta.0",
"@ngx-gallery/lightbox": "^5.0.0-beta.0",
"@ngxs/store": "^3.6.0",
"@zasmilingidiot/particl-marketplace": "0.3.12",
"@zasmilingidiot/particl-marketplace": "0.3.13",
"@zasmilingidiot/particl-zmq": "1.0.7",
"adm-zip": "^0.5.9",
"ajv": "^8.11.0",
Expand Down
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
8 changes: 4 additions & 4 deletions src/app/main-market/base/market-base.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@
</div>
</ng-container>

<ng-container ngProjectAs="sidebar" *ngIf="showProfileWarning || showWalletLockedWarning">
<div class="menu-items">
<a *ngIf="showWalletLockedWarning" class="menu-item warning">
<ng-container ngProjectAs="sidebar" *ngIf="isStarted">
<div class="menu-items" *ngIf="showProfileWarning || showWalletLockedWarning">
<a *ngIf="showWalletLockedWarning" class="menu-item warning" appDebounceClick (debounceClick)="openWalletUnlockModal()">
<mat-icon fontIcon="part-alert"></mat-icon>
<span class="text"
matTooltip="Updates to orders can be received while this wallet is encrypted"
matTooltip="Cannot update order statuses while this wallet is encrypted (locked)"
matTooltipPosition="right">
Wallet is currently locked
</span>
Expand Down
6 changes: 5 additions & 1 deletion src/app/main-market/base/market-base.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { MatDialog, MatExpansionPanel } from '@angular/material';
import { Subject, Observable, iif, defer, of, merge, combineLatest } from 'rxjs';
import { takeUntil, tap, map, startWith, finalize, concatMap, mapTo, catchError } from 'rxjs/operators';
import { takeUntil, tap, map, startWith, finalize, concatMap, mapTo, catchError, take } from 'rxjs/operators';

import { Store, Select } from '@ngxs/store';
import { MarketState } from '../store/market.state';
Expand Down Expand Up @@ -264,6 +264,10 @@ export class MarketBaseComponent implements OnInit, OnDestroy {
).subscribe();
}

openWalletUnlockModal() {
this._unlocker.changeCurrentStatus().pipe(take(1), takeUntil(this.destroy$)).subscribe();
}


identitySelected(identity: RenderedIdentity) {

Expand Down
17 changes: 14 additions & 3 deletions src/app/main-market/store/market.state.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { of, defer, iif, timer, throwError, merge } from 'rxjs';
import { tap, catchError, concatMap, retryWhen, map, mapTo } from 'rxjs/operators';

import { State, StateToken, Action, StateContext, Selector, createSelector } from '@ngxs/store';
import { State, StateToken, Action, StateContext, Selector, createSelector, Store } from '@ngxs/store';
import { patch, updateItem, removeItem, iif as nxgsIif } from '@ngxs/store/operators';
import { Particl } from 'app/networks/networks.module';
import { MarketStateActions, MarketUserActions } from './market.actions';
Expand All @@ -18,6 +18,7 @@ import {
MarketNotifications, ChatNotifications, IPCResponses
} from './market.models';
import { ChatChannelType } from '../services/chats/chats.models';
import { WalletInfoStateModel } from 'app/networks/particl/particl.models';


const MARKET_STATE_TOKEN = new StateToken<MarketStateModel>('market');
Expand Down Expand Up @@ -191,6 +192,7 @@ export class MarketState {
private _marketService: MarketRpcService,
private _socketService: MarketSocketService,
private _backendService: BackendService,
private _store: Store,
) {}


Expand Down Expand Up @@ -433,7 +435,7 @@ export class MarketState {
}
}

// Selected identity is not in the list returned, or there is no selected identity
// Selected identity is not in the list returned, or there is no selected identity: attempt the default identity
const savedID = ctx.getState().settings.defaultIdentityID;

if (savedID) {
Expand All @@ -443,11 +445,20 @@ export class MarketState {
}
}

// No valid current identity and no saved identity... get first identity from list
// No valid current identity and no saved identity... check if the current selected particl wallet is a valid identity
const activeParticlWalletInfo = this._store.selectSnapshot<WalletInfoStateModel>(Particl.State.Wallet.Info);
const current = identities.find(identity => identity.name === activeParticlWalletInfo.walletname);
if (current) {
return ctx.dispatch(new MarketStateActions.SetCurrentIdentity(current));
}

// welp, nothing else worked: use first identity found from the marketplace (if it has any)
const selected = JSON.parse(JSON.stringify(identities)).sort((a: Identity, b: Identity) => a.id - b.id)[0];
if (selected) {
return ctx.dispatch(new MarketStateActions.SetCurrentIdentity(selected));
}

// now bail... the null identity is the chosen one
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@

<mat-action-row class="action-buttons" fxLayout fxLayoutAlign="space-between stretch">
<div class="left">
<button *ngIf="!txn.isAbandoned && (txn.confirmations === 0)" mat-button color="warn" class="small" appDebounceClick (debounceClick)="abandonTransaction(txn.txid)">
<button *ngIf="!txn.isAbandoned && (txn.confirmations === 0) && txn.category === 'send'" mat-button color="warn" class="small" appDebounceClick (debounceClick)="abandonTransaction(txn.txid)">
<mat-icon fontIcon="part-error"></mat-icon>
Abandon This Transaction
</button>
Expand Down
27 changes: 17 additions & 10 deletions src/app/networks/particl/particl.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,11 @@ export class ParticlZMQState {
}));

if (message.channel === 'hashblock') {
return ctx.dispatch(new ParticlActions.WalletActions.RefreshBalances);
return ctx.dispatch([
new ParticlActions.WalletActions.RefreshBalances(),
new ParticlActions.WalletActions.RefreshWalletInfo(),
new ParticlActions.WalletActions.UpdateColdStakingInfo(),
]);
}
}
}
Expand Down Expand Up @@ -761,8 +765,18 @@ export class WalletInfoState {
}


@Action(ParticlInternalActions.WalletActions.WalletLoaded)
initializeWalletBalances(
ctx: StateContext<WalletInfoStateModel>,
{ walletName }: ParticlInternalActions.WalletActions.WalletLoaded
) {
return this._walletService.setSmsgActiveWallet(walletName);
}


private updateWalletInfo(
ctx: StateContext<WalletInfoStateModel>, newWalletLoaded: boolean = false
ctx: StateContext<WalletInfoStateModel>,
newWalletLoaded: boolean = false
): Observable<RPCResponses.GetWalletInfo> {
return this._walletService.getWalletInfo(1).pipe(
tap((info) => {
Expand Down Expand Up @@ -961,14 +975,7 @@ export class WalletBalanceState {
if (resKey in currentState) {
if (!result[resKey].length) {
updatedValues[resKey] = [];
} else if (
(currentState[resKey].length !== result[resKey].length) ||
(xorWith<PublicUTXO | BlindUTXO | AnonUTXO>(
currentState[resKey],
result[resKey],
(val, otherVal) => (val.txid === otherVal.txid) && (val.vout === otherVal.vout)
).length > 0)
) {
} else {
updatedValues[resKey] = result[resKey];
}
}
Expand Down
Loading

0 comments on commit 47d4907

Please sign in to comment.