From 24db04bccc15a4ddc2b94dc7623e3f2c0e86795d Mon Sep 17 00:00:00 2001 From: Isaac Visintainer Date: Fri, 23 Apr 2021 13:18:20 -0700 Subject: [PATCH] temp --- pkg/arvo/app/btc-wallet.hoon | 37 ++- pkg/arvo/lib/bitcoin-json.hoon | 13 +- pkg/arvo/sur/btc-wallet.hoon | 4 +- .../src/js/components/lib/balance.js | 1 + pkg/btc-wallet/src/js/components/lib/send.js | 239 +++++++++++------- .../src/js/components/lib/transaction.js | 10 +- .../src/js/components/lib/tx-counterparty.js | 3 +- pkg/btc-wallet/src/js/reducers/initial.js | 3 +- 8 files changed, 201 insertions(+), 109 deletions(-) diff --git a/pkg/arvo/app/btc-wallet.hoon b/pkg/arvo/app/btc-wallet.hoon index cce62bc4a1..af8a6a7543 100644 --- a/pkg/arvo/app/btc-wallet.hoon +++ b/pkg/arvo/app/btc-wallet.hoon @@ -186,6 +186,7 @@ [%give %fact ~ %json !>(response)]~ :: [%all ~] + ~& %watch-all ?> (team:title our.bowl src.bowl) :_ this [give-initial:hc]~ @@ -643,6 +644,7 @@ btc-state [block fee now.bowl] == ?: ?|(?!(connected.p) (lth block.btc-state block)) + ~& >> block ;: weld (retry-pend-piym network) (retry-poym network) @@ -652,6 +654,7 @@ retry-ahistorical-txs == ;: weld +:: (retry-addrs network) retry-ahistorical-txs (retry-pend-piym network) == @@ -760,6 +763,7 @@ ++ handle-tx-info |= ti=info:tx ^- (quip card _state) + ~& %handle-tx-info^ti |^ =/ h (~(get by history) txid.ti) =. ahistorical-txs (~(del in ahistorical-txs) txid.ti) @@ -769,6 +773,13 @@ %+ turn (weld inputs.ti outputs.ti) |=(=val:tx address.val) is-our-address + ~& addresses+our-addrs +:: =/ addr-info-cards=(list card) +:: %+ turn ~(tap in our-addrs) +:: |= a=address +:: ^- card +:: (poke-provider [%address-info a]) + :: ?: =(0 ~(wyt in our-addrs)) `state =/ =xpub xpub.w:(need (address-coords:bl (snag 0 ~(tap in our-addrs)) ~(val by walts))) @@ -776,13 +787,16 @@ =/ new-hest=hest (mk-hest xpub our-addrs) =. history (~(put by history) txid.ti new-hest) :_ state +:: :_ addr-info-cards [(give-update %new-tx new-hest)]~ ?. included.ti :: tx in history, but not in mempool/blocks :_ state(history (~(del by history) txid.ti)) +:: :_ addr-info-cards [(give-update %cancel-tx txid.ti)]~ =/ new-hest u.h(confs confs.ti, recvd recvd.ti) =. history (~(put by history) txid.ti new-hest) :_ state +:: :_ addr-info-cards [(give-update %new-tx new-hest)]~ :: ++ mk-hest @@ -830,6 +844,7 @@ ++ handle-address-info |= [=address utxos=(set utxo) used=?] ^- (quip card _state) + ~& %handle-address-info^address =/ ac (address-coords:bl address ~(val by walts)) ?~ ac `state @@ -1020,21 +1035,29 @@ :: ++ balance |= =xpub:bc - ^- (unit sats) + ^- (unit [sats sats]) =/ w (~(get by walts) xpub) ?~ w ~ - =/ values=(list sats) + =/ values=(list [confirmed=sats unconfirmed=sats]) %+ turn ~(val by wach.u.w) - |= =addi ^- sats + |= =addi ^- [sats sats] %+ roll %+ turn ~(tap by utxos.addi) - |=(=utxo value.utxo) - add - `(roll values add) + |= =utxo + ^- [sats sats] + ?: (~(spendable sut:bl [u.w eny.bowl block.btc-state ~ 0 ~]) utxo) + [value.utxo 0] + [0 value.utxo] + |= [[a=sats b=sats] out=[p=sats q=sats]] + [(add a p.out) (add b q.out)] + :- ~ + %+ roll values + |= [[a=sats b=sats] out=[p=sats q=sats]] + [(add a p.out) (add b q.out)] :: :: ++ current-balance - ^- (unit sats) + ^- (unit [sats sats]) ?~ curr-xpub ~ (balance u.curr-xpub) :: diff --git a/pkg/arvo/lib/bitcoin-json.hoon b/pkg/arvo/lib/bitcoin-json.hoon index e5a2756d4c..b05fb53a71 100644 --- a/pkg/arvo/lib/bitcoin-json.hoon +++ b/pkg/arvo/lib/bitcoin-json.hoon @@ -116,7 +116,7 @@ %- pairs :~ provider+(provider provider.upd) wallet+?~(wallet.upd ~ [%s u.wallet.upd]) - balance+?~(balance.upd ~ (numb u.balance.upd)) + balance+(balance balance.upd) history+(history history.upd) btc-state+(btc-state btc-state.upd) address+?~(address.upd ~ (address u.address.upd)) @@ -134,10 +134,19 @@ ^- json %- pairs :~ wallet+?~(wallet.upd ~ [%s u.wallet.upd]) - balance+?~(balance.upd ~ (numb u.balance.upd)) + balance+(balance balance.upd) history+(history history.upd) == :: + ++ balance + |= b=(unit [p=@ q=@]) + ^- json + ?~ b ~ + %- pairs + :~ confirmed+(numb p.u.b) + unconfirmed+(numb q.u.b) + == + :: ++ btc-state |= bs=btc-state:btc-wallet ^- json diff --git a/pkg/arvo/sur/btc-wallet.hoon b/pkg/arvo/sur/btc-wallet.hoon index ba08860437..6e6be63576 100644 --- a/pkg/arvo/sur/btc-wallet.hoon +++ b/pkg/arvo/sur/btc-wallet.hoon @@ -118,13 +118,13 @@ $% $: %initial provider=(unit provider) wallet=(unit xpub) - balance=(unit sats) + balance=(unit [p=sats q=sats]) =history =btc-state address=(unit address) == [%change-provider provider=(unit provider)] - [%change-wallet wallet=(unit xpub) balance=(unit sats) =history] + [%change-wallet wallet=(unit xpub) balance=(unit [p=sats q=sats]) =history] [%psbt pb=@t] [%btc-state =btc-state] [%new-tx =hest] diff --git a/pkg/btc-wallet/src/js/components/lib/balance.js b/pkg/btc-wallet/src/js/components/lib/balance.js index ac85f2f954..8351ee1b3a 100644 --- a/pkg/btc-wallet/src/js/components/lib/balance.js +++ b/pkg/btc-wallet/src/js/components/lib/balance.js @@ -67,6 +67,7 @@ export default class Balance extends Component { denomination={denomination} sats={sats} conversion={conversion} + network={this.props.network} stopSending={() => { this.setState({sending: false}); store.handleEvent({data: {psbt: ''}}); diff --git a/pkg/btc-wallet/src/js/components/lib/send.js b/pkg/btc-wallet/src/js/components/lib/send.js index 0d506b07c0..ac994c8af6 100644 --- a/pkg/btc-wallet/src/js/components/lib/send.js +++ b/pkg/btc-wallet/src/js/components/lib/send.js @@ -33,12 +33,38 @@ export default class Send extends Component { focusCurrency: false, focusSats: false, submitting: false, + feeChoices: { + low: [10, 1], + mid: [10, 1], + high: [10, 1], + }, + feeValue: "mid", + showModal: false, }; this.initPayment = this.initPayment.bind(this); this.checkPayee = this.checkPayee.bind(this); } + componentDidMount(){ + // TODO switch this to bitcoin + if (this.props.network === 'testnet'){ + let url = "https://bitcoiner.live/api/fees/estimates/latest"; + fetch(url).then(res => res.json()).then(n => { + let estimates = Object.keys(n.estimates); + let mid = Math.floor(estimates.length/2) + let high = estimates.length - 1; + this.setState({ + feeChoices: { + low: [30, n.estimates[30]["sat_per_vbyte"]], + mid: [180, n.estimates[180]["sat_per_vbyte"]], + high: [360, n.estimates[360]["sat_per_vbyte"]], + } + }); + }) + } + } + checkPayee(e){ let payee = e.target.value; let isPatp = ob.isValidPatp(payee); @@ -154,102 +180,133 @@ export default class Send extends Component { borderRadius='32px' mb={5} p={5} + display="flex" + flexDirection="column" + justifyContent="space-between" > - - Send BTC - {value} - stopSending()} - /> - - - - To - {this.state.checkingPatp ? - : null - } + + + Send BTC + {value} + stopSending()} + /> - {this.setState({focusPayee: true})}} - onBlur={() => {this.setState({focusPayee: false})}} - color={payeeColor} - backgroundColor={payeeBg} - borderColor={payeeBorder} - ml={2} - flexGrow="1" - fontSize='14px' - placeholder='~sampel-palnet or BTC address' - value={payee} - fontFamily="mono" - disabled={signing} - onChange={this.checkPayee} - /> - - - Amount - {this.setState({focusCurrency: true})}} - onBlur={() => {this.setState({focusCurrency: false})}} - fontSize='14px' - width='100%' - type='number' - borderColor={this.state.focusCurrency ? "lightGray" : "none"} - disabled={signing} - value={denomAmount} - onChange={e => { - this.setState({ - denomAmount: e.target.value, - satsAmount: Math.round(parseFloat(e.target.value) / conversion * 100000000) - }); - }} - /> - {denomination} - - - {/* yes this is a hack */} - - {this.setState({focusSats: true})}} - onBlur={() => {this.setState({focusSats: false})}} - fontSize='14px' - width='100%' - type='number' - borderColor={this.state.focusSats ? "lightGray" : "none"} - disabled={signing} - value={satsAmount} - onChange={e => { - this.setState({ - denomAmount: parseFloat(e.target.value) * (conversion / 100000000), - satsAmount: e.target.value - }); - }} - /> - sats - + + + To + {this.state.checkingPatp ? + : null + } + + {this.setState({focusPayee: true})}} + onBlur={() => {this.setState({focusPayee: false})}} + color={payeeColor} + backgroundColor={payeeBg} + borderColor={payeeBorder} + ml={2} + flexGrow="1" + fontSize='14px' + placeholder='~sampel-palnet or BTC address' + value={payee} + fontFamily="mono" + disabled={signing} + onChange={this.checkPayee} + /> + + + Amount + {this.setState({focusCurrency: true})}} + onBlur={() => {this.setState({focusCurrency: false})}} + fontSize='14px' + width='100%' + type='number' + borderColor={this.state.focusCurrency ? "lightGray" : "none"} + disabled={signing} + value={denomAmount} + onChange={e => { + this.setState({ + denomAmount: e.target.value, + satsAmount: Math.round(parseFloat(e.target.value) / conversion * 100000000) + }); + }} + /> + {denomination} + + + {/* yes this is a hack */} + + {this.setState({focusSats: true})}} + onBlur={() => {this.setState({focusSats: false})}} + fontSize='14px' + width='100%' + type='number' + borderColor={this.state.focusSats ? "lightGray" : "none"} + disabled={signing} + value={satsAmount} + onChange={e => { + this.setState({ + denomAmount: parseFloat(e.target.value) * (conversion / 100000000), + satsAmount: e.target.value + }); + }} + /> + sats + + + Fee + + + {this.state.feeChoices[this.state.feeValue][1]} sats/vbyte + + { this.setState({showModal: !this.state.showModal}); }} + cursor="pointer"/> + + + + {!this.state.showModal ? null : + + Transaction Speed + + } + +