diff --git a/src/app/wallet/overview/widgets/coldstake/coldstake.component.ts b/src/app/wallet/overview/widgets/coldstake/coldstake.component.ts index bcdd4cc76..3e7b518f1 100644 --- a/src/app/wallet/overview/widgets/coldstake/coldstake.component.ts +++ b/src/app/wallet/overview/widgets/coldstake/coldstake.component.ts @@ -76,7 +76,81 @@ export class ColdstakeComponent implements OnInit { } openZapWalletsettingsModal() { - this.dialog.open(ZapWalletsettingsComponent); + + /* TODO: use async / await, make return value useful, subscribe errors */ + this.log.d('zap called !'); + + this._rpc.call('walletsettings', ['changeaddress']).subscribe(info => { + + this.log.d('zap walletsettings', info); + const pkey = info.changeaddress.coldstakingaddress; + if (pkey === 'default') { + return false; + } + + this._rpc.call('deriverangekeys', [1, 1, pkey]).subscribe(info => { + + this.log.d('zap deriverangekeys', info); + if (!info || info.length !== 1) { + return false; + } + const stake = info[0]; + + this._rpc.call('getnewaddress', ['""', 'false', 'false', 'true']) + .subscribe(info => { + + this.log.d('zap getnewaddress', info); + const spend = info; + if (!spend || spend === '') { + return false; + } + + this._rpc.call('buildscript', [{ + recipe: 'ifcoinstake', + addrstake: stake, + addrspend: spend + }]).subscribe(info => { + + this.log.d('zap buildscript', info); + if (!info || !info.hex) { + return false; + } + const script = info.hex; + + this._rpc.call('listunspent').subscribe(info => { + + let sum_inputs = 0; + const inputs = []; + + info.map(utxo => { + this.log.d('listunspent utxo', utxo); + sum_inputs += utxo.amount; + inputs.push({tx: utxo.txid, n: utxo.vout}); + }); + + this.log.d('zap params', sum_inputs, inputs); + + this._rpc.call('sendtypeto', ['part', 'part', [{ + subfee: true, + address: 'script', + amount: sum_inputs, + script: script + }], '', '', 4, 64, true, JSON.stringify({ + inputs: inputs + })]).subscribe(info => { + + this.log.d('zap sendtypeto simulate', info); + + // TODO: ask user to confirm info.fee in a modal + this.dialog.open(ZapWalletsettingsComponent); + + }); + }) + + }); + }); + }) + }); } openUnlockWalletModal(): void { diff --git a/src/app/wallet/overview/widgets/coldstake/zap-walletsettings/zap-walletsettings.component.html b/src/app/wallet/overview/widgets/coldstake/zap-walletsettings/zap-walletsettings.component.html index 66544efdd..2777ed464 100644 --- a/src/app/wallet/overview/widgets/coldstake/zap-walletsettings/zap-walletsettings.component.html +++ b/src/app/wallet/overview/widgets/coldstake/zap-walletsettings/zap-walletsettings.component.html @@ -2,7 +2,9 @@

Zap Wallet Settings

- + {{ fee }} PART + + diff --git a/src/app/wallet/overview/widgets/coldstake/zap-walletsettings/zap-walletsettings.component.ts b/src/app/wallet/overview/widgets/coldstake/zap-walletsettings/zap-walletsettings.component.ts index 5f6673724..3ee5fcc1e 100644 --- a/src/app/wallet/overview/widgets/coldstake/zap-walletsettings/zap-walletsettings.component.ts +++ b/src/app/wallet/overview/widgets/coldstake/zap-walletsettings/zap-walletsettings.component.ts @@ -13,95 +13,19 @@ export class ZapWalletsettingsComponent { private log: any = Log.create('zap-walletsettings'); + fee: number = 42; + constructor(private _rpc: RpcService) { } - zap() { - /* TODO: use async / await, make return value useful, subscribe errors */ - this.log.d('zap called !'); - - this._rpc.call('walletsettings', ['changeaddress']).subscribe(info => { - - this.log.d('zap walletsettings', info); - const pkey = info.changeaddress.coldstakingaddress; - if (pkey === 'default') { - return false; - } - - this._rpc.call('deriverangekeys', [1, 1, pkey]).subscribe(info => { - - this.log.d('zap deriverangekeys', info); - if (!info || info.length !== 1) { - return false; - } - const stake = info[0]; - - this._rpc.call('getnewaddress', ['""', 'false', 'false', 'true']) - .subscribe(info => { - - this.log.d('zap getnewaddress', info); - const spend = info; - if (!spend || spend === '') { - return false; - } - - this._rpc.call('buildscript', [{ - recipe: 'ifcoinstake', - addrstake: stake, - addrspend: spend - }]).subscribe(info => { - - this.log.d('zap buildscript', info); - if (!info || !info.hex) { - return false; - } - const script = info.hex; - - this._rpc.call('listunspent').subscribe(info => { - - let sum_inputs = 0; - /* TODO */ - const inputs = []; - - info.map(utxo => { - this.log.d('listunspent utxo', utxo); - sum_inputs += utxo.amount; - inputs.push({tx: utxo.txid, n: utxo.vout}); - }); - - this.log.d('zap params', sum_inputs, inputs); - - this._rpc.call('sendtypeto', ['part', 'part', [{ - subfee: true, - address: 'script', - amount: sum_inputs, - script: script - }], '', '', 4, 64, true, JSON.stringify({ - inputs: inputs - })]).subscribe(info => { - - this.log.d('zap sendtypeto simulate', info); - - // TODO: ask user to confirm info.fee in a modal - - this.confirmZap(sum_inputs, script); - - }); - }) - - }); - }); - }) - }); - } + zap(amount: number, script: any) { - confirmZap(amount: number, script: any) { this._rpc.call('sendtypeto', ['part', 'part', [{ subfee: true, address: 'script', amount: amount, - script: script - }], '', '', 4, 64, false]).subscribe(info => { + script: script /* TODO : remove optional args */ + }], 'coldstaking zap', '', 4, 64, false]).subscribe(info => { this.log.d('zap sendtypeto', info);