-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from NEARBuilders/temp-jiku
Slow submit inputs fix
- Loading branch information
Showing
5 changed files
with
134 additions
and
65 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
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 extractValidNearAddresses = (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 { extractValidNearAddresses }; |
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,38 @@ | ||
const flattenObject = (obj, parentKey) => { | ||
parentKey = parentKey ?? ""; | ||
let paths = []; | ||
|
||
Object.keys(obj).forEach((key) => { | ||
const currentPath = parentKey ? `${parentKey}/${key}` : key; | ||
|
||
if (typeof obj[key] === "object") { | ||
paths = paths.concat(flattenObject(obj[key], currentPath)); | ||
} else { | ||
paths.push(currentPath); | ||
} | ||
}); | ||
|
||
console.log("from the helper function!"); | ||
|
||
return paths; | ||
}; | ||
|
||
const fetchProjects = (app, type) => { | ||
const keys = Social.keys(`*/${app}/${type}/*`, "final", { | ||
return_type: "BlockHeight", | ||
}); | ||
|
||
if (!keys) { | ||
return "Loading..."; | ||
} | ||
|
||
let flattenedKeys = flattenObject(keys); | ||
flattenedKeys = flattenedKeys.filter( | ||
(s) => !s.includes("/project/hackathon") | ||
); | ||
|
||
const projects = Social.get(flattenedKeys, "final"); | ||
return projects; | ||
}; | ||
|
||
return { fetchProjects }; |
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 |
---|---|---|
@@ -1,38 +1,16 @@ | ||
const flattenObject = (obj, parentKey) => { | ||
parentKey = parentKey ?? ""; | ||
let paths = []; | ||
|
||
Object.keys(obj).forEach((key) => { | ||
const currentPath = parentKey ? `${parentKey}/${key}` : key; | ||
|
||
if (typeof obj[key] === "object") { | ||
paths = paths.concat(flattenObject(obj[key], currentPath)); | ||
} else { | ||
paths.push(currentPath); | ||
} | ||
}); | ||
|
||
console.log("from the helper function!"); | ||
|
||
return paths; | ||
const { extractValidNearAddresses } = VM.require( | ||
"buildbox.near/widget/utils.extractValidNearAddresses" | ||
) || { | ||
validNearAddresses: () => {}, | ||
}; | ||
|
||
const fetchProjects = (app, type) => { | ||
const keys = Social.keys(`*/${app}/${type}/*`, "final", { | ||
return_type: "BlockHeight", | ||
}); | ||
|
||
if (!keys) { | ||
return "Loading..."; | ||
} | ||
|
||
let flattenedKeys = flattenObject(keys); | ||
flattenedKeys = flattenedKeys.filter( | ||
(s) => !s.includes("/project/hackathon") | ||
); | ||
|
||
const projects = Social.get(flattenedKeys, "final"); | ||
return projects; | ||
const { fetchProjects } = VM.require( | ||
"buildbox.near/widget/utils.fetchProjects" | ||
) || { | ||
fetchProjects: () => {}, | ||
}; | ||
|
||
return { fetchProjects }; | ||
return { | ||
fetchProjects, | ||
extractValidNearAddresses, | ||
}; |