[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] branch master updated (381a99408 -> 1f2d3dc54)
From: |
gnunet |
Subject: |
[taler-wallet-core] branch master updated (381a99408 -> 1f2d3dc54) |
Date: |
Mon, 27 Nov 2023 17:10:02 +0100 |
This is an automated email from the git hooks/post-receive script.
sebasjm pushed a change to branch master
in repository wallet-core.
from 381a99408 settings
new dc7072304 send error as string
new 5cc00344e DD51 look for currency symbol and split between small and
normal
new 1f2d3dc54 monitor in admin home
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
packages/demobank-ui/src/hooks/circuit.ts | 4 +-
.../src/pages/PaytoWireTransferForm.tsx | 43 ++------------
.../demobank-ui/src/pages/admin/AccountForm.tsx | 1 -
packages/demobank-ui/src/pages/admin/AdminHome.tsx | 58 ++++++++++---------
packages/taler-util/src/amounts.ts | 65 +++++++++++++++++++++-
packages/web-util/src/serve.ts | 2 +-
6 files changed, 99 insertions(+), 74 deletions(-)
diff --git a/packages/demobank-ui/src/hooks/circuit.ts
b/packages/demobank-ui/src/hooks/circuit.ts
index 4686969dc..327a50409 100644
--- a/packages/demobank-ui/src/hooks/circuit.ts
+++ b/packages/demobank-ui/src/hooks/circuit.ts
@@ -290,7 +290,7 @@ export function useLastMonitorInfo(currentMoment: number,
previousMoment: number
const { state: credentials } = useBackendState();
const token = credentials.status !== "loggedIn" ? undefined :
credentials.token
- async function fetcher([token]: [AccessToken]) {
+ async function fetcher([token, timeframe]: [AccessToken,
TalerCorebankApi.MonitorTimeframeParam]) {
const [current, previous] = await Promise.all([
api.getMonitor(token, { timeframe, which: currentMoment }),
api.getMonitor(token, { timeframe, which: previousMoment }),
@@ -302,7 +302,7 @@ export function useLastMonitorInfo(currentMoment: number,
previousMoment: number
}
const { data, error } = useSWR<LastMonitor, TalerHttpError>(
- !config.allow_conversion || !token ? undefined : [token,
"useLastMonitorInfo"], fetcher, {
+ !token ? undefined : [token, timeframe, "useLastMonitorInfo"], fetcher, {
refreshInterval: 0,
refreshWhenHidden: false,
revalidateOnFocus: false,
diff --git a/packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx
b/packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx
index c93388d57..27b26f8b7 100644
--- a/packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx
+++ b/packages/demobank-ui/src/pages/PaytoWireTransferForm.tsx
@@ -16,9 +16,11 @@
import {
AmountJson,
+ AmountLike,
AmountString,
Amounts,
CurrencySpecification,
+ FRAC_SEPARATOR,
Logger,
PaytoString,
TranslatedString,
@@ -469,48 +471,13 @@ export function InputAmount(
);
}
-const FRAC_SEPARATOR = "."
-export function RenderAmount({ value, spec, negative, withColor, allowShort }:
{ spec: CurrencySpecification; value: AmountJson, allowShort?: boolean,
negative?: boolean, withColor?: boolean }): VNode {
+export function RenderAmount({ value, spec, negative, withColor, hideSmall }:
{ spec: CurrencySpecification; value: AmountJson, hideSmall?: boolean,
negative?: boolean, withColor?: boolean }): VNode {
const neg = !!negative //convert to true or false
- const str = Amounts.stringifyValue(value)
- const pos = str.indexOf(FRAC_SEPARATOR)
- const sep_pos = pos < 0 ? 0 : pos;
- let currency = value.currency
- const names = Object.keys(spec.alt_unit_names)
- let smallerIndex: string = "0"
- if (names.length > 1) {
- let indexSize = sep_pos
- Object.keys(spec.alt_unit_names).forEach(index => {
- const i = Number.parseInt(index, 10)
- if (Number.isNaN(i)) return;
- if (sep_pos - i < indexSize) {
- indexSize = sep_pos - i;
- smallerIndex = index
- }
- })
- currency = spec.alt_unit_names[smallerIndex]
- } else if (names.length === 1) {
- currency = names[0]
- }
+ const { currency, normal, small } = Amounts.stringifyValueWithSpec(value,
spec)
- let normal: string;
- let small: string | undefined;
- if (sep_pos && str.length - sep_pos - 1 > spec.num_fractional_normal_digits)
{
- const limit = sep_pos + spec.num_fractional_normal_digits + 1
- normal = str.substring(0, limit)
- small = str.substring(limit)
- } else {
- normal = str
- small = undefined
- }
-
-
- if (allowShort) {
- // const int_part = str.substring(0, sep_pos)
- }
return <span data-negative={withColor ? neg : undefined}
class="whitespace-nowrap data-[negative=false]:text-green-600
data-[negative=true]:text-red-600">
{negative ? "-" : undefined}
- {currency} {normal} {small && <sup class="-ml-1">{small}</sup>}
+ {currency} {normal} {!hideSmall && small && <sup
class="-ml-1">{small}</sup>}
</span>
}
\ No newline at end of file
diff --git a/packages/demobank-ui/src/pages/admin/AccountForm.tsx
b/packages/demobank-ui/src/pages/admin/AccountForm.tsx
index 526deeeab..c2afb195a 100644
--- a/packages/demobank-ui/src/pages/admin/AccountForm.tsx
+++ b/packages/demobank-ui/src/pages/admin/AccountForm.tsx
@@ -46,7 +46,6 @@ export function AccountForm({
const { i18n } = useTranslationContext();
function updateForm(newForm: typeof initial): void {
- console.log(newForm)
const parsed = !newForm.cashout_payto_uri
? undefined
: buildPayto("iban", newForm.cashout_payto_uri, undefined);;
diff --git a/packages/demobank-ui/src/pages/admin/AdminHome.tsx
b/packages/demobank-ui/src/pages/admin/AdminHome.tsx
index 22090f83a..1892acfce 100644
--- a/packages/demobank-ui/src/pages/admin/AdminHome.tsx
+++ b/packages/demobank-ui/src/pages/admin/AdminHome.tsx
@@ -1,9 +1,9 @@
-import { AmountString, Amounts, TalerCorebankApi, TalerError,
assertUnreachable } from "@gnu-taler/taler-util";
+import { AmountString, Amounts, CurrencySpecification, TalerCorebankApi,
TalerError, assertUnreachable } from "@gnu-taler/taler-util";
import { ErrorLoading, useTranslationContext } from
"@gnu-taler/web-util/browser";
import { Fragment, VNode, h } from "preact";
import { useState } from "preact/hooks";
import { Transactions } from "../../components/Transactions/index.js";
-import { useLastMonitorInfo } from "../../hooks/circuit.js";
+import { useConversionInfo, useLastMonitorInfo } from "../../hooks/circuit.js";
import { RenderAmount } from "../PaytoWireTransferForm.js";
import { WireTransfer } from "../WireTransfer.js";
import { AccountList } from "./AccountList.js";
@@ -83,7 +83,8 @@ function getTimeframesForDate(time: Date, timeframe:
TalerCorebankApi.MonitorTim
function Metrics(): VNode {
const { i18n } = useTranslationContext()
const [metricType, setMetricType] =
useState<TalerCorebankApi.MonitorTimeframeParam>(TalerCorebankApi.MonitorTimeframeParam.hour);
-
+ const { config } = useBankCoreApiContext();
+ const respInfo = useConversionInfo()
const params = getTimeframesForDate(new Date(), metricType)
const resp = useLastMonitorInfo(params.current, params.previous, metricType);
@@ -91,13 +92,10 @@ function Metrics(): VNode {
if (resp instanceof TalerError) {
return <ErrorLoading error={resp} />
}
- if (resp.current.type !== "ok" || resp.current.type !== "ok" ||
resp.current.type !== "ok") {
+ if (resp.current.type !== "ok" || resp.previous.type !== "ok") {
return <Fragment />
}
- if (resp.previous.type !== "ok" || resp.previous.type !== "ok" ||
resp.previous.type !== "ok") {
- return <Fragment />
- }
-
+ const fiatSpec = respInfo && (!(respInfo instanceof TalerError)) ?
respInfo.body.fiat_currency_specification : undefined
return <Fragment>
<div class="sm:hidden">
<label for="tabs" class="sr-only"><i18n.Translate>Select a
section</i18n.Translate></label>
@@ -137,9 +135,9 @@ function Metrics(): VNode {
<i18n.Translate>Trading volume on {getDateForTimeframe(params.current,
metricType)} compared to {getDateForTimeframe(params.previous,
metricType)}</i18n.Translate>
</h1>
</div>
- <dl class="mt-5 grid grid-cols-1 md:grid-cols-1 divide-y divide-gray-200
overflow-hidden rounded-lg bg-white shadow-lg md:divide-x md:divide-y-0">
+ <dl class="mt-5 grid grid-cols-1 md:grid-cols-2 divide-y divide-gray-200
overflow-hidden rounded-lg bg-white shadow-lg md:divide-x md:divide-y-0">
- {resp.current.body.type !== "with-conversions" ||
resp.previous.body.type !== "with-conversions" ? undefined :
+ {!fiatSpec || resp.current.body.type !== "with-conversions" ||
resp.previous.body.type !== "with-conversions" ? undefined :
<Fragment>
<div class="px-4 py-5 sm:p-6">
<dt class="text-base font-normal text-gray-900">
@@ -148,6 +146,7 @@ function Metrics(): VNode {
<MetricValue
current={resp.current.body.cashinFiatVolume}
previous={resp.previous.body.cashinFiatVolume}
+ spec={fiatSpec}
/>
</div>
<div class="px-4 py-5 sm:p-6">
@@ -157,6 +156,7 @@ function Metrics(): VNode {
<MetricValue
current={resp.current.body.cashoutFiatVolume}
previous={resp.previous.body.cashoutFiatVolume}
+ spec={fiatSpec}
/>
</div>
</Fragment>
@@ -168,6 +168,7 @@ function Metrics(): VNode {
<MetricValue
current={resp.current.body.talerInVolume}
previous={resp.previous.body.talerInVolume}
+ spec={config.currency_specification}
/>
</div>
<div class="px-4 py-5 sm:p-6">
@@ -177,6 +178,7 @@ function Metrics(): VNode {
<MetricValue
current={resp.current.body.talerOutVolume}
previous={resp.previous.body.talerOutVolume}
+ spec={config.currency_specification}
/>
</div>
</dl>
@@ -185,11 +187,11 @@ function Metrics(): VNode {
}
-function MetricValue({ current, previous }: { current: AmountString |
undefined, previous: AmountString | undefined }): VNode {
+function MetricValue({ current, previous, spec }: { spec:
CurrencySpecification, current: AmountString | undefined, previous:
AmountString | undefined }): VNode {
const { i18n } = useTranslationContext()
- const { config } = useBankCoreApiContext();
const cmp = current && previous ? Amounts.cmp(current, previous) : 0;
- const currAmount = !current ? undefined :
Number.parseFloat(Amounts.stringifyValue(current))
+ const cv = !current ? undefined : Amounts.stringifyValue(current)
+ const currAmount = !cv ? undefined : Number.parseFloat(cv)
const prevAmount = !previous ? undefined :
Number.parseFloat(Amounts.stringifyValue(previous))
const rate = !currAmount || Number.isNaN(currAmount) || !prevAmount ||
Number.isNaN(prevAmount) ? 0 :
@@ -198,34 +200,30 @@ function MetricValue({ current, previous }: { current:
AmountString | undefined,
const negative = cmp === 0 ? undefined : cmp === -1
const rateStr = `${(Math.abs(rate) * 100).toFixed(2)}%`
- const pepe = "QWEQWEQWEWw:111111174523848.85229681"
- function size(s: string = ""): "lg" | "md" | "sm" {
- return s.length < 10 ? "sm" : s.length > 20 ? "lg" : "md";
- }
return <Fragment>
<dd class="mt-1 block ">
- <div data-size={size(pepe)} class="flex justify-start
- data-[size=sm]:text-2xl
- data-[size=md]:text-lg
- data-[size=lg]:text-sm
- items-baseline
- font-semibold text-indigo-600">
- {!current ? "-" : <RenderAmount value={Amounts.parseOrThrow(pepe)}
spec={config.currency_specification} />}
+ <div class="flex justify-start text-2xl items-baseline font-semibold
text-indigo-600">
+ {!current ? "-" : <RenderAmount value={Amounts.parseOrThrow(current)}
spec={spec} hideSmall />}
</div>
- {pepe.length}
- <div style={{ width: 16, height: 16, border: "1px solid red" }} />
<div class="flex flex-col">
<div class="flex justify-end items-baseline text-2xl font-semibold
text-indigo-600">
<small class="ml-2 text-sm font-medium text-gray-500">
- <i18n.Translate>from</i18n.Translate> {!previous ? "-" :
<RenderAmount value={Amounts.parseOrThrow(previous)}
spec={config.currency_specification} />}
+ <i18n.Translate>from</i18n.Translate> {!previous ? "-" :
<RenderAmount value={Amounts.parseOrThrow(previous)} spec={spec} hideSmall />}
</small>
</div>
{negative !== undefined &&
<span data-negative={negative} class="flex items-center gap-x-1.5
w-fit rounded-md bg-green-100 text-green-800 data-[negative=true]:bg-red-100
px-2 py-1 text-xs font-medium data-[negative=true]:text-red-700 whitespace-pre">
- <svg class="h-5 w-5 self-center
data-[negative=false]:text-green-500 data-[negative=true]:text-red-500"
viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
- <path fill-rule="evenodd" d="M10 3a.75.75 0
01.75.75v10.638l3.96-4.158a.75.75 0 111.08 1.04l-5.25 5.5a.75.75 0 01-1.08
0l-5.25-5.5a.75.75 0 111.08-1.04l3.96 4.158V3.75A.75.75 0 0110 3z"
clip-rule="evenodd" />
- </svg>
+ {negative ?
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0
24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
+ <path stroke-linecap="round" stroke-linejoin="round" d="M12
4.5v15m0 0l6.75-6.75M12 19.5l-6.75-6.75" />
+ </svg>
+ :
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0
24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
+ <path stroke-linecap="round" stroke-linejoin="round" d="M12
19.5v-15m0 0l-6.75 6.75M12 4.5l6.75 6.75" />
+ </svg>
+ }
+
{negative ?
<span class="sr-only"><i18n.Translate>Descreased
by</i18n.Translate></span> :
<span class="sr-only"><i18n.Translate>Increased
by</i18n.Translate></span>
diff --git a/packages/taler-util/src/amounts.ts
b/packages/taler-util/src/amounts.ts
index 5c6444b00..76ba3a0c5 100644
--- a/packages/taler-util/src/amounts.ts
+++ b/packages/taler-util/src/amounts.ts
@@ -30,6 +30,7 @@ import {
DecodingError,
renderContext,
} from "./codec.js";
+import { CurrencySpecification } from "./index.js";
import { AmountString } from "./taler-types.js";
/**
@@ -49,6 +50,11 @@ export const amountFractionalLength = 8;
*/
export const amountMaxValue = 2 ** 52;
+/**
+ * Separator character between interger and fractional
+ */
+export const FRAC_SEPARATOR = "."
+
/**
* Non-negative financial amount. Fractional values are expressed as multiples
* of 1e-8.
@@ -373,7 +379,7 @@ export class Amounts {
if (!res) {
return undefined;
}
- const tail = res[3] || ".0";
+ const tail = res[3] || (FRAC_SEPARATOR + "0");
if (tail.length > amountFractionalLength + 1) {
return undefined;
}
@@ -508,7 +514,7 @@ export class Amounts {
let s = av.toString();
if (af || minFractional) {
- s = s + ".";
+ s = s + FRAC_SEPARATOR;
let n = af;
for (let i = 0; i < amountFractionalLength; i++) {
if (!n && i >= minFractional) {
@@ -543,4 +549,59 @@ export class Amounts {
}
return amountFractionalLength - i + 1;
}
+
+
+ static stringifyValueWithSpec(value: AmountJson, spec:
CurrencySpecification): { currency: string, normal: string, small?: string } {
+ const strValue = Amounts.stringifyValue(value)
+ const pos = strValue.indexOf(FRAC_SEPARATOR)
+ const originalPosition = pos < 0 ? strValue.length : pos;
+
+ let currency = value.currency
+ const names = Object.keys(spec.alt_unit_names)
+ let FRAC_POS_NEW_POSITION = originalPosition
+ //find symbol
+ //FIXME: this should be based on a cache to speed up
+ if (names.length > 0) {
+ let unitIndex: string = "0" //default entry by DD51
+ names.forEach(index => {
+ const i = Number.parseInt(index, 10)
+ if (Number.isNaN(i)) return; //skip
+ if (originalPosition - i <= 0) return; //too big
+ if (originalPosition - i < FRAC_POS_NEW_POSITION) {
+ FRAC_POS_NEW_POSITION = originalPosition - i;
+ unitIndex = index
+ }
+ })
+ currency = spec.alt_unit_names[unitIndex]
+ }
+
+ if (originalPosition === FRAC_POS_NEW_POSITION) {
+ const { normal, small } = splitNormalAndSmall(strValue,
originalPosition, spec)
+ return { currency, normal, small }
+ }
+
+ const intPart = strValue.substring(0, originalPosition)
+ const fracPArt = strValue.substring(originalPosition + 1)
+ //indexSize is always smaller than originalPosition
+ const newValue = intPart.substring(0, FRAC_POS_NEW_POSITION) +
FRAC_SEPARATOR + intPart.substring(FRAC_POS_NEW_POSITION) + fracPArt
+ const { normal, small } = splitNormalAndSmall(newValue,
FRAC_POS_NEW_POSITION, spec)
+ return { currency, normal, small }
+ }
+
+
+}
+
+function splitNormalAndSmall(decimal: string, fracSeparatorIndex: number,
spec: CurrencySpecification): { normal: string, small?: string } {
+ let normal: string;
+ let small: string | undefined;
+ if (decimal.length - fracSeparatorIndex - 1 >
spec.num_fractional_normal_digits) {
+ const limit = fracSeparatorIndex + spec.num_fractional_normal_digits + 1
+ normal = decimal.substring(0, limit)
+ small = decimal.substring(limit)
+ } else {
+ normal = decimal
+ small = undefined
+ }
+ return { normal, small }
}
+
diff --git a/packages/web-util/src/serve.ts b/packages/web-util/src/serve.ts
index 93d8082fe..3d2744bb9 100644
--- a/packages/web-util/src/serve.ts
+++ b/packages/web-util/src/serve.ts
@@ -93,7 +93,7 @@ export async function serve(opts: {
.catch((error) => {
sendToAllClients({
type: "file-updated-failed",
- data: { path, error },
+ data: { path, error: JSON.stringify(error) },
});
});
} else {
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-wallet-core] branch master updated (381a99408 -> 1f2d3dc54),
gnunet <=