ADD: getUtxo frozen argument

This commit is contained in:
Ivan Vershigora 2020-10-23 13:49:17 +03:00
parent 8c484ffecb
commit 3bcc60d5bc
4 changed files with 20 additions and 13 deletions

View file

@ -716,9 +716,18 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet {
*
* @returns {[]}
*/
getUtxo() {
if (this._utxo.length === 0) return this.getDerivedUtxoFromOurTransaction(); // oy vey, no stored utxo. lets attempt to derive it from stored transactions
return this._utxo;
getUtxo({ frozen = false } = {}) {
let ret = [];
if (this._utxo.length === 0) {
ret = this.getDerivedUtxoFromOurTransaction(); // oy vey, no stored utxo. lets attempt to derive it from stored transactions
} else {
ret = this._utxo;
}
if (!frozen && this.frozenUtxo) {
ret = ret.filter(({ txId, vout }) => !this.frozenUtxo.some(i => txId === i.txid && vout === i.vout));
}
return ret;
}
getDerivedUtxoFromOurTransaction(returnSpentUtxoAsWell = false) {

View file

@ -139,14 +139,14 @@ export class LegacyWallet extends AbstractWallet {
}
}
getUtxo({ frozen = false }) {
getUtxo({ frozen = false } = {}) {
let ret = [];
for (const u of this.utxo) {
if (u.txId) u.txid = u.txId;
if (!u.confirmations && u.height) u.confirmations = BlueElectrum.estimateCurrentBlockheight() - u.height;
ret.push(u);
}
if (frozen && this.frozenUtxo) {
if (!frozen && this.frozenUtxo) {
ret = ret.filter(({ txId, vout }) => !this.frozenUtxo.some(i => txId === i.txid && vout === i.vout));
}
return ret;

View file

@ -150,8 +150,8 @@ export class WatchOnlyWallet extends LegacyWallet {
throw new Error('Not initialized');
}
getUtxo() {
if (this._hdWalletInstance) return this._hdWalletInstance.getUtxo();
getUtxo(...args) {
if (this._hdWalletInstance) return this._hdWalletInstance.getUtxo(...args);
throw new Error('Not initialized');
}

View file

@ -72,8 +72,6 @@ const CoinControl = () => {
const frozenUtxo = wallet.getFrozenUtxo();
const switchValue = output && frozenUtxo.some(({ txid, vout }) => output.txid === txid && output.vout === vout);
console.info('frozenUtxo', frozenUtxo);
const handleChoose = item => setOutput(item);
const onFreeze = async ({ txid, vout }, value) => {
if (value) {
@ -84,11 +82,11 @@ const CoinControl = () => {
await BlueApp.saveToDisk();
setReRender(i => !i);
};
const renderItem = ({ item }) => (
const renderItem = p => (
<Output
item={item}
frozen={frozenUtxo.some(({ txid, vout }) => item.txid === txid && item.vout === vout)}
onPress={() => handleChoose(item)}
item={p.item}
frozen={frozenUtxo.some(({ txid, vout }) => p.item.txid === txid && p.item.vout === vout)}
onPress={() => handleChoose(p.item)}
/>
);