Skip to content

Commit

Permalink
Merge pull request #1995 from oasisprotocol/lw/refactor
Browse files Browse the repository at this point in the history
Speedup CountdownButton in tests
  • Loading branch information
lukaw3d authored Jul 8, 2024
2 parents b7ecb22 + 1c0ab37 commit ab1c9db
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
1 change: 1 addition & 0 deletions .changelog/1995.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Speedup CountdownButton in tests
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
"@oasisprotocol/ledger": "1.0.0",
"@reduxjs/toolkit": "1.9.7",
"base64-arraybuffer": "1.0.2",
"bech32": "2.0.0",
"bignumber.js": "9.1.2",
"bip39": "3.1.0",
"body-scroll-lock": "4.0.0-beta.0",
Expand Down
17 changes: 10 additions & 7 deletions src/app/components/CountdownButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ export const CountdownButton = (props: Omit<ButtonExtendedProps, 'disabled'>) =>
const isDisabled = countdown > 0

useEffect(() => {
const timerId = setInterval(() => {
setCountdown(prevCountdown => {
const newCount = prevCountdown - 1
if (newCount <= 0) clearInterval(timerId)
return newCount
})
}, 1000)
const timerId = setInterval(
() => {
setCountdown(prevCountdown => {
const newCount = prevCountdown - 1
if (newCount <= 0) clearInterval(timerId)
return newCount
})
},
process.env.REACT_APP_E2E_TEST ? 200 : 1000,
)

return () => clearInterval(timerId)
}, [])
Expand Down
6 changes: 1 addition & 5 deletions src/app/lib/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { bech32 } from 'bech32'
import { quantity, staking, types } from '@oasisprotocol/client'
import { decode as base64decode, encode as base64encode } from 'base64-arraybuffer'
import BigNumber from 'bignumber.js'
Expand Down Expand Up @@ -27,11 +26,8 @@ export const uint2bigintString = (uint: Uint8Array): StringifiedBigInt => quanti
export const stringBigint2uint = (number: StringifiedBigInt) => quantity.fromBigInt(BigInt(number))

export const isValidAddress = (addr: string) => {
if (!addr.match(/^oasis1/)) {
return false
}
try {
bech32.decode(addr)
staking.addressFromBech32(addr)
return true
} catch (e) {
return false
Expand Down
22 changes: 19 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3962,7 +3962,7 @@ bcrypt-pbkdf@^1.0.0:
dependencies:
tweetnacl "^0.14.3"

bech32@2.0.0, bech32@^2.0.0:
bech32@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/bech32/-/bech32-2.0.0.tgz"
integrity sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg==
Expand Down Expand Up @@ -9554,7 +9554,16 @@ string-natural-compare@^3.0.1:
resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4"
integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw==

"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -9627,7 +9636,14 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down

0 comments on commit ab1c9db

Please sign in to comment.