-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Passed down details into project, using temporal sdk for reusable fuc…
…tions
- Loading branch information
1 parent
3f3aa46
commit a97646b
Showing
6 changed files
with
200 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* HELPER FUNCTION */ | ||
function isNearAddress(address) { | ||
if (typeof address !== "string") { | ||
return false; | ||
} | ||
|
||
// Allow both ".near" and ".testnet" endings | ||
if (!address.endsWith(".near") && !address.endsWith(".testnet")) { | ||
return false; | ||
} | ||
|
||
const parts = address.split("."); | ||
if (parts.length !== 2) { | ||
return false; | ||
} | ||
|
||
if (parts[0].length < 2 || parts[0].length > 32) { | ||
return false; | ||
} | ||
|
||
if (!/^[a-z0-9_-]+$/i.test(parts[0])) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
const validNearAddresses = (string) => { | ||
// removing extra characters and splitting the string into an array | ||
const arr = string.replace(/[\[\]\(\)@]/g, "").split(/[\s,]+/); | ||
|
||
// filtering out teammates that are not near addresses | ||
const hexRegex = /^[0-9A-F\-_]+$/i; | ||
const valid = arr.filter((teammate) => { | ||
if (hexRegex.test(teammate)) { | ||
return teammate; | ||
} | ||
return isNearAddress(teammate); | ||
}); | ||
|
||
console.log("valid from validNearAddresses", valid); | ||
|
||
return valid; | ||
}; | ||
|
||
return { validNearAddresses }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.