From 9a1007775fb986e18865c3d9b4352bd80622b31e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Leal?= <30505180+JooVLC@users.noreply.github.com> Date: Fri, 26 May 2023 07:32:22 -0300 Subject: [PATCH] Fix bug with negative premium textfield (#614) Fixing the type handlePremiumChange function to handle the discount to the right type (React.ChangeEventHandler) Using the correct type of handlePremiumChange function, then deconstructing the "value" var from the event.target Using Number(value) in declaration of "newPremium", instead of using multiplication with number and string To not affect another methods using "premium" var, I used isNaN func to make a check and set the initial value of "premium" var to zero (if is NaN) or newPremium (when valid number is entered) The fix in the bug is the line "premium: isNaN(newPremium) || value === '' ? '' : premium," in setMaker. That makes the "premium" var to be set to zero when the input is empty or not a number, allowing the user to input the "-" (minus sign) and not entering 0 as before. --- .../src/components/MakerForm/MakerForm.tsx | 43 ++++++++++--------- frontend/static/locales/ca.json | 1 + frontend/static/locales/collect_phrases.py | 8 ++-- frontend/static/locales/cs.json | 1 + frontend/static/locales/de.json | 1 + frontend/static/locales/en.json | 1 + frontend/static/locales/es.json | 1 + frontend/static/locales/eu.json | 1 + frontend/static/locales/fr.json | 1 + frontend/static/locales/it.json | 1 + frontend/static/locales/ja.json | 1 + frontend/static/locales/pl.json | 1 + frontend/static/locales/pt.json | 1 + frontend/static/locales/ru.json | 1 + frontend/static/locales/sv.json | 1 + frontend/static/locales/th.json | 1 + frontend/static/locales/zh-SI.json | 1 + frontend/static/locales/zh-TR.json | 1 + 18 files changed, 43 insertions(+), 24 deletions(-) diff --git a/frontend/src/components/MakerForm/MakerForm.tsx b/frontend/src/components/MakerForm/MakerForm.tsx index 6059829b..dd1632e1 100644 --- a/frontend/src/components/MakerForm/MakerForm.tsx +++ b/frontend/src/components/MakerForm/MakerForm.tsx @@ -181,27 +181,28 @@ const MakerForm = ({ }); }; - const handlePremiumChange = function (e: object) { - const max = fav.mode === 'fiat' ? 999 : 99; - const min = -100; - const newPremium = Math.floor(e.target.value * Math.pow(10, 2)) / Math.pow(10, 2); - let premium: number = newPremium; - let badPremiumText: string = ''; - if (newPremium > 999) { - badPremiumText = t('Must be less than {{max}}%', { max }); - premium = 999; - } else if (newPremium <= -100) { - badPremiumText = t('Must be more than {{min}}%', { min }); - premium = -99.99; - } - updateCurrentPrice(limits.list, fav.currency, premium); - updateAmountLimits(limits.list, fav.currency, premium); - setMaker({ - ...maker, - premium, - badPremiumText, - }); - }; + const handlePremiumChange: React.ChangeEventHandler = + function ({ target: { value } }) { + const max = fav.mode === 'fiat' ? 999 : 99; + const min = -100; + const newPremium = Math.floor(Number(value) * Math.pow(10, 2)) / Math.pow(10, 2); + let premium: number = isNaN(newPremium) ? 0 : newPremium; + let badPremiumText: string = ''; + if (newPremium > 999) { + badPremiumText = t('Must be less than {{max}}%', { max }); + premium = 999; + } else if (newPremium <= -100) { + badPremiumText = t('Must be more than {{min}}%', { min }); + premium = -99.99; + } + updateCurrentPrice(limits.list, fav.currency, premium); + updateAmountLimits(limits.list, fav.currency, premium); + setMaker({ + ...maker, + premium: isNaN(newPremium) || value === '' ? '' : premium, + badPremiumText, + }); + }; const handleSatoshisChange = function (e: object) { const newSatoshis = e.target.value; diff --git a/frontend/static/locales/ca.json b/frontend/static/locales/ca.json index a6b5b832..885621f9 100644 --- a/frontend/static/locales/ca.json +++ b/frontend/static/locales/ca.json @@ -268,6 +268,7 @@ "#26": "Phrases in components/Dialogs/Stats.tsx", "... somewhere on Earth!": "... en algun indret de la Terra!", "24h contracted volume": "Volum contractat en 24h", + "CLN version": "CLN version", "Client": "Client", "Coordinator": "Coordinador", "Coordinator commit hash": "Coordinator commit hash", diff --git a/frontend/static/locales/collect_phrases.py b/frontend/static/locales/collect_phrases.py index 9b585472..29c0a1be 100644 --- a/frontend/static/locales/collect_phrases.py +++ b/frontend/static/locales/collect_phrases.py @@ -47,7 +47,7 @@ locales = [f for f in os.listdir(".") if f.endswith(".json")] for locale in locales: new_phrases = OrderedDict() with open(locale, "r", encoding="utf-8") as f: - old_phrases = json.load(f) + old_phrases = json.load(f, object_pairs_hook=OrderedDict) for key in all_phrases.keys(): # update dictionary with new keys on /src/, but ignore the counter of files keys if key in old_phrases and not re.match(r"^#\d+$", key): @@ -55,8 +55,10 @@ for locale in locales: else: new_phrases[key] = all_phrases[key] - with open(locale, "w", encoding="utf-8") as f: - json.dump(new_phrases, f, ensure_ascii=False) + # don't change the file if there aren't new keys (order matters) + if new_phrases != old_phrases: + with open(locale, "w", encoding="utf-8") as f: + json.dump(new_phrases, f, ensure_ascii=False) with open("./collected_phrases.json", "w", encoding="utf-8") as f: json.dump(all_phrases, f, ensure_ascii=False) diff --git a/frontend/static/locales/cs.json b/frontend/static/locales/cs.json index 8384e50e..350fd3b4 100644 --- a/frontend/static/locales/cs.json +++ b/frontend/static/locales/cs.json @@ -268,6 +268,7 @@ "#26": "Phrases in components/Dialogs/Stats.tsx", "... somewhere on Earth!": "... někde na Zemi!", "24h contracted volume": "Zobchodované množství za 24h", + "CLN version": "CLN version", "Client": "Client", "Coordinator": "Coordinator", "Coordinator commit hash": "Coordinator commit hash", diff --git a/frontend/static/locales/de.json b/frontend/static/locales/de.json index e1ad56a0..447a604c 100644 --- a/frontend/static/locales/de.json +++ b/frontend/static/locales/de.json @@ -268,6 +268,7 @@ "#26": "Phrases in components/Dialogs/Stats.tsx", "... somewhere on Earth!": "... irgendwo auf der Erde!", "24h contracted volume": "24h Handelsvolumen", + "CLN version": "CLN version", "Client": "Client", "Coordinator": "Coordinator", "Coordinator commit hash": "Coordinator commit hash", diff --git a/frontend/static/locales/en.json b/frontend/static/locales/en.json index 5bf9cbc5..0f80d2e6 100644 --- a/frontend/static/locales/en.json +++ b/frontend/static/locales/en.json @@ -268,6 +268,7 @@ "#26": "Phrases in components/Dialogs/Stats.tsx", "... somewhere on Earth!": "... somewhere on Earth!", "24h contracted volume": "24h contracted volume", + "CLN version": "CLN version", "Client": "Client", "Coordinator": "Coordinator", "Coordinator commit hash": "Coordinator commit hash", diff --git a/frontend/static/locales/es.json b/frontend/static/locales/es.json index 436e9796..021a08a3 100644 --- a/frontend/static/locales/es.json +++ b/frontend/static/locales/es.json @@ -268,6 +268,7 @@ "#26": "Phrases in components/Dialogs/Stats.tsx", "... somewhere on Earth!": "... en algún lugar de La Tierra!", "24h contracted volume": "Volumen de los contratos en 24h", + "CLN version": "CLN version", "Client": "Cliente", "Coordinator": "Coordinador", "Coordinator commit hash": "Hash de confirmación del coordinador", diff --git a/frontend/static/locales/eu.json b/frontend/static/locales/eu.json index 8ab61d72..986997a6 100644 --- a/frontend/static/locales/eu.json +++ b/frontend/static/locales/eu.json @@ -268,6 +268,7 @@ "#26": "Phrases in components/Dialogs/Stats.tsx", "... somewhere on Earth!": "... Lurreko lekuren batean!", "24h contracted volume": "24 ordutan kontratatutako bolumena", + "CLN version": "CLN version", "Client": "Bezeroa", "Coordinator": "Koordinatzailea", "Coordinator commit hash": "Coordinator commit hash", diff --git a/frontend/static/locales/fr.json b/frontend/static/locales/fr.json index f9eb7862..33e46993 100644 --- a/frontend/static/locales/fr.json +++ b/frontend/static/locales/fr.json @@ -268,6 +268,7 @@ "#26": "Phrases in components/Dialogs/Stats.tsx", "... somewhere on Earth!": "... quelque part sur Terre!", "24h contracted volume": "Volume contracté en 24h", + "CLN version": "CLN version", "Client": "Client", "Coordinator": "Coordinator", "Coordinator commit hash": "Coordinator commit hash", diff --git a/frontend/static/locales/it.json b/frontend/static/locales/it.json index 7093f6a9..c6647bde 100644 --- a/frontend/static/locales/it.json +++ b/frontend/static/locales/it.json @@ -268,6 +268,7 @@ "#26": "Phrases in components/Dialogs/Stats.tsx", "... somewhere on Earth!": "... da qualche parte sulla Terra!", "24h contracted volume": "Volume scambiato in 24h", + "CLN version": "CLN version", "Client": "Client", "Coordinator": "Coordinator", "Coordinator commit hash": "Coordinator commit hash", diff --git a/frontend/static/locales/ja.json b/frontend/static/locales/ja.json index 446436ce..78f15d31 100644 --- a/frontend/static/locales/ja.json +++ b/frontend/static/locales/ja.json @@ -268,6 +268,7 @@ "#26": "Phrases in components/Dialogs/Stats.tsx", "... somewhere on Earth!": "......地球上のどっかから!", "24h contracted volume": "24時間の契約量", + "CLN version": "CLN version", "Client": "クライアント", "Coordinator": "コーディネーター", "Coordinator commit hash": "コーディネーターコミットハッシュ", diff --git a/frontend/static/locales/pl.json b/frontend/static/locales/pl.json index 64f77e90..66b70025 100644 --- a/frontend/static/locales/pl.json +++ b/frontend/static/locales/pl.json @@ -268,6 +268,7 @@ "#26": "Phrases in components/Dialogs/Stats.tsx", "... somewhere on Earth!": "... gdzieś na Ziemi!", "24h contracted volume": "Zakontraktowana objętość 24h", + "CLN version": "CLN version", "Client": "Client", "Coordinator": "Coordinator", "Coordinator commit hash": "Coordinator commit hash", diff --git a/frontend/static/locales/pt.json b/frontend/static/locales/pt.json index 362f2a97..6d343bc8 100644 --- a/frontend/static/locales/pt.json +++ b/frontend/static/locales/pt.json @@ -268,6 +268,7 @@ "#26": "Phrases in components/Dialogs/Stats.tsx", "... somewhere on Earth!": "... alguém na terra!", "24h contracted volume": "Volume contratado em 24h", + "CLN version": "CLN version", "Client": "Client", "Coordinator": "Coordinator", "Coordinator commit hash": "Coordinator commit hash", diff --git a/frontend/static/locales/ru.json b/frontend/static/locales/ru.json index 9bb57831..89c663f9 100644 --- a/frontend/static/locales/ru.json +++ b/frontend/static/locales/ru.json @@ -268,6 +268,7 @@ "#26": "Phrases in components/Dialogs/Stats.tsx", "... somewhere on Earth!": "... где-то на земле!", "24h contracted volume": "Объём контрактов за 24 часа", + "CLN version": "CLN version", "Client": "Client", "Coordinator": "Coordinator", "Coordinator commit hash": "Coordinator commit hash", diff --git a/frontend/static/locales/sv.json b/frontend/static/locales/sv.json index 14f2241f..2befcd74 100644 --- a/frontend/static/locales/sv.json +++ b/frontend/static/locales/sv.json @@ -268,6 +268,7 @@ "#26": "Phrases in components/Dialogs/Stats.tsx", "... somewhere on Earth!": "... någonstans på jorden!", "24h contracted volume": "24h kontrakterad volym", + "CLN version": "CLN version", "Client": "Client", "Coordinator": "Coordinator", "Coordinator commit hash": "Coordinator commit hash", diff --git a/frontend/static/locales/th.json b/frontend/static/locales/th.json index 40bc6a59..927e4b9c 100644 --- a/frontend/static/locales/th.json +++ b/frontend/static/locales/th.json @@ -268,6 +268,7 @@ "#26": "Phrases in components/Dialogs/Stats.tsx", "... somewhere on Earth!": "... ซักที่ บนโลกใบนี้!", "24h contracted volume": "24h ปริมาณการซื้อขาย 24 ชั่วโมงที่แล้ว", + "CLN version": "CLN version", "Client": "Client", "Coordinator": "Coordinator", "Coordinator commit hash": "Coordinator commit hash", diff --git a/frontend/static/locales/zh-SI.json b/frontend/static/locales/zh-SI.json index efba59ee..e36e2065 100644 --- a/frontend/static/locales/zh-SI.json +++ b/frontend/static/locales/zh-SI.json @@ -268,6 +268,7 @@ "#26": "Phrases in components/Dialogs/Stats.tsx", "... somewhere on Earth!": "...在世界上某处建造!", "24h contracted volume": "24小时合约量", + "CLN version": "CLN version", "Client": "客户端", "Coordinator": "协调器", "Coordinator commit hash": "协调器提交哈希", diff --git a/frontend/static/locales/zh-TR.json b/frontend/static/locales/zh-TR.json index eda8b6c9..9abb9fbc 100644 --- a/frontend/static/locales/zh-TR.json +++ b/frontend/static/locales/zh-TR.json @@ -268,6 +268,7 @@ "#26": "Phrases in components/Dialogs/Stats.tsx", "... somewhere on Earth!": "...在世界上某處製造!", "24h contracted volume": "24小時合約量", + "CLN version": "CLN version", "Client": "客戶端", "Coordinator": "協調器", "Coordinator commit hash": "協調器提交哈希",