Skip to content

Commit

Permalink
Added ability to hide amounts in the UI with **** (#187)
Browse files Browse the repository at this point in the history
* Added ability to hide amounts in the UI with ****

* Made invoice amount visible when paying.

* Updated hide amounts to use the UI store instead of mints store.
  • Loading branch information
cjbeery24 authored Jun 27, 2024
1 parent 969966b commit 54926a7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/boot/base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { copyToClipboard } from "quasar";
import { useUiStore } from "stores/ui";

window.LOCALE = "en";
// window.EventHub = new Vue();
Expand Down Expand Up @@ -35,10 +36,13 @@ window.windowMixin = {
});
});
},
formatCurrency: function (value, currency) {
formatCurrency: function (value, currency, showBalance = false) {
if (currency == undefined) {
currency = "sat";
}
if (useUiStore().hideBalance && !showBalance) {
return "****"
}
if (currency == "sat") return this.formatSat(value);
if (currency == "usd") value = value / 100;
return new Intl.NumberFormat(window.LOCALE, {
Expand Down
9 changes: 7 additions & 2 deletions src/components/BalanceView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<div class="row">
<div class="col-12">
<h3
class="q-my-none q-py-none"
@click="activeUnit = toggleUnit()"
class="q-my-none q-py-none cursor-pointer"
@click="toggleHideBalance"
>
<strong>
{{ formatCurrency(getTotalBalance, activeUnit) }}
Expand Down Expand Up @@ -113,6 +113,7 @@ import { mapState, mapWritableState, mapActions } from "pinia";
import { useMintsStore } from "stores/mints";
import { useSettingsStore } from "stores/settings";
import { useTokensStore } from "stores/tokens";
import { useUiStore } from "stores/ui";
import { useWalletStore } from "stores/wallet";
import ToggleUnit from "components/ToggleUnit.vue";
Expand Down Expand Up @@ -147,6 +148,7 @@ export default defineComponent({
...mapState(useTokensStore, ["historyTokens"]),
...mapState(useSettingsStore, ["getBitcoinPrice"]),
...mapWritableState(useMintsStore, ["activeUnit"]),
...mapWritableState(useUiStore, ["hideBalance"]),
pendingBalance: function () {
return -this.historyTokens
.filter((t) => t.status == "pending")
Expand Down Expand Up @@ -218,6 +220,9 @@ export default defineComponent({
units[(units.indexOf(this.activeUnit) + 1) % units.length];
return this.activeUnit;
},
toggleHideBalance() {
this.hideBalance = !this.hideBalance
}
},
});
</script>
3 changes: 2 additions & 1 deletion src/components/InvoiceDetailDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ export default defineComponent({
displayUnit: function () {
let display = this.formatCurrency(
this.invoiceData.amount,
this.invoiceData.unit
this.invoiceData.unit,
true
);
return display;
},
Expand Down
3 changes: 2 additions & 1 deletion src/components/PayInvoiceDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
{{
formatCurrency(
payInvoiceData.meltQuote.response.amount,
activeUnit
activeUnit,
true
)
}}
</h6>
Expand Down
1 change: 1 addition & 0 deletions src/stores/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const unitTickerShortMap = {

export const useUiStore = defineStore("ui", {
state: () => ({
hideBalance: useLocalStorage<boolean>("cashu.ui.hideBalance", false),
tickerLong: "Satoshis",
showInvoiceDetails: false,
showSendDialog: false,
Expand Down
7 changes: 6 additions & 1 deletion src/stores/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ type KeysetCounter = {

const receiveStore = useReceiveTokensStore();
const tokenStore = useTokensStore();
const uIStore = useUiStore();

export const useWalletStore = defineStore("wallet", {
state: () => {
Expand Down Expand Up @@ -275,6 +274,7 @@ export const useWalletStore = defineStore("wallet", {
return selectedProofs
},
spendableProofs: function (proofs: WalletProof[], amount: number) {
const uIStore = useUiStore();
const proofsStore = useProofsStore();
const mintStore = useMintsStore();
const spendableProofs = proofsStore.getUnreservedProofs(proofs);
Expand Down Expand Up @@ -358,6 +358,7 @@ export const useWalletStore = defineStore("wallet", {
/*
uses split to receive new tokens.
*/
const uIStore = useUiStore();
const mintStore = useMintsStore();
receiveStore.showReceiveTokens = false;
console.log("### receive tokens", receiveStore.receiveData.tokensBase64);
Expand Down Expand Up @@ -537,6 +538,7 @@ export const useWalletStore = defineStore("wallet", {
}
},
melt: async function () {
const uIStore = useUiStore();
const proofsStore = useProofsStore();
const mintStore = useMintsStore();
const tokenStore = useTokensStore();
Expand Down Expand Up @@ -708,6 +710,7 @@ export const useWalletStore = defineStore("wallet", {
checks whether a base64-encoded token (from the history table) has been spent already.
if it is spent, the appropraite entry in the history table is set to paid.
*/
const uIStore = useUiStore();
const mintStore = useMintsStore();
const tokenStore = useTokensStore();
const proofsStore = useProofsStore();
Expand Down Expand Up @@ -763,6 +766,7 @@ export const useWalletStore = defineStore("wallet", {
return true;
},
checkInvoice: async function (quote: string, verbose = true) {
const uIStore = useUiStore();
const mintStore = useMintsStore();
console.log("### checkInvoice.quote", quote);
const invoice = this.invoiceHistory.find((i) => i.quote === quote);
Expand All @@ -786,6 +790,7 @@ export const useWalletStore = defineStore("wallet", {
}
},
checkOutgoingInvoice: async function (quote: string, verbose = true) {
const uIStore = useUiStore();
const mintStore = useMintsStore();
const invoice = this.invoiceHistory.find((i) => i.quote === quote);
if (!invoice) {
Expand Down

0 comments on commit 54926a7

Please sign in to comment.