From 1cbad38f50d0b15eef001a4dd440c4a692c2466f Mon Sep 17 00:00:00 2001 From: Ivan Vershigora Date: Tue, 28 May 2024 12:17:09 +0100 Subject: [PATCH] fix: PinPad race condition 2 --- src/screens/Settings/PIN/ChangePin.tsx | 15 +++++++-------- src/screens/Settings/PIN/ChangePin2.tsx | 15 +++++++-------- src/screens/Settings/PIN/ChoosePIN.tsx | 15 +++++++-------- src/screens/Wallets/Send/SendPinPad.tsx | 15 +++++++-------- 4 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/screens/Settings/PIN/ChangePin.tsx b/src/screens/Settings/PIN/ChangePin.tsx index f480d46d9..a49ee5cde 100644 --- a/src/screens/Settings/PIN/ChangePin.tsx +++ b/src/screens/Settings/PIN/ChangePin.tsx @@ -30,16 +30,15 @@ const ChangePin = ({ const { brand, brand08 } = useColors(); const handleOnPress = (key: string): void => { + vibrate(); if (key === 'delete') { - if (pin.length !== 0) { - vibrate(); - setPin((p) => p.slice(0, -1)); - } + setPin((p) => { + return p.length === 0 ? '' : p.slice(0, -1); + }); } else { - if (pin.length !== 4) { - vibrate(); - setPin((p) => p + key); - } + setPin((p) => { + return p.length === 4 ? p : p + key; + }); } }; diff --git a/src/screens/Settings/PIN/ChangePin2.tsx b/src/screens/Settings/PIN/ChangePin2.tsx index 393948fc7..890115111 100644 --- a/src/screens/Settings/PIN/ChangePin2.tsx +++ b/src/screens/Settings/PIN/ChangePin2.tsx @@ -31,16 +31,15 @@ const ChangePin2 = ({ const { brand, brand08 } = useColors(); const handleOnPress = (key: string): void => { + vibrate(); if (key === 'delete') { - if (pin.length !== 0) { - vibrate(); - setPin((p) => p.slice(0, -1)); - } + setPin((p) => { + return p.length === 0 ? '' : p.slice(0, -1); + }); } else { - if (pin.length !== 4) { - vibrate(); - setPin((p) => p + key); - } + setPin((p) => { + return p.length === 4 ? p : p + key; + }); } }; diff --git a/src/screens/Settings/PIN/ChoosePIN.tsx b/src/screens/Settings/PIN/ChoosePIN.tsx index 7fadcefb1..29a7868e0 100644 --- a/src/screens/Settings/PIN/ChoosePIN.tsx +++ b/src/screens/Settings/PIN/ChoosePIN.tsx @@ -34,16 +34,15 @@ const ChoosePIN = ({ const { brand, brand08 } = useColors(); const handleOnPress = (key: string): void => { + vibrate(); if (key === 'delete') { - if (pin.length !== 0) { - vibrate(); - setPin((p) => p.slice(0, -1)); - } + setPin((p) => { + return p.length === 0 ? '' : p.slice(0, -1); + }); } else { - if (pin.length !== 4) { - vibrate(); - setPin((p) => p + key); - } + setPin((p) => { + return p.length === 4 ? p : p + key; + }); } }; diff --git a/src/screens/Wallets/Send/SendPinPad.tsx b/src/screens/Wallets/Send/SendPinPad.tsx index 509397dc6..4e10d30b1 100644 --- a/src/screens/Wallets/Send/SendPinPad.tsx +++ b/src/screens/Wallets/Send/SendPinPad.tsx @@ -18,16 +18,15 @@ const SendPinPad = ({ onSuccess }: { onSuccess: () => void }): ReactElement => { const { brand, brand08 } = useColors(); const handleOnPress = (key: string): void => { + vibrate(); if (key === 'delete') { - if (pin.length !== 0) { - vibrate(); - setPin((p) => p.slice(0, -1)); - } + setPin((p) => { + return p.length === 0 ? '' : p.slice(0, -1); + }); } else { - if (pin.length !== 4) { - vibrate(); - setPin((p) => p + key); - } + setPin((p) => { + return p.length === 4 ? p : p + key; + }); } };