mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-29 18:06:43 +03:00
btc: address copying
This commit is contained in:
parent
2158e9a4cd
commit
197934f95b
@ -163,18 +163,29 @@
|
||||
++ on-watch
|
||||
|= =path
|
||||
^- (quip card _this)
|
||||
?> (team:title our.bowl src.bowl)
|
||||
?> ?=([%all ~] path)
|
||||
=/ initial=update
|
||||
:* %initial
|
||||
prov
|
||||
curr-xpub
|
||||
current-balance:hc
|
||||
current-history:hc
|
||||
btc-state
|
||||
==
|
||||
:_ this
|
||||
[%give %fact ~ %btc-wallet-update !>(initial)]~
|
||||
?+ path (on-watch:def path)
|
||||
[%all ~]
|
||||
?> (team:title our.bowl src.bowl)
|
||||
=^ a=(unit address) state
|
||||
?~ curr-xpub `state
|
||||
=/ uw=(unit walt) (~(get by walts) u.curr-xpub)
|
||||
?: ?|(?=(~ uw) ?!(scanned.u.uw))
|
||||
~|("no wallet with xpub or wallet not scanned yet" !!)
|
||||
=/ [addr=address =idx w=walt]
|
||||
~(gen-address wad:bl u.uw %0)
|
||||
[`addr state(walts (~(put by walts) u.curr-xpub w))]
|
||||
=/ initial=update
|
||||
:* %initial
|
||||
prov
|
||||
curr-xpub
|
||||
current-balance:hc
|
||||
current-history:hc
|
||||
btc-state
|
||||
a
|
||||
==
|
||||
:_ this
|
||||
[%give %fact ~ %btc-wallet-update !>(initial)]~
|
||||
==
|
||||
::
|
||||
++ on-leave on-leave:def
|
||||
++ on-arvo on-arvo:def
|
||||
@ -184,6 +195,7 @@
|
||||
++ handle-command
|
||||
|= comm=command
|
||||
^- (quip card _state)
|
||||
?> (team:title our.bowl src.bowl)
|
||||
?- -.comm
|
||||
%set-provider
|
||||
=* sub-card
|
||||
@ -243,6 +255,16 @@
|
||||
?. tx-match state
|
||||
?~ poym state
|
||||
state(signed-tx.u.poym `signed)
|
||||
::
|
||||
%gen-new-address
|
||||
?~ curr-xpub ~|("btc-wallet: no curr-xpub set" !!)
|
||||
=/ uw=(unit walt) (~(get by walts) u.curr-xpub)
|
||||
?: ?|(?=(~ uw) ?!(scanned.u.uw))
|
||||
~|("no wallet with xpub or wallet not scanned yet" !!)
|
||||
=/ [addr=address =idx w=walt]
|
||||
~(gen-address wad:bl u.uw %0)
|
||||
:_ state(walts (~(put by walts) u.curr-xpub w))
|
||||
[(give-update %new-address addr)]~
|
||||
==
|
||||
::
|
||||
++ handle-action
|
||||
|
@ -1,4 +1,5 @@
|
||||
/- btc-wallet, btc-provider, bitcoin
|
||||
/+ bl=bitcoin
|
||||
|%
|
||||
++ dejs
|
||||
=, dejs:format
|
||||
@ -15,6 +16,7 @@
|
||||
delete-wallet+so
|
||||
init-payment+init-payment
|
||||
broadcast-tx+so
|
||||
gen-new-address+|=(json ~)
|
||||
==
|
||||
::
|
||||
++ ship (su ;~(pfix sig fed:ag))
|
||||
@ -34,6 +36,12 @@
|
||||
value+ni
|
||||
feyb+ni
|
||||
==
|
||||
::
|
||||
++ address
|
||||
|= jon=json
|
||||
?> ?=([%s @t] jon)
|
||||
^- address:bitcoin
|
||||
(from-cord:adr:bl +.jon)
|
||||
--
|
||||
::
|
||||
++ enjs
|
||||
@ -89,6 +97,7 @@
|
||||
%btc-state (btc-state btc-state.upd)
|
||||
%new-tx (hest hest.upd)
|
||||
%cancel-tx (hexb txid.upd)
|
||||
%new-address (address address.upd)
|
||||
==
|
||||
::
|
||||
++ initial
|
||||
@ -101,6 +110,7 @@
|
||||
balance+?~(balance.upd ~ (numb u.balance.upd))
|
||||
history+(history history.upd)
|
||||
btc-state+(btc-state btc-state.upd)
|
||||
address+?~(address.upd ~ (address u.address.upd))
|
||||
==
|
||||
::
|
||||
++ change-provider
|
||||
|
@ -2,7 +2,7 @@
|
||||
/+ bip32
|
||||
|%
|
||||
+$ params [batch-size=@ud fam-limit=@ud piym-limit=@ud]
|
||||
+$ provider [host=ship connected=?]
|
||||
+$ provider [host=ship connected=?]
|
||||
+$ block @ud
|
||||
+$ btc-state [=block fee=(unit sats) t=@da]
|
||||
+$ payment [pend=(unit txid) =xpub =address payer=ship value=sats]
|
||||
@ -19,6 +19,7 @@
|
||||
[%delete-wallet =xpub]
|
||||
[%init-payment payee=ship value=sats feyb=sats]
|
||||
[%broadcast-tx txhex=cord]
|
||||
[%gen-new-address ~]
|
||||
==
|
||||
:: action: how peers poke us
|
||||
::
|
||||
@ -118,6 +119,7 @@
|
||||
balance=(unit sats)
|
||||
=history
|
||||
=btc-state
|
||||
address=(unit address)
|
||||
==
|
||||
[%change-provider provider=(unit provider)]
|
||||
[%change-wallet wallet=(unit xpub) balance=(unit sats) =history]
|
||||
@ -125,5 +127,6 @@
|
||||
[%btc-state =btc-state]
|
||||
[%new-tx =hest]
|
||||
[%cancel-tx =txid]
|
||||
[%new-address =address]
|
||||
==
|
||||
--
|
||||
|
@ -41,7 +41,10 @@ export default class Balance extends Component {
|
||||
},
|
||||
denomination: "USD",
|
||||
sending: false,
|
||||
copied: false,
|
||||
}
|
||||
|
||||
this.copyAddress = this.copyAddress.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
@ -52,17 +55,39 @@ export default class Balance extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
copyAddress() {
|
||||
let address = this.props.state.address;
|
||||
function listener(e) {
|
||||
e.clipboardData.setData('text/plain', address);
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
document.addEventListener('copy', listener);
|
||||
document.execCommand('copy');
|
||||
document.removeEventListener('copy', listener);
|
||||
|
||||
this.props.api.btcWalletCommand({'gen-new-address': null});
|
||||
this.setState({copied: true});
|
||||
setTimeout(() => {
|
||||
this.setState({copied: false});
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
|
||||
render() {
|
||||
const sats = (this.props.state.balance || 0);
|
||||
const value = currencyFormat(sats, this.state.conversion, this.state.denomination);
|
||||
const sendDisabled = (sats === 0);
|
||||
const addressText = (this.props.state.address === null) ? '' :
|
||||
this.props.state.address.slice(0, 6) + '...' +
|
||||
this.props.state.address.slice(-6);
|
||||
|
||||
return (
|
||||
<>
|
||||
{this.state.sending ?
|
||||
<Send
|
||||
api={api}
|
||||
shipWallets={this.props.state.shipWallets}
|
||||
value={value}
|
||||
denomination={this.state.denomination}
|
||||
sats={sats}
|
||||
@ -80,13 +105,13 @@ export default class Balance extends Component {
|
||||
>
|
||||
<Row justifyContent="space-between">
|
||||
<Text color="orange" fontSize={1}>Balance</Text>
|
||||
<Text color="lighterGray" fontSize="14px">bc1qxy...hx0wlh</Text>
|
||||
<Text color="lighterGray" fontSize="14px" mono>{addressText}</Text>
|
||||
<Row>
|
||||
<Icon icon="ChevronDouble" color="orange" pt="2px"/>
|
||||
<Text color="orange" fontSize={1}>{this.state.denomination}</Text>
|
||||
</Row>
|
||||
</Row>
|
||||
<Col justifyContent="center" alignItems="center" mt="100px" mb="100px">
|
||||
<Col justifyContent="center" alignItems="center">
|
||||
<Text fontSize="52px" color="orange">{value}</Text>
|
||||
<Text fontSize={1} color="orange">{sats} sats</Text>
|
||||
</Col>
|
||||
@ -104,16 +129,19 @@ export default class Balance extends Component {
|
||||
px="24px"
|
||||
onClick={() => this.setState({sending: true})}
|
||||
/>
|
||||
<Button children="Copy Address" mr={3}
|
||||
<Button children={(this.state.copied) ? "Address Copied!" : "Copy Address"}
|
||||
mr={3}
|
||||
disabled={this.state.copied}
|
||||
fontSize={1}
|
||||
fontWeight="bold"
|
||||
color="orange"
|
||||
backgroundColor="midOrange"
|
||||
style={{cursor:"pointer"}}
|
||||
color={(this.state.copied) ? "green" : "orange"}
|
||||
backgroundColor={(this.state.copied) ? "veryLightGreen" : "midOrange" }
|
||||
style={{cursor: (this.state.copied) ? "default" : "pointer"}}
|
||||
borderColor="none"
|
||||
borderRadius="24px"
|
||||
py="24px"
|
||||
px="24px"
|
||||
onClick={this.copyAddress}
|
||||
/>
|
||||
</Row>
|
||||
</Col>
|
||||
|
@ -4,12 +4,12 @@ export class InitialReducer {
|
||||
reduce(json, state) {
|
||||
let data = _.get(json, 'initial', false);
|
||||
if (data) {
|
||||
console.log('InitialReducer', data);
|
||||
state.provider = data.provider;
|
||||
state.wallet = data.wallet;
|
||||
state.balance = data.balance;
|
||||
state.btcState = data['btc-state'];
|
||||
state.history = this.reduceHistory(data.history);
|
||||
state.address = data.address
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@ import _ from 'lodash';
|
||||
|
||||
export class UpdateReducer {
|
||||
reduce(json, state) {
|
||||
console.log('update', json);
|
||||
if (json.providerStatus) {
|
||||
this.reduceProviderStatus(json.providerStatus, state);
|
||||
}
|
||||
@ -25,6 +24,9 @@ export class UpdateReducer {
|
||||
if (json["cancel-tx"]) {
|
||||
this.reduceCancelTx(json["cancel-tx"], state);
|
||||
}
|
||||
if (json.address) {
|
||||
this.reduceAddress(json.address, state);
|
||||
}
|
||||
}
|
||||
|
||||
reduceProviderStatus(json, state) {
|
||||
@ -48,8 +50,8 @@ export class UpdateReducer {
|
||||
}
|
||||
|
||||
reduceNewTx(json, state) {
|
||||
console.log("new-tx.....", json);
|
||||
let old = _.findIndex(state.history, (h) => {
|
||||
if (!h) return false;
|
||||
return ( h.txid.dat === json.txid.dat &&
|
||||
h.txid.wid === json.txid.wid );
|
||||
});
|
||||
@ -62,7 +64,7 @@ export class UpdateReducer {
|
||||
// we expect history to have null recvd values first, and the rest in
|
||||
// descending order
|
||||
let insertionIndex = _.findIndex(state.history, (h) => {
|
||||
console.log("h", h);
|
||||
if (!h) return false;
|
||||
return ((h.recvd < json.recvd) && (h.recvd !== null));
|
||||
});
|
||||
state.history.splice(insertionIndex, 0, json);
|
||||
@ -74,4 +76,8 @@ export class UpdateReducer {
|
||||
});
|
||||
state.history[entryIndex].failure = true;
|
||||
}
|
||||
|
||||
reduceAddress(json, state) {
|
||||
state.address = json;
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ class Store {
|
||||
btcState: null,
|
||||
history: [],
|
||||
psbt: '',
|
||||
address: null,
|
||||
};
|
||||
|
||||
this.initialReducer = new InitialReducer();
|
||||
|
Loading…
Reference in New Issue
Block a user