{
"data": {
"cuongdcdev.near": {
"widget": {
"linkdrop_plus": {
"": "const accountId = context.accountId ?? props.accountId;\n\nif (!accountId) {\n return \"U need to login first or create new NEAR account here:https://shard.dog/go\";\n}\nlet dropInfo = Social.getr(`${accountId}/keypomConfig`);\n\nif (dropInfo === null) {\n console.log(\"dropinfo\", dropInfo);\n return \"Please wait...\";\n}\nState.init({\n amount: \"0.05\",\n drops: \"5\",\n img: dropInfo.img ?? null,\n desc: dropInfo.desc ?? \"\",\n publicKeys: [],\n privKeys: [],\n});\n\nif (Storage.privateGet(\"key_list\")) {\n let obj = Storage.privateGet(\"key_list\");\n console.log(\"get from storage\", obj);\n State.update({\n publicKeys: obj.publicKeys,\n privKeys: obj.privKeys,\n });\n}\n\nconst keypomContract = \"v2.keypom.near\";\nconst gatewayUrl = \"https://near.org/cuongdcdev.near/widget/linkdrop-viewer\";\n\nconst Yocto2Near = (amount) =>\n new Big(amount).div(new Big(10).pow(24)).toString();\n\nconst Near2Yocto = (amount) =>\n new Big(amount).times(new Big(10).pow(24)).toFixed().toString();\n\nconst createDrop = () => {\n let generatorUrl = \"https://keypom.sctuts.com/keypair/\";\n asyncFetch(generatorUrl + state.drops + \"/rootEntrophy\").then((res) => {\n let keyPairs = JSON.parse(res.body);\n console.log(\"keypairs:\", keyPairs);\n let pubKeys = [];\n let privKeys = [];\n keyPairs.forEach((e) => {\n pubKeys.push(e.pub);\n privKeys.push(e.priv);\n });\n\n let obj = {\n publicKeys: pubKeys,\n privKeys: privKeys,\n };\n State.update(obj);\n\n Storage.privateSet(\"key_list\", obj);\n\n console.log(\"public keys:\", state.publicKeys, \"priv keys:\", state.privKeys);\n\n Near.call([\n {\n contractName: keypomContract,\n methodName: \"create_drop\",\n gas: \"100000000000000\",\n\n args: {\n public_keys: state.publicKeys,\n deposit_per_use: Near2Yocto(state.amount ?? \"0.05\"),\n },\n deposit: Near2Yocto(state.publicKeys.length * state.amount + 0.05),\n },\n ]);\n });\n};\n\nconst onChangeValue = (t, v) => {\n State.update({\n [t]: v,\n });\n if (t == \"drops\" && v > 50) {\n State.update({\n drops: 50,\n });\n }\n console.log(t + \" : \", v);\n};\n\nconst getListLink = () => {\n let links = \"\";\n state.privKeys.map((e, i) => {\n let data = JSON.stringify({ u: accountId, k: e });\n //base64 encoded\n let link =\n gatewayUrl + \"?k=\" + Buffer.from(data, \"utf-8\").toString(\"base64\");\n links += link + \" \\n \";\n });\n\n return links;\n};\n\nconst saveDropInfo = () => {\n let obj = {\n img: state.img.cid,\n desc: state.desc,\n };\n console.log(obj);\n};\n\nreturn (\n <div className=\"mb-3 container row\">\n <div className=\"container\">\n <h2>Set Linkdrop Info</h2>\n <div className=\"config-drop\">\n Set Linkdrop Image\n <br />\n <IpfsImageUpload image={state.img} />\n <div className=\"mt-2\">\n {state.img && (\n <img\n style={{ maxWidth: 500 }}\n src={`https://ipfs.near.social/ipfs/${\n state.img.cid ?? state.img\n }`}\n alt=\"uploaded\"\n />\n )}\n </div>\n Linkdrop Description (markdown supported)\n <br />\n <textarea\n className=\"form-control\"\n rows=\"10\"\n onChange={(e) => onChangeValue(\"desc\", e.target.value)}\n value={state.desc}\n />\n <Markdown className=\"mt-3\" text={state.desc} />\n <CommitButton\n className=\"btn btn-info\"\n data={{\n keypomConfig: {\n img: state.img.cid ?? state.img,\n desc: state.desc,\n },\n }}\n >\n Save linkdrop info\n </CommitButton>\n </div>\n </div>\n\n <div className=\"container mt-5 border-top border-3\">\n <h2 className=\"mt-3\">Create new linkdrops</h2>\n <div className=\"input-field\">\n Linkdrop amount:\n <input\n type=\"number\"\n min=\"1\"\n max=\"50\"\n defaultValue=\"5\"\n value={state.drops}\n onChange={(e) => onChangeValue(\"drops\", e.target.value)}\n />\n NEAR per Drop:\n <input\n type=\"number\"\n min=\"0\"\n step=\"0.01\"\n defaultValue=\"0.05\"\n onChange={(e) => onChangeValue(\"amount\", e.target.value)}\n />\n <button\n className=\"btn btn-lg btn-primary mt-3\"\n onClick={(e) => createDrop()}\n >\n Create\n </button>\n </div>\n </div>\n\n <div className=\"result-field mt-5 border-top border-3 \">\n <h2 className=\"mt-3\">Results</h2>\n {state.publicKeys.length > 0 && (\n <>\n <button\n className=\"btn btn-sm btn-dark\"\n onClick={() => clipboard.writeText(JSON.stringify(getListLink()))}\n >\n Copy all {state.publicKeys.length} linkdrop to Clipboard\n </button>\n </>\n )}\n <br />\n <small>Make sure to save these links to use later!</small>\n\n <div className=\"link-list\">\n {state.privKeys.length > 0 &&\n state.privKeys.map((e, i) => {\n // let link =\n // \"https://testnet.mynearwallet.com/linkdrop/v2.keypom.testnet/\" +\n // e;\n let data = JSON.stringify({ u: accountId, k: e });\n\n //base64 encoded\n let link =\n gatewayUrl +\n \"?k=\" +\n Buffer.from(data, \"utf-8\").toString(\"base64\");\n\n return (\n <>\n <div class=\"input-group mb-3\">\n <a\n class=\"btn btn-outline-secondary\"\n target=\"_blank\"\n href={link}\n >\n {\" \"}\n Drop #{i + 1}\n </a>{\" \"}\n <br />\n <button\n class=\"btn btn-outline-secondary\"\n type=\"button\"\n onClick={(e) => clipboard.writeText(link)}\n >\n Copy\n </button>\n </div>\n </>\n );\n })}\n </div>\n </div>\n </div>\n);\n",
"metadata": {
"fork_of": "cuongdcdev.near/widget/linkdrop_plus@94971654"
}
}
}
}
}
}