fix #7497
This commit is contained in:
parent
3577227cc0
commit
219e48f351
@ -468,7 +468,7 @@ export class Amounts {
|
|||||||
const af = aJ.fraction % amountFractionalBase;
|
const af = aJ.fraction % amountFractionalBase;
|
||||||
let s = av.toString();
|
let s = av.toString();
|
||||||
|
|
||||||
if (af) {
|
if (af || minFractional) {
|
||||||
s = s + ".";
|
s = s + ".";
|
||||||
let n = af;
|
let n = af;
|
||||||
for (let i = 0; i < amountFractionalLength; i++) {
|
for (let i = 0; i < amountFractionalLength; i++) {
|
||||||
|
@ -193,6 +193,16 @@ VNode {
|
|||||||
|
|
||||||
export function WalletNavBar({ path = "" }: { path?: string }): VNode {
|
export function WalletNavBar({ path = "" }: { path?: string }): VNode {
|
||||||
const { i18n } = useTranslationContext();
|
const { i18n } = useTranslationContext();
|
||||||
|
|
||||||
|
const api = wxApi; //FIXME: as parameter
|
||||||
|
const hook = useAsyncAsHook(async () => {
|
||||||
|
return await api.wallet.call(
|
||||||
|
WalletApiOperation.GetUserAttentionUnreadCount,
|
||||||
|
{},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
const attentionCount = !hook || hook.hasError ? 0 : hook.response.total;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NavigationHeaderHolder>
|
<NavigationHeaderHolder>
|
||||||
<NavigationHeader>
|
<NavigationHeader>
|
||||||
@ -209,9 +219,13 @@ export function WalletNavBar({ path = "" }: { path?: string }): VNode {
|
|||||||
<i18n.Translate>Backup</i18n.Translate>
|
<i18n.Translate>Backup</i18n.Translate>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
{attentionCount > 0 ? (
|
||||||
<a href={Pages.notifications}>
|
<a href={Pages.notifications}>
|
||||||
<i18n.Translate>Notifications</i18n.Translate>
|
<i18n.Translate>Notifications</i18n.Translate>
|
||||||
</a>
|
</a>
|
||||||
|
) : (
|
||||||
|
<Fragment />
|
||||||
|
)}
|
||||||
|
|
||||||
<JustInDevMode>
|
<JustInDevMode>
|
||||||
<a href={Pages.dev} class={path.startsWith("/dev") ? "active" : ""}>
|
<a href={Pages.dev} class={path.startsWith("/dev") ? "active" : ""}>
|
||||||
|
@ -44,7 +44,9 @@ export function AmountField({
|
|||||||
handler: AmountFieldHandler;
|
handler: AmountFieldHandler;
|
||||||
}): VNode {
|
}): VNode {
|
||||||
const [unit, setUnit] = useState(1);
|
const [unit, setUnit] = useState(1);
|
||||||
const [dotAtTheEnd, setDotAtTheEnd] = useState(false);
|
const [decimalPlaces, setDecimalPlaces] = useState<number | undefined>(
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
const currency = handler.value.currency;
|
const currency = handler.value.currency;
|
||||||
|
|
||||||
let hd = Math.floor(Math.log10(highestDenom || 1) / 3);
|
let hd = Math.floor(Math.log10(highestDenom || 1) / 3);
|
||||||
@ -72,10 +74,18 @@ export function AmountField({
|
|||||||
ld--;
|
ld--;
|
||||||
}
|
}
|
||||||
|
|
||||||
const prev = Amounts.stringifyValue(handler.value);
|
const previousValue = Amounts.stringifyValue(handler.value, decimalPlaces);
|
||||||
|
|
||||||
|
const normal = denormalize(handler.value, unit) ?? handler.value;
|
||||||
|
|
||||||
|
let textValue = Amounts.stringifyValue(normal, decimalPlaces);
|
||||||
|
if (decimalPlaces === 0) {
|
||||||
|
textValue += ".";
|
||||||
|
}
|
||||||
|
|
||||||
function positiveAmount(value: string): string {
|
function positiveAmount(value: string): string {
|
||||||
setDotAtTheEnd(value.endsWith("."));
|
// setDotAtTheEnd(value.endsWith("."));
|
||||||
|
// const dotAtTheEnd = value.endsWith(".");
|
||||||
if (!value) {
|
if (!value) {
|
||||||
if (handler.onInput) {
|
if (handler.onInput) {
|
||||||
handler.onInput(Amounts.zeroOfCurrency(currency));
|
handler.onInput(Amounts.zeroOfCurrency(currency));
|
||||||
@ -85,28 +95,30 @@ export function AmountField({
|
|||||||
try {
|
try {
|
||||||
//remove all but last dot
|
//remove all but last dot
|
||||||
const parsed = value.replace(/(\.)(?=.*\1)/g, "");
|
const parsed = value.replace(/(\.)(?=.*\1)/g, "");
|
||||||
|
const parts = parsed.split(".");
|
||||||
|
setDecimalPlaces(parts.length === 1 ? undefined : parts[1].length);
|
||||||
|
|
||||||
|
//FIXME: should normalize before parsing
|
||||||
|
//parsing first add some restriction on the rage of the values
|
||||||
const real = parseValue(currency, parsed);
|
const real = parseValue(currency, parsed);
|
||||||
|
|
||||||
if (!real || real.value < 0) {
|
if (!real || real.value < 0) {
|
||||||
return prev;
|
return previousValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const normal = normalize(real, unit);
|
const realNormalized = normalize(real, unit);
|
||||||
|
|
||||||
console.log(real, unit, normal);
|
// console.log(real, unit, normal);
|
||||||
if (normal && handler.onInput) {
|
if (realNormalized && handler.onInput) {
|
||||||
handler.onInput(normal);
|
handler.onInput(realNormalized);
|
||||||
}
|
}
|
||||||
return parsed;
|
return parsed;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
return prev;
|
return previousValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const normal = denormalize(handler.value, unit) ?? handler.value;
|
|
||||||
|
|
||||||
const textValue = Amounts.stringifyValue(normal) + (dotAtTheEnd ? "." : "");
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<TextField
|
<TextField
|
||||||
@ -161,19 +173,21 @@ export function AmountField({
|
|||||||
|
|
||||||
function parseValue(currency: string, s: string): AmountJson | undefined {
|
function parseValue(currency: string, s: string): AmountJson | undefined {
|
||||||
const [intPart, fractPart] = s.split(".");
|
const [intPart, fractPart] = s.split(".");
|
||||||
const tail = "." + (fractPart || "0");
|
const tailPart = !fractPart
|
||||||
if (tail.length > amountFractionalLength + 1) {
|
? "0"
|
||||||
return undefined;
|
: fractPart.substring(0, amountFractionalLength);
|
||||||
}
|
|
||||||
const value = Number.parseInt(intPart, 10);
|
const value = Number.parseInt(intPart, 10);
|
||||||
if (Number.isNaN(value) || value > amountMaxValue) {
|
const parsedTail = Number.parseFloat(`.${tailPart}`);
|
||||||
|
if (Number.isNaN(value) || Number.isNaN(parsedTail)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return {
|
if (value > amountMaxValue) {
|
||||||
currency,
|
return undefined;
|
||||||
fraction: Math.round(amountFractionalBase * Number.parseFloat(tail)),
|
}
|
||||||
value,
|
|
||||||
};
|
const fraction = Math.round(amountFractionalBase * parsedTail);
|
||||||
|
return { currency, fraction, value };
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalize(amount: AmountJson, unit: number): AmountJson | undefined {
|
function normalize(amount: AmountJson, unit: number): AmountJson | undefined {
|
||||||
|
@ -203,6 +203,7 @@ export function SettingsView({
|
|||||||
</DestructiveText>
|
</DestructiveText>
|
||||||
);
|
);
|
||||||
case ExchangeTosStatus.Unknown:
|
case ExchangeTosStatus.Unknown:
|
||||||
|
default:
|
||||||
return (
|
return (
|
||||||
<DestructiveText>
|
<DestructiveText>
|
||||||
<i18n.Translate>
|
<i18n.Translate>
|
||||||
|
Loading…
Reference in New Issue
Block a user