btc: persist preferred currency; clean up btc currency style

This commit is contained in:
ixv 2021-05-21 13:02:26 -07:00
parent 84f6aa33d0
commit 8770e1e00c
6 changed files with 37 additions and 6 deletions

View File

@ -60,9 +60,12 @@
%btc-wallet
[[%custom `'/~btc' `'/~btc/img/tile.png'] %.y]
=/ warning [%settings-event !>([%put-entry %btc-wallet %warning %b %.y])]
=/ currency
[%settings-event !>([%put-entry %btc-wallet %currency %s 'USD'])]
:- :~ [%pass /btc-wallet-server %agent [our.bowl %file-server] %poke file]
[%pass /btc-wallet-tile %agent [our.bowl %launch] %poke tile]
[%pass /warn %agent [our.bowl %settings-store] %poke warning]
[%pass /warn %agent [our.bowl %settings-store] %poke currency]
==
%_ this
state

View File

@ -99,12 +99,15 @@ export default class Balance extends Component {
{this.state.copiedString ? "copied" : addressText}
</Text>
<CurrencyPicker
api={this.props.api}
denomination={denomination}
currencies={this.props.state.currencyRates}
/>
</Row>
<Col justifyContent="center" alignItems="center">
<Text fontSize="52px" color="orange">{value}</Text>
<Text fontSize="40px" color="orange" style={{whiteSpace: "nowrap"}} >
{value}
</Text>
<Text fontSize={1} color="orange">{`${sats}${unconfirmedString} sats`}</Text>
</Col>
<Row flexDirection="row-reverse">

View File

@ -20,13 +20,22 @@ export default class CurrencyPicker extends Component {
}
switchCurrency(){
let newCurrency;
if (this.props.denomination === 'BTC') {
if (this.props.currencies['USD']) {
store.handleEvent({data: {denomination: 'USD'}})
newCurrency = "USD";
}
} else if (this.props.denomination === 'USD') {
store.handleEvent({data: {denomination: 'BTC'}})
newCurrency = "BTC";
}
let setCurrency = {
"put-entry": {
value: newCurrency,
"entry-key": "currency",
"bucket-key": "btc-wallet",
}
}
this.props.api.settingsEvent(setCurrency);
}

View File

@ -92,7 +92,7 @@ export function satsToCurrency(sats, denomination, rates){
let val = (sats * rate.last) * 0.00000001;
let text;
if (denomination === 'BTC'){
text = rate.symbol + val.toFixed(8)
text = val + ' ' + rate.symbol
} else {
text = rate.symbol + val.toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
}

View File

@ -4,11 +4,27 @@ export class SettingsReducer {
reduce(json, state) {
let data = _.get(json, 'bucket', false);
if (data) {
state.showWarning = data.warning;
let warning = _.get(json, 'bucket.warning', -1);
if (warning !== -1) {
state.showWarning = warning
}
let currency = _.get(json, 'bucket.currency', -1);
if (currency !== -1) {
state.denomination = currency;
}
state.loadedSettings = true;
if (state.loadedBtc) {
state.loaded = true;
}
}
let entry = _.get(json, 'settings-event.put-entry.entry-key', false);
if (entry === 'currency') {
let value = _.get(json, 'settings-event.put-entry.value', false);
state.denomination = value;
} else if (entry === 'warning') {
let value = _.get(json, 'settings-event.put-entry.value', false);
state.showWarning = value;
}
}
}

View File

@ -20,7 +20,7 @@ class Store {
psbt: '',
address: null,
currencyRates: {
BTC: { last: 1, symbol: '฿' }
BTC: { last: 1, symbol: 'BTC' }
},
denomination: 'BTC',
showWarning: true,