Skip to content

Commit 477f078

Browse files
committed
sync block height validation
1 parent cd0901d commit 477f078

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

packages/snap/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@chainsafe/webzjs-zcash-snap",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "Zcash Metmamask Snap that utilizes WebZjs.",
55
"repository": {
66
"type": "git",

packages/snap/snap.manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"version": "0.2.1",
2+
"version": "0.2.2",
33
"description": "WebZjs Snap for demo wallet",
44
"proposedName": "WebZjs Snap",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/ChainSafe/WebZjs.git"
88
},
99
"source": {
10-
"shasum": "qEgmDNiFc38+m/Ra1d5sOCSYmdAitT/Ghy6lVl21oDY=",
10+
"shasum": "YsNLaFFSeBvE+cukvWF2qkh2PhTrCmU+H9gaEpVUr74=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/snap/src/utils/setSyncBlockHeight.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ export function setSyncBlockHeight(
55
userInputCreationBlock: string | null,
66
latestBlock: number,
77
): number {
8+
//In case input was empty, default to latestBlock
89
if (userInputCreationBlock === null) return latestBlock;
910

11+
// Check if input is a valid number
12+
if (!/^\d+$/.test(userInputCreationBlock)) return latestBlock;
13+
1014
const customBirthdayBlock = Number(userInputCreationBlock);
1115

16+
// Check if custom block is higher than latest block
17+
if (customBirthdayBlock > latestBlock) return latestBlock;
18+
1219
const latestAcceptableSyncBlock = NU5_ACTIVATION;
1320

21+
//In case user entered older than acceptable block height
1422
return customBirthdayBlock > latestAcceptableSyncBlock
1523
? customBirthdayBlock
1624
: latestAcceptableSyncBlock;

0 commit comments

Comments
 (0)