diff --git a/jestconfig.json b/jestconfig.json index e1bb70c..371dac8 100644 --- a/jestconfig.json +++ b/jestconfig.json @@ -3,5 +3,6 @@ "^.+\\.(t|j)sx?$": "ts-jest" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", + "testEnvironment": "jsdom", "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"] } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index fc422eb..570799e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@cafeca/lunar", - "version": "0.3.6", + "version": "0.4.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -839,6 +839,12 @@ "@sinonjs/commons": "^1.7.0" } }, + "@tootallnate/once": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz", + "integrity": "sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==", + "dev": true + }, "@types/babel__core": { "version": "7.1.20", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.20.tgz", @@ -923,6 +929,17 @@ "pretty-format": "^29.0.0" } }, + "@types/jsdom": { + "version": "20.0.1", + "resolved": "https://registry.npmjs.org/@types/jsdom/-/jsdom-20.0.1.tgz", + "integrity": "sha512-d0r18sZPmMQr1eG35u12FZfhIXNrnsPU/g5wvRKCUf/tOGilKKwYMYGqh33BNR6ba+2gkHw1EUiHoN3mn7E5IQ==", + "dev": true, + "requires": { + "@types/node": "*", + "@types/tough-cookie": "*", + "parse5": "^7.0.0" + } + }, "@types/node": { "version": "18.11.18", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz", @@ -941,6 +958,12 @@ "integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==", "dev": true }, + "@types/tough-cookie": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.2.tgz", + "integrity": "sha512-Q5vtl1W5ue16D+nIaW8JWebSSraJVlK+EthKn7e7UcD4KWsaSJ8BqGPXNaPghgtcn/fhvrN17Tv8ksUsQpiplw==", + "dev": true + }, "@types/yargs": { "version": "17.0.19", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.19.tgz", @@ -956,16 +979,47 @@ "integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==", "dev": true }, + "abab": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz", + "integrity": "sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==", + "dev": true + }, "acorn": { "version": "8.8.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.1.tgz", "integrity": "sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==" }, + "acorn-globals": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/acorn-globals/-/acorn-globals-7.0.1.tgz", + "integrity": "sha512-umOSDSDrfHbTNPuNpC2NSnnA3LUrqpevPb4T9jRx4MagXNS0rs+gwiTcAvqCRmsD6utzsrzNt+ebm00SNWiC3Q==", + "dev": true, + "requires": { + "acorn": "^8.1.0", + "acorn-walk": "^8.0.2" + } + }, "acorn-jsx": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==" }, + "acorn-walk": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", + "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", + "dev": true + }, + "agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "dev": true, + "requires": { + "debug": "4" + } + }, "ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -1018,6 +1072,12 @@ "sprintf-js": "~1.0.2" } }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true + }, "babel-jest": { "version": "29.3.1", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.3.1.tgz", @@ -1238,6 +1298,15 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "requires": { + "delayed-stream": "~1.0.0" + } + }, "commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", @@ -1265,6 +1334,40 @@ "which": "^2.0.1" } }, + "cssom": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/cssom/-/cssom-0.5.0.tgz", + "integrity": "sha512-iKuQcq+NdHqlAcwUY0o/HL69XQrUaQdMjmStJ8JFmUaiiQErlhrmuigkg/CU4E2J0IyUKUrMAgl36TvN67MqTw==", + "dev": true + }, + "cssstyle": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-2.3.0.tgz", + "integrity": "sha512-AZL67abkUzIuvcHqk7c09cezpGNcxUxU4Ioi/05xHk4DQeTkWmGYftIE6ctU6AEt+Gn4n1lDStOtj7FKycP71A==", + "dev": true, + "requires": { + "cssom": "~0.3.6" + }, + "dependencies": { + "cssom": { + "version": "0.3.8", + "resolved": "https://registry.npmjs.org/cssom/-/cssom-0.3.8.tgz", + "integrity": "sha512-b0tGHbfegbhPJpxpiBPU2sCkigAqtM9O121le6bbOlgyV+NyGyCmVfJ6QW9eRjz8CpNfWEOYBIMIGRYkLwsIYg==", + "dev": true + } + } + }, + "data-urls": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-3.0.2.tgz", + "integrity": "sha512-Jy/tj3ldjZJo63sVAvg6LHt2mHvl4V6AgRAmNDtLdm7faqtsx+aJG42rsyCo9JCoRVKwPFzKlIPx3DIibwSIaQ==", + "dev": true, + "requires": { + "abab": "^2.0.6", + "whatwg-mimetype": "^3.0.0", + "whatwg-url": "^11.0.0" + } + }, "debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -1273,6 +1376,12 @@ "ms": "2.1.2" } }, + "decimal.js": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.4.3.tgz", + "integrity": "sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==", + "dev": true + }, "dedent": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/dedent/-/dedent-0.7.0.tgz", @@ -1290,6 +1399,12 @@ "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==", "dev": true }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true + }, "detect-newline": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz", @@ -1316,6 +1431,15 @@ "esutils": "^2.0.2" } }, + "domexception": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/domexception/-/domexception-4.0.0.tgz", + "integrity": "sha512-A2is4PLG+eeSfoTMA95/s4pvAoSo2mKtiM5jlHkAVewmiO8ISFTFKZjH7UAM1Atli/OT/7JHOrJRJiMKUZKYBw==", + "dev": true, + "requires": { + "webidl-conversions": "^7.0.0" + } + }, "electron-to-chromium": { "version": "1.4.284", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.284.tgz", @@ -1334,6 +1458,12 @@ "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", "dev": true }, + "entities": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.4.0.tgz", + "integrity": "sha512-oYp7156SP8LkeGD0GF85ad1X9Ai79WtRsZ2gxJqtBuzH+98YUV6jkHEKlZkMbcrjJjIVJNIDP/3WL9wQkoPbWA==", + "dev": true + }, "error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -1355,6 +1485,60 @@ "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", "dev": true }, + "escodegen": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-2.0.0.tgz", + "integrity": "sha512-mmHKys/C8BFUGI+MAWNcSYoORYLMdPzjrknd2Vc+bUsjN5bXcr8EhrNB+UTqfL1y3I9c4fw2ihgtMPQLBRiQxw==", + "dev": true, + "requires": { + "esprima": "^4.0.1", + "estraverse": "^5.2.0", + "esutils": "^2.0.2", + "optionator": "^0.8.1", + "source-map": "~0.6.1" + }, + "dependencies": { + "levn": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", + "integrity": "sha512-0OO4y2iOHix2W6ujICbKIaEQXvFQHue65vUG3pb5EUomzPI90z9hsA1VsO/dbIIpC53J8gxM9Q4Oho0jrCM/yA==", + "dev": true, + "requires": { + "prelude-ls": "~1.1.2", + "type-check": "~0.3.2" + } + }, + "optionator": { + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz", + "integrity": "sha512-+IW9pACdk3XWmmTXG8m3upGUJst5XRGzxMRjXzAuJ1XnIFNvfhjjIuYkDvysnPQ7qzqVzLt78BCruntqRhWQbA==", + "dev": true, + "requires": { + "deep-is": "~0.1.3", + "fast-levenshtein": "~2.0.6", + "levn": "~0.3.0", + "prelude-ls": "~1.1.2", + "type-check": "~0.3.2", + "word-wrap": "~1.2.3" + } + }, + "prelude-ls": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", + "integrity": "sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==", + "dev": true + }, + "type-check": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", + "integrity": "sha512-ZCmOJdvOWDBYJlzAoFkC+Q0+bUyEOS1ltgp1MGU03fqHG+dbi9tBFU2Rd9QKiDZFAYrhPh2JUf7rZRIuHRKtOg==", + "dev": true, + "requires": { + "prelude-ls": "~1.1.2" + } + } + } + }, "eslint": { "version": "8.32.0", "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.32.0.tgz", @@ -1647,6 +1831,17 @@ "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.7.tgz", "integrity": "sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==" }, + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -1741,18 +1936,57 @@ "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" }, + "html-encoding-sniffer": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-3.0.0.tgz", + "integrity": "sha512-oWv4T4yJ52iKrufjnyZPkrN0CH3QnrUqdB6In1g5Fe1mia8GmF36gnfNySxoZtxD5+NmYw1EElVXiBk93UeskA==", + "dev": true, + "requires": { + "whatwg-encoding": "^2.0.0" + } + }, "html-escaper": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", "dev": true }, + "http-proxy-agent": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz", + "integrity": "sha512-n2hY8YdoRE1i7r6M0w9DIw5GgZN0G25P8zLCRQ8rjXtTU3vsNFBI/vWK/UIeE6g5MUUz6avwAPXmL6Fy9D/90w==", + "dev": true, + "requires": { + "@tootallnate/once": "2", + "agent-base": "6", + "debug": "4" + } + }, + "https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "dev": true, + "requires": { + "agent-base": "6", + "debug": "4" + } + }, "human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", "dev": true }, + "iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dev": true, + "requires": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + } + }, "ignore": { "version": "5.2.4", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz", @@ -1854,6 +2088,12 @@ "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", "integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==" }, + "is-potential-custom-element-name": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz", + "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==", + "dev": true + }, "is-stream": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", @@ -2073,6 +2313,22 @@ "pretty-format": "^29.3.1" } }, + "jest-environment-jsdom": { + "version": "29.3.1", + "resolved": "https://registry.npmjs.org/jest-environment-jsdom/-/jest-environment-jsdom-29.3.1.tgz", + "integrity": "sha512-G46nKgiez2Gy4zvYNhayfMEAFlVHhWfncqvqS6yCd0i+a4NsSUD2WtrKSaYQrYiLQaupHXxCRi8xxVL2M9PbhA==", + "dev": true, + "requires": { + "@jest/environment": "^29.3.1", + "@jest/fake-timers": "^29.3.1", + "@jest/types": "^29.3.1", + "@types/jsdom": "^20.0.0", + "@types/node": "*", + "jest-mock": "^29.3.1", + "jest-util": "^29.3.1", + "jsdom": "^20.0.0" + } + }, "jest-environment-node": { "version": "29.3.1", "resolved": "https://registry.npmjs.org/jest-environment-node/-/jest-environment-node-29.3.1.tgz", @@ -2426,6 +2682,40 @@ "esprima": "^4.0.0" } }, + "jsdom": { + "version": "20.0.3", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-20.0.3.tgz", + "integrity": "sha512-SYhBvTh89tTfCD/CRdSOm13mOBa42iTaTyfyEWBdKcGdPxPtLFBXuHR8XHb33YNYaP+lLbmSvBTsnoesCNJEsQ==", + "dev": true, + "requires": { + "abab": "^2.0.6", + "acorn": "^8.8.1", + "acorn-globals": "^7.0.0", + "cssom": "^0.5.0", + "cssstyle": "^2.3.0", + "data-urls": "^3.0.2", + "decimal.js": "^10.4.2", + "domexception": "^4.0.0", + "escodegen": "^2.0.0", + "form-data": "^4.0.0", + "html-encoding-sniffer": "^3.0.0", + "http-proxy-agent": "^5.0.0", + "https-proxy-agent": "^5.0.1", + "is-potential-custom-element-name": "^1.0.1", + "nwsapi": "^2.2.2", + "parse5": "^7.1.1", + "saxes": "^6.0.0", + "symbol-tree": "^3.2.4", + "tough-cookie": "^4.1.2", + "w3c-xmlserializer": "^4.0.0", + "webidl-conversions": "^7.0.0", + "whatwg-encoding": "^2.0.0", + "whatwg-mimetype": "^3.0.0", + "whatwg-url": "^11.0.0", + "ws": "^8.11.0", + "xml-name-validator": "^4.0.0" + } + }, "jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", @@ -2550,6 +2840,21 @@ "picomatch": "^2.3.1" } }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "dev": true + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dev": true, + "requires": { + "mime-db": "1.52.0" + } + }, "mimic-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", @@ -2616,6 +2921,12 @@ "path-key": "^3.0.0" } }, + "nwsapi": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.2.tgz", + "integrity": "sha512-90yv+6538zuvUMnN+zCr8LuV6bPFdq50304114vJYJ8RDyK8D5O9Phpbd6SZWgI7PwzmmfN1upeOJlvybDSgCw==", + "dev": true + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -2690,6 +3001,15 @@ "lines-and-columns": "^1.1.6" } }, + "parse5": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.1.2.tgz", + "integrity": "sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==", + "dev": true, + "requires": { + "entities": "^4.4.0" + } + }, "path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -2777,11 +3097,23 @@ "sisteransi": "^1.0.5" } }, + "psl": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", + "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==", + "dev": true + }, "punycode": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.2.0.tgz", "integrity": "sha512-LN6QV1IJ9ZhxWTNdktaPClrNfp8xdSAYS0Zk2ddX7XsXZAxckMHPCBcHRo0cTcEIgYPRiGEkmji3Idkh2yFtYw==" }, + "querystringify": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", + "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==", + "dev": true + }, "queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -2804,6 +3136,12 @@ "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", "dev": true }, + "requires-port": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", + "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==", + "dev": true + }, "resolve": { "version": "1.22.1", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz", @@ -2857,6 +3195,21 @@ "queue-microtask": "^1.2.2" } }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "dev": true + }, + "saxes": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz", + "integrity": "sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==", + "dev": true, + "requires": { + "xmlchars": "^2.2.0" + } + }, "semver": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", @@ -2993,6 +3346,12 @@ "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", "dev": true }, + "symbol-tree": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", + "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", + "dev": true + }, "test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", @@ -3030,6 +3389,27 @@ "is-number": "^7.0.0" } }, + "tough-cookie": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.2.tgz", + "integrity": "sha512-G9fqXWoYFZgTc2z8Q5zaHy/vJMjm+WV0AkAeHxVCQiEB1b+dGvWzFW6QV07cY5jQ5gRkeid2qIkzkxUnmoQZUQ==", + "dev": true, + "requires": { + "psl": "^1.1.33", + "punycode": "^2.1.1", + "universalify": "^0.2.0", + "url-parse": "^1.5.3" + } + }, + "tr46": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz", + "integrity": "sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==", + "dev": true, + "requires": { + "punycode": "^2.1.1" + } + }, "ts-jest": { "version": "29.0.3", "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.0.3.tgz", @@ -3197,6 +3577,12 @@ "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==" }, + "universalify": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz", + "integrity": "sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==", + "dev": true + }, "update-browserslist-db": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.10.tgz", @@ -3215,6 +3601,16 @@ "punycode": "^2.1.0" } }, + "url-parse": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", + "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", + "dev": true, + "requires": { + "querystringify": "^2.1.1", + "requires-port": "^1.0.0" + } + }, "v8-to-istanbul": { "version": "9.0.1", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.0.1.tgz", @@ -3234,6 +3630,15 @@ } } }, + "w3c-xmlserializer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-4.0.0.tgz", + "integrity": "sha512-d+BFHzbiCx6zGfz0HyQ6Rg69w9k19nviJspaj4yNscGjrHu94sVP+aRm75yEbCh+r2/yR+7q6hux9LVtbuTGBw==", + "dev": true, + "requires": { + "xml-name-validator": "^4.0.0" + } + }, "walker": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/walker/-/walker-1.0.8.tgz", @@ -3243,6 +3648,37 @@ "makeerror": "1.0.12" } }, + "webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "dev": true + }, + "whatwg-encoding": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-2.0.0.tgz", + "integrity": "sha512-p41ogyeMUrw3jWclHWTQg1k05DSVXPLcVxRTYsXUk+ZooOCZLcoYgPZ/HL/D/N+uQPOtcp1me1WhBEaX02mhWg==", + "dev": true, + "requires": { + "iconv-lite": "0.6.3" + } + }, + "whatwg-mimetype": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-3.0.0.tgz", + "integrity": "sha512-nt+N2dzIutVRxARx1nghPKGv1xHikU7HKdfafKkLNLindmPU/ch3U31NOCGGA/dmPcmb1VlofO0vnKAcsm0o/Q==", + "dev": true + }, + "whatwg-url": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-11.0.0.tgz", + "integrity": "sha512-RKT8HExMpoYx4igMiVMY83lN6UeITKJlBQ+vR/8ZJ8OCdSiN3RwCq+9gH0+Xzj0+5IrM6i4j/6LuvzbZIQgEcQ==", + "dev": true, + "requires": { + "tr46": "^3.0.0", + "webidl-conversions": "^7.0.0" + } + }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -3282,6 +3718,24 @@ "signal-exit": "^3.0.7" } }, + "ws": { + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.12.0.tgz", + "integrity": "sha512-kU62emKIdKVeEIOIKVegvqpXMSTAMLJozpHZaJNDYqBjzlSYXQGviYwN1osDLJ9av68qHd4a2oSjd7yD4pacig==", + "dev": true + }, + "xml-name-validator": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-4.0.0.tgz", + "integrity": "sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw==", + "dev": true + }, + "xmlchars": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", + "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==", + "dev": true + }, "y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/package.json b/package.json index 40bb7b9..828fbbf 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "devDependencies": { "@types/jest": "^29.2.5", "jest": "^29.3.1", + "jest-environment-jsdom": "^29.3.1", "prettier": "^2.8.2", "ts-jest": "^29.0.3", "tslint": "^6.1.3", diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts new file mode 100644 index 0000000..192d414 --- /dev/null +++ b/src/__tests__/index.test.ts @@ -0,0 +1,8 @@ +import Lunar from '../index'; + +describe("Check Blockchains", () => { + test("BOLT - chain id is 8017", () => { + const { chainName } = Lunar.findBlockchain(8017); + expect(chainName).toBe("BOLT"); + }); +}) \ No newline at end of file diff --git a/src/connectors/connector.ts b/src/connectors/connector.ts index ae5ba4b..07a3b7e 100644 --- a/src/connectors/connector.ts +++ b/src/connectors/connector.ts @@ -9,7 +9,6 @@ class Connector { _type: string = Wallets.TideWallet; _assets: string[] = []; - constructor() {} get isConnected() { return this._isConnected; } @@ -26,35 +25,54 @@ class Connector { return this._blockchain.chainId; } - async init() {} - on(event:Event, callback:Function) {} + constructor() { + return this; + } + + async init() { + return true; + } + + on(event:Event, callback:() => void) { + return; + } + async connect({ blockchain }: { blockchain?: Blockchain } = {}): Promise { return true; } + async switchBlockchain({ blockchain }: { blockchain: Blockchain }): Promise { return true; } + async disconnect(): Promise { return true; } + async send({ to, amount, data }: { to: string, amount: number, data:string }): Promise { return "0x"; } + async getAsset({ contract }: { contract?: string }): Promise { return { name: '', symbol: '', decimals: 18, totalSupply: '0' }; } + async getAllowance({ contract, owner, spender }: { contract: string, owner: string, spender: string }): Promise { return '0'; } + async getContractBalance({ contract, address, state }: { contract: string, address: string, state?: string }): Promise { return "0x"; } + async getBalance({ contract, address, state }: { contract?: string, address?: string, state?: string } = {}): Promise { return "0x"; } + async getData({ contract, data, func, params, state }: { contract: string, data?: string, func?: string, params?: string[], state?: string }): Promise { return "0x"; } + async interfaceOf({ contract, abi }: { contract: string, abi: any }): Promise { return; } diff --git a/src/connectors/connector_factory.ts b/src/connectors/connector_factory.ts index d170792..6c64b22 100644 --- a/src/connectors/connector_factory.ts +++ b/src/connectors/connector_factory.ts @@ -1,8 +1,8 @@ -import Wallets from '../constants/wallets.js'; -import TideWallet from './tidewallet.js'; -import ImToken from './imtoken.js'; -import Metamask from './metamask.js'; -import Connector from './connector.js'; +import Wallets from '../constants/wallets'; +import TideWallet from './tidewallet'; +import ImToken from './imtoken'; +import Metamask from './metamask'; +import Connector from './connector'; class ConnectorFactory { static get types() { diff --git a/src/connectors/imtoken.ts b/src/connectors/imtoken.ts index 1a83a3a..62349c7 100644 --- a/src/connectors/imtoken.ts +++ b/src/connectors/imtoken.ts @@ -1,8 +1,5 @@ -import Wallets from '../constants/wallets.js'; -import SmartContract from '../libs/smartcontract.js'; -import Metamask from './metamask.js' - -declare let ethereum: any; +import Wallets from '../constants/wallets'; +import Metamask from './metamask' class ImToken extends Metamask { _type = Wallets.imToken; diff --git a/src/connectors/metamask.ts b/src/connectors/metamask.ts index 25f1746..d0da7ee 100644 --- a/src/connectors/metamask.ts +++ b/src/connectors/metamask.ts @@ -1,7 +1,7 @@ import BigNumber from 'bignumber.js'; -import Wallets from '../constants/wallets.js'; -import Connector from './connector.js'; -import SmartContract from '../libs/smartcontract.js'; +import Wallets from '../constants/wallets'; +import Connector from './connector'; +import SmartContract from '../libs/smartcontract'; import Blockchains, { Blockchain } from '../constants/blockchains'; declare let ethereum: any; @@ -16,7 +16,7 @@ class Metamask extends Connector { this._blockchain = Blockchains.findByChainId(chainId); } catch(e) { - console.trace(e); + throw e; } } @@ -59,7 +59,7 @@ class Metamask extends Connector { }; return ethereum.request(requestData); } else { - let _data = func ? + const _data = func ? SmartContract.toContractData({ func, params }) : ''; const result = await this.getData({ contract, data: _data }); @@ -68,12 +68,12 @@ class Metamask extends Connector { } async getContractBalance({ contract, address, state = "latest" } : { contract: string, address: string, state?: string }): Promise { - let address_ = address; + let tmpAddress = address; if(!SmartContract.isEthereumAddress(address)) { - address_ = this.address; + tmpAddress = this.address; } return Promise.all([ - this.getData({ contract, func: 'balanceOf(address)', params: [address_], state }), + this.getData({ contract, func: 'balanceOf(address)', params: [tmpAddress], state }), this.getDecimals({ contract }) ]) .then(([ _balance, _decimals ]) => { @@ -82,18 +82,18 @@ class Metamask extends Connector { }) } - async getBalance({ contract, address, state = "latest" } = { contract: '', address: '' }) { - const address_ = SmartContract.isEthereumAddress(address) ? + async getBalance({ contract = '', address = '', state = "latest" }) { + const tmpAddress = SmartContract.isEthereumAddress(address) ? address : this.address; - if(typeof(contract) == 'string') { - return this.getContractBalance({ contract, address: address_ || '' }); + if(SmartContract.isEthereumAddress(contract)) { + return this.getContractBalance({ contract, address: tmpAddress || '' }); } const requestData = { method: "eth_getBalance", - params: [address_, state] + params: [tmpAddress, state] } return ethereum.request(requestData).then((rs: BigNumber.Value) => { const balance = (new BigNumber(rs).dividedBy(new BigNumber(10).pow(18))).toString(); @@ -114,7 +114,7 @@ class Metamask extends Connector { } return this.getData({ contract, func: 'decimals()' }).then((rs) => { - const result = parseInt(rs); + const result = parseInt(rs, 10); return Promise.resolve(result); }) } @@ -153,7 +153,6 @@ class Metamask extends Connector { }) } async getTotalSupply({ contract } : { contract?: string } = {}) { - let totalSupply; if(!contract) { return Promise.resolve('0'); } @@ -167,7 +166,8 @@ class Metamask extends Connector { return Promise.resolve(totalSupply); }) } - async getAsset({ contract, decimals }: { contract?: string, decimals?: number } = {}) { + + async getAsset({ contract }: { contract?: string } = {}) { return Promise.all([ this.getName({ contract }), this.getSymbol({ contract }), diff --git a/src/connectors/tidewallet.ts b/src/connectors/tidewallet.ts index c50fd64..2528f78 100644 --- a/src/connectors/tidewallet.ts +++ b/src/connectors/tidewallet.ts @@ -1,7 +1,7 @@ -import Wallets from '../constants/wallets.js'; -import Connector from './connector.js' +import Wallets from '../constants/wallets'; +import Metamask from './metamask' -class TideWallet extends Connector { +class TideWallet extends Metamask { _type = Wallets.TideWallet; } diff --git a/src/constants/blockchains.ts b/src/constants/blockchains.ts index 7c2fef3..9b41236 100644 --- a/src/constants/blockchains.ts +++ b/src/constants/blockchains.ts @@ -162,22 +162,19 @@ export const Blockchains = class { static get keys() { return Object.keys(this); } - static list(isTestnet: boolean | undefined):Blockchain[] { + static list(isTestnet?: boolean):Blockchain[] { const result = Object.values(Blockchains) .filter((v) => { - const rs = isTestnet == undefined || (isTestnet == v.isTestnet); + const rs = (isTestnet === v.isTestnet) || isTestnet === undefined; return rs; }) return result; } static findByChainId(chainId: number = 8017) { - let searchKey = toHex(chainId); - if(searchKey.indexOf('0x') != 0) searchKey = '0x'.concat(searchKey); - return Object.values(Blockchains) .find((v) => { - return parseInt(v.chainId) == parseInt(searchKey); + return v.chainId === chainId; }) } } diff --git a/src/index.ts b/src/index.ts index 533900b..842397f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -55,7 +55,7 @@ class Lunar { undefined; } - on(event: string, callback: Function) { + on(event: string, callback: () => void) { return } @@ -63,7 +63,7 @@ class Lunar { return this._connectors .filter((v) => !!v) .find((v) => { - return v.type == walletType; + return v.type === walletType; }) } @@ -144,7 +144,7 @@ class Lunar { if(window) { window.Lunar = Lunar; - /** Test Case + /* Test Case window.lunar = new Lunar(); window.lunar.connect({ blockchain: Lunar.Blockchains.Ropsten }); window.lunar.getData({ contract: '0x333cf7C5F2A544cc998d4801e5190BCb9E04003e', func: 'factory()', params: [] }); diff --git a/src/interfaces/iconnector.ts b/src/interfaces/iconnector.ts index d4c4f2d..17b9307 100644 --- a/src/interfaces/iconnector.ts +++ b/src/interfaces/iconnector.ts @@ -15,7 +15,7 @@ interface IConnector { get chainId(): number; init(): Promise; - on(event:Event, callback:Function): void; + on(event:Event, callback: () => void): void; connect({ blockchain }: { blockchain?: IBlockchain }): Promise; switchBlockchain({ blockchain }: { blockchain: IBlockchain }): Promise; disconnect(): Promise; diff --git a/src/libs/common.ts b/src/libs/common.ts index 31267d7..95e8004 100644 --- a/src/libs/common.ts +++ b/src/libs/common.ts @@ -43,8 +43,8 @@ export const stringToHex = (data: string) => { seed = data; for(let i = 0; i < seed.length; i++) { - let code = seed.charCodeAt(i) + 1; - let tmpSqr = Math.ceil(Math.log(code) / Math.log(256)); + const code = seed.charCodeAt(i) + 1; + const tmpSqr = Math.ceil(Math.log(code) / Math.log(256)); sqr = tmpSqr > sqr ? tmpSqr : sqr; arr[i] = seed.charCodeAt(i).toString(16).padStart(tmpSqr * 2, '0'); } @@ -58,9 +58,9 @@ export const isHex = (data: string) => { return /^0x[a-fA-F0-9]*$/.test(data); } -export const toHex = (data: any) => { +export const toHex = (data: any): string => { let result; - if(data == undefined) { + if(data === undefined) { result = ''; } else if(isHex(data)) { @@ -69,13 +69,14 @@ export const toHex = (data: any) => { else if(Number.isInteger(data)) { const map = "0123456789abcdef"; let hex = data === 0 ? "0" : ""; - while (data !== 0) { - hex = map[data & 15] + hex; - data = data >>> 4; + let tmpInt = data; + while (tmpInt !== 0) { + hex = map[tmpInt % 16] + hex; + tmpInt = Math.floor(tmpInt / 16); } result = hex; } - else if(typeof data == 'string') { + else if(typeof data === 'string') { result = stringToHex(data); } else { result = ''; diff --git a/src/libs/environment.ts b/src/libs/environment.ts index 25c07d9..63204ee 100644 --- a/src/libs/environment.ts +++ b/src/libs/environment.ts @@ -8,7 +8,9 @@ class Environment { try { result = navigator.userAgent; } - catch(e) {} + catch(e) { + // Ignore error + } return result; } static getWallets() { @@ -19,7 +21,9 @@ class Environment { result.push(Wallets.Metamask); } } - catch(e) {} + catch(e) { + // Ignore error + } // imToken try { @@ -27,7 +31,9 @@ class Environment { result.push(Wallets.imToken); } } - catch(e) {} + catch(e) { + // Ignore error + } // TideWallet try { @@ -35,13 +41,19 @@ class Environment { result.push(Wallets.TideWallet); } } - catch(e) {} + catch(e) { + // Ignore error + } // Trust try { - + if(window.ethereum.isTrust) { + result.push(Wallets.Trust); + } + } + catch(e) { + // Ignore error } - catch(e) {} return result; } diff --git a/src/libs/smartcontract.ts b/src/libs/smartcontract.ts index 5c34c13..d5a94ff 100644 --- a/src/libs/smartcontract.ts +++ b/src/libs/smartcontract.ts @@ -5,9 +5,8 @@ import BigNumber from 'bignumber.js'; class SmartContract { static leftPad32(str: any) { let result = ''; - let arr; - let length = 32 * 2; - if(typeof str == 'string') { + const length = 32 * 2; + if(typeof str === 'string') { result = str.padStart(length, '0'); } else { try { @@ -22,20 +21,22 @@ class SmartContract { static parseString(data: string): string { let seed = data; - if(seed.indexOf('0x') == 0) { + if(seed.indexOf('0x') === 0) { seed = seed.substr(2); } if(seed.length > 64) { - let chunks = chunkSubstr(seed, 64).slice(2); + const chunks = chunkSubstr(seed, 64).slice(2); return chunks.map((v) => this.parseString(v)).join(''); } let result = ''; try { - result = decodeURIComponent('%' + seed.match(/.{1,2}/g)?.filter((v) => v != '00').join('%')); + result = decodeURIComponent('%' + seed.match(/.{1,2}/g)?.filter((v) => v !== '00').join('%')); + } + catch(e) { + // Ignore error } - catch(e) {} return result; } @@ -43,7 +44,7 @@ class SmartContract { let seed = data; let chunks; let result; - if(seed.indexOf('0x') == 0) { + if(seed.indexOf('0x') === 0) { seed = seed.substr(2); } @@ -86,7 +87,7 @@ class SmartContract { } static isEthereumAddress(addr: any) { - if(typeof addr != 'string') { return false; } + if(typeof addr !== 'string') { return false; } return /^0x[a-fA-F0-9]{40}$/.test(addr); } }