Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix activeUnitLabel computation and add support for EUR and mSAT units #211

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/boot/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ window.windowMixin = {
currency = "sat";
}
if (useUiStore().hideBalance && !showBalance) {
return "****"
return "****";
}
if (currency == "sat") return this.formatSat(value);
if (currency == "msat") return this.fromMsat(value);
if (currency == "usd") value = value / 100;
if (currency == "eur") value = value / 100;
return new Intl.NumberFormat(window.LOCALE, {
style: "currency",
currency: currency,
Expand All @@ -57,6 +59,10 @@ window.windowMixin = {
value = parseInt(value);
return new Intl.NumberFormat(window.LOCALE).format(value) + " sat";
},
fromMsat: function (value) {
value = parseInt(value);
return new Intl.NumberFormat(window.LOCALE).format(value) + " msat";
},
notifyApiError: function (error) {
var types = {
400: "warning",
Expand Down
4 changes: 2 additions & 2 deletions src/components/InvoiceDetailDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
flat
color="primary"
@click="toggleUnit()"
:label="activeUnit == 'sat' ? 'BTC' : 'USD'"
:label="activeUnitLabel"
/>
</q-input>
<div class="row items-center no-wrap q-my-sm q-py-none">
Expand Down Expand Up @@ -171,7 +171,7 @@ export default defineComponent({
},
computed: {
...mapState(useWalletStore, ["invoiceData"]),
...mapState(useMintsStore, ["activeUnit"]),
...mapState(useMintsStore, ["activeUnit", "activeUnitLabel"]),
...mapState(useWorkersStore, ["invoiceWorkerRunning"]),
...mapWritableState(useUiStore, ["showInvoiceDetails", "tickerShort"]),
displayUnit: function () {
Expand Down
7 changes: 4 additions & 3 deletions src/components/SendTokenDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
flat
color="primary"
@click="toggleUnit()"
:label="activeUnit == 'sat' ? 'BTC' : 'USD'"
:label="activeUnitLabel"
/>
</q-input>
<!-- <q-input
Expand Down Expand Up @@ -391,6 +391,7 @@ export default defineComponent({
...mapState(useMintsStore, [
"activeProofs",
"activeUnit",
"activeUnitLabel",
"activeMintUrl",
"activeMintBalance",
]),
Expand Down Expand Up @@ -581,7 +582,7 @@ export default defineComponent({
lockTokens: async function () {
let sendAmount = this.sendData.amount;
// if unit is USD, multiply by 100
if (this.activeUnit === "usd") {
if (this.activeUnit === "usd" || this.activeUnit == "eur") {
sendAmount = sendAmount * 100;
}
try {
Expand Down Expand Up @@ -625,7 +626,7 @@ export default defineComponent({
try {
let sendAmount = this.sendData.amount;
// if unit is USD, multiply by 100
if (this.activeUnit === "usd") {
if (this.activeUnit === "usd" || this.activeUnit == "eur") {
sendAmount = sendAmount * 100;
}
// keep firstProofs, send scndProofs and delete them (invalidate=true)
Expand Down
4 changes: 2 additions & 2 deletions src/components/ToggleUnit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
outline
color="primary"
@click="toggleUnit()"
:label="activeUnit == 'sat' ? 'BTC' : 'USD'"
:label="activeUnitLabel"
/>
</template>
<script>
Expand All @@ -26,7 +26,7 @@ export default defineComponent({
mounted() {},
watch: {},
computed: {
...mapState(useMintsStore, ["activeUnit"]),
...mapState(useMintsStore, ["activeUnit", "activeUnitLabel"]),
},
methods: {
...mapActions(useMintsStore, ["toggleUnit"]),
Expand Down
13 changes: 13 additions & 0 deletions src/stores/mints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ export const useMintsStore = defineStore("mints", {
).reduce((sum, p) => sum + p.amount, 0);
return balance
},
activeUnitLabel({ activeUnit }): string {
if (activeUnit == "sat") {
return "SAT";
} else if (activeUnit == "usd") {
return "USD";
} else if (activeUnit == "eur") {
return "EUR";
} else if (activeUnit == "msat") {
return "mSAT";
} else {
return activeUnit;
}
}
},
actions: {
activeMint() {
Expand Down
15 changes: 2 additions & 13 deletions src/stores/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { useLocalStorage } from "@vueuse/core";
const unitTickerShortMap = {
sat: "sats",
usd: "USD",
eur: "EUR",
msat: "msats"
};

export const useUiStore = defineStore("ui", {
Expand All @@ -22,19 +24,6 @@ export const useUiStore = defineStore("ui", {
setTab(tab: string) {
this.tab = tab;
},
formatCurrency: function (value: number, currency: string) {
if (currency == undefined) {
currency = "sat";
}
if (currency == "sat") return this.formatSat(value);
if (currency == "usd") value = value / 100;
return new Intl.NumberFormat(navigator.language, {
style: "currency",
currency: currency,
}).format(value);
// + " " +
// currency.toUpperCase()
},
formatSat: function (value: number) {
return new Intl.NumberFormat(navigator.language).format(value) + " sat";
},
Expand Down
Loading