From 9752b574ce1219368706576c9f92e27c1a92f465 Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Wed, 13 Nov 2024 22:51:00 +0100 Subject: [PATCH] Revert "Revert "Revert "Feat/transak bump (#639)" (#643)" (#645)" This reverts commit 24aec7c87778d57de2c7ba9df8af56f3359f36d3. --- package-lock.json | 399 +++++++++++++++++--- package.json | 2 +- src/lib/marketplaceApi.ts | 14 - src/modules/gateway/sagas.spec.ts | 85 ++--- src/modules/gateway/sagas.ts | 33 +- src/modules/gateway/transak/Transak.spec.ts | 70 +--- src/modules/gateway/transak/Transak.ts | 91 ++--- src/modules/gateway/transak/types.ts | 22 +- src/modules/gateway/types.ts | 1 - src/types/transak.d.ts | 1 + 10 files changed, 420 insertions(+), 298 deletions(-) create mode 100644 src/types/transak.d.ts diff --git a/package-lock.json b/package-lock.json index a60a0bc5..02106585 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "@dcl/schemas": "^14.0.0", "@dcl/single-sign-on-client": "^0.1.0", "@dcl/ui-env": "^1.5.0", - "@transak/transak-sdk": "^3.1.3", + "@transak/transak-sdk": "^1.0.31", "@types/flat": "0.0.28", "@types/segment-analytics": "^0.0.38", "@well-known-components/fetch-component": "^2.0.1", @@ -325,6 +325,7 @@ "version": "2.2.1", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.1.tgz", "integrity": "sha512-lFMjJTrFL3j7L9yBxwYfCq2k6qqwHyzuUl/XBnif78PWTJYyL/dfowQHWE3sp6U6ZzqWiiIZnpTMO96zhkjwtg==", + "dev": true, "dependencies": { "@jridgewell/gen-mapping": "^0.3.0", "@jridgewell/trace-mapping": "^0.3.9" @@ -564,6 +565,7 @@ "version": "7.23.9", "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.9.tgz", "integrity": "sha512-5q0175NOjddqpvvzU+kDiSOAk4PfdO6FvwCWoQ6RO7rTzEe8vlo+4HVfcnAREhD4npMs0e9uZypjTwzZPCf/cw==", + "dev": true, "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.23.5", @@ -593,6 +595,7 @@ "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "dev": true, "bin": { "semver": "bin/semver.js" } @@ -719,6 +722,7 @@ "version": "7.23.3", "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.23.3.tgz", "integrity": "sha512-7bBs4ED9OmswdfDzpz4MpWgSrV7FXlc3zIagvLFjS5H+Mk7Snr21vQ6QwrsoCGMfNC4e4LQPdoULEt4ykz0SRQ==", + "dev": true, "dependencies": { "@babel/helper-environment-visitor": "^7.22.20", "@babel/helper-module-imports": "^7.22.15", @@ -745,6 +749,7 @@ "version": "7.22.5", "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.22.5.tgz", "integrity": "sha512-n0H99E/K+Bika3++WNL17POvo4rKWZ7lZEp1Q+fStVbUi8nxPQEBOlTmCOxW/0JsS56SKKQ+ojAe2pHKJHN35w==", + "dev": true, "dependencies": { "@babel/types": "^7.22.5" }, @@ -791,6 +796,7 @@ "version": "7.23.9", "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.23.9.tgz", "integrity": "sha512-87ICKgU5t5SzOT7sBMfCOZQ2rHjRU+Pcb9BoILMYz600W6DkVRLFBPwQ18gwUVvggqXivaUakpnxWQGbpywbBQ==", + "dev": true, "dependencies": { "@babel/template": "^7.23.9", "@babel/traverse": "^7.23.9", @@ -4664,16 +4670,13 @@ } }, "node_modules/@transak/transak-sdk": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/@transak/transak-sdk/-/transak-sdk-3.1.3.tgz", - "integrity": "sha512-Ea4/OY5Rz/vZLWt2mgwoJDaeUScNbK1AI/yDfhJrNHG0cmalX3SSQOMswY1uX/GAL+6VNSLAybJg9FRx5I1N/A==", + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/@transak/transak-sdk/-/transak-sdk-1.2.3.tgz", + "integrity": "sha512-nmpMB6zUwVO/2VlTQIrlDawUbMVTGoio4IiwHxCbNRiFGzxxXwymXNqlspxCszWtznUHFHWtEMomRAdW05MAkw==", "dependencies": { - "events": "^3.3.0", - "pako": "^2.1.0", - "query-string": "^8.2.0" - }, - "engines": { - "node": ">=18.0.0" + "events": "^3.1.0", + "query-string": "^6.12.1", + "request": "^2.88.2" } }, "node_modules/@tsconfig/node10": { @@ -5938,6 +5941,22 @@ "node": ">=0.10.0" } }, + "node_modules/asn1": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", + "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==", + "dependencies": { + "safer-buffer": "~2.1.0" + } + }, + "node_modules/assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=", + "engines": { + "node": ">=0.8" + } + }, "node_modules/async-mutex": { "version": "0.2.6", "resolved": "https://registry.npmjs.org/async-mutex/-/async-mutex-0.2.6.tgz", @@ -5975,6 +5994,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/aws-sign2": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", + "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=", + "engines": { + "node": "*" + } + }, + "node_modules/aws4": { + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz", + "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==" + }, "node_modules/axios": { "version": "0.21.4", "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", @@ -6181,6 +6213,14 @@ } ] }, + "node_modules/bcrypt-pbkdf": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", + "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", + "dependencies": { + "tweetnacl": "^0.14.3" + } + }, "node_modules/bech32": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/bech32/-/bech32-1.1.4.tgz", @@ -6500,6 +6540,11 @@ "cdl": "bin/cdl.js" } }, + "node_modules/caseless": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", + "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" + }, "node_modules/chalk": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz", @@ -7015,7 +7060,8 @@ "node_modules/convert-source-map": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", - "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==" + "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", + "dev": true }, "node_modules/cookie": { "version": "0.5.0", @@ -7077,8 +7123,7 @@ "node_modules/core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", - "dev": true + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, "node_modules/cosmiconfig": { "version": "8.0.0", @@ -7413,6 +7458,17 @@ "node": ">=12" } }, + "node_modules/dashdash": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", + "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", + "dependencies": { + "assert-plus": "^1.0.0" + }, + "engines": { + "node": ">=0.10" + } + }, "node_modules/data-urls": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-3.0.2.tgz", @@ -8285,6 +8341,15 @@ "stream-shift": "^1.0.2" } }, + "node_modules/ecc-jsbn": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", + "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", + "dependencies": { + "jsbn": "~0.1.0", + "safer-buffer": "^2.1.0" + } + }, "node_modules/electron-to-chromium": { "version": "1.4.650", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.650.tgz", @@ -9218,6 +9283,19 @@ "resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz", "integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw==" }, + "node_modules/extend": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==" + }, + "node_modules/extsprintf": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", + "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=", + "engines": [ + "node >=0.6.0" + ] + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -9256,8 +9334,7 @@ "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", - "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", - "dev": true + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==" }, "node_modules/fast-redact": { "version": "3.5.0", @@ -9407,6 +9484,14 @@ "is-callable": "^1.1.3" } }, + "node_modules/forever-agent": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", + "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=", + "engines": { + "node": "*" + } + }, "node_modules/form-data": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", @@ -9576,6 +9661,7 @@ "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", "integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==", + "dev": true, "engines": { "node": ">=6.9.0" } @@ -9647,6 +9733,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/getpass": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", + "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", + "dependencies": { + "assert-plus": "^1.0.0" + } + }, "node_modules/git-log-parser": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/git-log-parser/-/git-log-parser-1.2.0.tgz", @@ -9872,6 +9966,47 @@ "uglify-js": "^3.1.4" } }, + "node_modules/har-schema": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", + "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=", + "engines": { + "node": ">=4" + } + }, + "node_modules/har-validator": { + "version": "5.1.5", + "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.5.tgz", + "integrity": "sha512-nmT2T0lljbxdQZfspsno9hgrG3Uir6Ks5afism62poxqBM6sDnMEuPmzTq8XN0OEwqKLLdh1jQI3qyE66Nzb3w==", + "deprecated": "this library is no longer supported", + "dependencies": { + "ajv": "^6.12.3", + "har-schema": "^2.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/har-validator/node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/har-validator/node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" + }, "node_modules/hard-rejection": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/hard-rejection/-/hard-rejection-2.1.0.tgz", @@ -10111,6 +10246,20 @@ "node": ">= 0.12.0" } }, + "node_modules/http-signature": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", + "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", + "dependencies": { + "assert-plus": "^1.0.0", + "jsprim": "^1.2.2", + "sshpk": "^1.7.0" + }, + "engines": { + "node": ">=0.8", + "npm": ">=1.3.7" + } + }, "node_modules/https-proxy-agent": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", @@ -10946,6 +11095,11 @@ "ws": "*" } }, + "node_modules/isstream": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", + "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" + }, "node_modules/issue-parser": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/issue-parser/-/issue-parser-6.0.0.tgz", @@ -12628,6 +12782,11 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" + }, "node_modules/jsdom": { "version": "20.0.3", "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-20.0.3.tgz", @@ -12766,6 +12925,11 @@ "resolved": "https://registry.npmjs.org/json-rpc-random-id/-/json-rpc-random-id-1.0.1.tgz", "integrity": "sha1-uknZat7RRE27jaPSA3SKy7zeyMg=" }, + "node_modules/json-schema": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", + "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==" + }, "node_modules/json-schema-traverse": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", @@ -12782,13 +12946,13 @@ "node_modules/json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", - "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", - "dev": true + "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" }, "node_modules/json5": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true, "bin": { "json5": "lib/cli.js" }, @@ -12847,6 +13011,20 @@ "node": "*" } }, + "node_modules/jsprim": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz", + "integrity": "sha512-P2bSOMAc/ciLz6DzgjVlGJP9+BrJWu5UDGK70C2iweC5QBIeFf0ZXRvGjEj2uYgrY2MkAAhsSWHDWlFtEroZWw==", + "dependencies": { + "assert-plus": "1.0.0", + "extsprintf": "1.3.0", + "json-schema": "0.4.0", + "verror": "1.10.0" + }, + "engines": { + "node": ">=0.6.0" + } + }, "node_modules/keccak": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/keccak/-/keccak-3.0.1.tgz", @@ -16488,6 +16666,14 @@ "integrity": "sha512-ub5E4+FBPKwAZx0UwIQOjYWGHTEq5sPqHQNRN8Z9e4A7u3Tj1weLJsL59yH9vmvqEtBHaOmT6cYQKIZOxp35FQ==", "dev": true }, + "node_modules/oauth-sign": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", + "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==", + "engines": { + "node": "*" + } + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -16683,11 +16869,6 @@ "node": ">=6" } }, - "node_modules/pako": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/pako/-/pako-2.1.0.tgz", - "integrity": "sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==" - }, "node_modules/parallax-js": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/parallax-js/-/parallax-js-3.1.0.tgz", @@ -17154,8 +17335,7 @@ "node_modules/psl": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", - "integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==", - "dev": true + "integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==" }, "node_modules/punycode": { "version": "2.1.1", @@ -17228,47 +17408,25 @@ "node": ">=10.13.0" } }, - "node_modules/query-string": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/query-string/-/query-string-8.2.0.tgz", - "integrity": "sha512-tUZIw8J0CawM5wyGBiDOAp7ObdRQh4uBor/fUR9ZjmbZVvw95OD9If4w3MQxr99rg0DJZ/9CIORcpEqU5hQG7g==", - "dependencies": { - "decode-uri-component": "^0.4.1", - "filter-obj": "^5.1.0", - "split-on-first": "^3.0.0" - }, - "engines": { - "node": ">=14.16" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/query-string/node_modules/decode-uri-component": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.4.1.tgz", - "integrity": "sha512-+8VxcR21HhTy8nOt6jf20w0c9CADrw1O8d+VZ/YzzCt4bJ3uBjw+D1q2osAB8RnpwwaeYBxy0HyKQxD5JBMuuQ==", + "node_modules/qs": { + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz", + "integrity": "sha512-qxXIEh4pCGfHICj1mAJQ2/2XVZkjCDTcEgfoSQxc/fYivUZxTkk7L3bDBJSoNrEzXI17oUO5Dp07ktqE5KzczA==", "engines": { - "node": ">=14.16" + "node": ">=0.6" } }, - "node_modules/query-string/node_modules/filter-obj": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/filter-obj/-/filter-obj-5.1.0.tgz", - "integrity": "sha512-qWeTREPoT7I0bifpPUXtxkZJ1XJzxWtfoWWkdVGqa+eCr3SHW/Ocp89o8vLvbUuQnadybJpjOKu4V+RwO6sGng==", - "engines": { - "node": ">=14.16" + "node_modules/query-string": { + "version": "6.13.5", + "resolved": "https://registry.npmjs.org/query-string/-/query-string-6.13.5.tgz", + "integrity": "sha512-svk3xg9qHR39P3JlHuD7g3nRnyay5mHbrPctEBDUxUkHRifPHXJDhBUycdCC0NBjXoDf44Gb+IsOZL1Uwn8M/Q==", + "dependencies": { + "decode-uri-component": "^0.2.0", + "split-on-first": "^1.0.0", + "strict-uri-encode": "^2.0.0" }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/query-string/node_modules/split-on-first": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/split-on-first/-/split-on-first-3.0.0.tgz", - "integrity": "sha512-qxQJTx2ryR0Dw0ITYyekNQWpz6f8dGd7vffGNflQQ3Iqj9NJ6qiZ7ELpZsJ/QBhIVAiDfXdag3+Gp8RvWa62AA==", "engines": { - "node": ">=12" + "node": ">=6" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -18026,6 +18184,59 @@ "node": ">=14" } }, + "node_modules/request": { + "version": "2.88.2", + "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", + "integrity": "sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==", + "deprecated": "request has been deprecated, see https://github.com/request/request/issues/3142", + "dependencies": { + "aws-sign2": "~0.7.0", + "aws4": "^1.8.0", + "caseless": "~0.12.0", + "combined-stream": "~1.0.6", + "extend": "~3.0.2", + "forever-agent": "~0.6.1", + "form-data": "~2.3.2", + "har-validator": "~5.1.3", + "http-signature": "~1.2.0", + "is-typedarray": "~1.0.0", + "isstream": "~0.1.2", + "json-stringify-safe": "~5.0.1", + "mime-types": "~2.1.19", + "oauth-sign": "~0.9.0", + "performance-now": "^2.1.0", + "qs": "~6.5.2", + "safe-buffer": "^5.1.2", + "tough-cookie": "~2.5.0", + "tunnel-agent": "^0.6.0", + "uuid": "^3.3.2" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/request/node_modules/form-data": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", + "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.6", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 0.12" + } + }, + "node_modules/request/node_modules/uuid": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", + "deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.", + "bin": { + "uuid": "bin/uuid" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -18239,8 +18450,7 @@ "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "dev": true + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "node_modules/saxes": { "version": "6.0.0", @@ -18997,6 +19207,30 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, + "node_modules/sshpk": { + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", + "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==", + "dependencies": { + "asn1": "~0.2.3", + "assert-plus": "^1.0.0", + "bcrypt-pbkdf": "^1.0.0", + "dashdash": "^1.12.0", + "ecc-jsbn": "~0.1.1", + "getpass": "^0.1.1", + "jsbn": "~0.1.0", + "safer-buffer": "^2.0.2", + "tweetnacl": "~0.14.0" + }, + "bin": { + "sshpk-conv": "bin/sshpk-conv", + "sshpk-sign": "bin/sshpk-sign", + "sshpk-verify": "bin/sshpk-verify" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/stable": { "version": "0.1.8", "resolved": "https://registry.npmjs.org/stable/-/stable-0.1.8.tgz", @@ -19466,6 +19700,18 @@ "node": ">=0.4.x" } }, + "node_modules/tough-cookie": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", + "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", + "dependencies": { + "psl": "^1.1.28", + "punycode": "^2.1.1" + }, + "engines": { + "node": ">=0.8" + } + }, "node_modules/tr46": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz", @@ -19805,6 +20051,22 @@ "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" } }, + "node_modules/tunnel-agent": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", + "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", + "dependencies": { + "safe-buffer": "^5.0.1" + }, + "engines": { + "node": "*" + } + }, + "node_modules/tweetnacl": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" + }, "node_modules/type": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz", @@ -20224,6 +20486,19 @@ "resolved": "https://registry.npmjs.org/varint/-/varint-6.0.0.tgz", "integrity": "sha512-cXEIW6cfr15lFv563k4GuVuW/fiwjknytD37jIOLSdSWuOI6WnO/oKwmP2FQTU2l01LP8/M5TSAJpzUaGe3uWg==" }, + "node_modules/verror": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", + "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", + "engines": [ + "node >=0.6.0" + ], + "dependencies": { + "assert-plus": "^1.0.0", + "core-util-is": "1.0.2", + "extsprintf": "^1.2.0" + } + }, "node_modules/victory-vendor": { "version": "36.9.1", "resolved": "https://registry.npmjs.org/victory-vendor/-/victory-vendor-36.9.1.tgz", diff --git a/package.json b/package.json index b6be40ec..3ded17f8 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "@dcl/schemas": "^14.0.0", "@dcl/single-sign-on-client": "^0.1.0", "@dcl/ui-env": "^1.5.0", - "@transak/transak-sdk": "^3.1.3", + "@transak/transak-sdk": "^1.0.31", "@types/flat": "0.0.28", "@types/segment-analytics": "^0.0.38", "@well-known-components/fetch-component": "^2.0.1", diff --git a/src/lib/marketplaceApi.ts b/src/lib/marketplaceApi.ts index 43f23ccb..2ee01522 100644 --- a/src/lib/marketplaceApi.ts +++ b/src/lib/marketplaceApi.ts @@ -1,6 +1,5 @@ import { AuthIdentity } from 'decentraland-crypto-fetch' import { WertMessageWithTarget } from '../modules/gateway/types' -import { OrderResponse } from '../modules/gateway/transak/types' import { BaseClient } from './BaseClient' export class MarketplaceAPI extends BaseClient { @@ -22,17 +21,4 @@ export class MarketplaceAPI extends BaseClient { throw new Error((error as Error).message) } } - /** - * Given the order id, returns relevant data related to status changes (status & tx hash). - * - * @param orderId - Transak Order ID. - */ - async getOrder( - orderId: string, - identity: AuthIdentity - ): Promise { - return await this.fetch(`/v1/transak/orders/${orderId}`, { - identity - }) - } } diff --git a/src/modules/gateway/sagas.spec.ts b/src/modules/gateway/sagas.spec.ts index 978cb107..b065a13b 100644 --- a/src/modules/gateway/sagas.spec.ts +++ b/src/modules/gateway/sagas.spec.ts @@ -46,7 +46,6 @@ import { } from './types' import { getPendingManaPurchase, getPendingPurchases } from './selectors' import { OrderResponse, TransakOrderStatus } from './transak/types' -import { generateIdentityFailure } from '../identity' jest.mock('@wert-io/widget-initializer') jest.mock('../../lib/marketplaceApi') @@ -789,65 +788,27 @@ describe('when handling the action signaling the load of the local storage into .mockResolvedValue(mockTransakOrderResponse) }) - describe("and there is no identity and it's generate function failed", () => { - it('should put the action signaling the failure of the poll purchase status request', async () => { - const transakPurchase = { - ...mockPurchase, - id: mockTransakOrderResponse.data.id, - gateway: NetworkGatewayType.TRANSAK - } - - return expectSaga(gatewaySaga) - .provide([[select(getPendingPurchases), [transakPurchase]]]) - .dispatch(load({})) - .dispatch(generateIdentityFailure('', '')) - .put(pollPurchaseStatusRequest(transakPurchase)) - - .not.put( - setPurchase({ - ...transakPurchase, - status: PurchaseStatus.COMPLETE, - txHash: mockTransakOrderResponse.data.transactionHash!, - failureReason: null - }) - ) - .put(pollPurchaseStatusFailure(NO_IDENTITY_ERROR)) - .silentRun() - }) - }) - - describe('and there is identity', () => { - beforeEach(() => { - jest - .spyOn(MarketplaceAPI.prototype, 'getOrder') - .mockResolvedValue(mockTransakOrderResponse) - }) - it('should put the action signaling the start pof the purchase status polling request', async () => { - const transakPurchase = { - ...mockPurchase, - id: mockTransakOrderResponse.data.id, - gateway: NetworkGatewayType.TRANSAK - } + it('should put the action signaling the start pof the purchase status polling request', async () => { + const transakPurchase = { + ...mockPurchase, + id: mockTransakOrderResponse.data.id, + gateway: NetworkGatewayType.TRANSAK + } - return expectSaga(gatewaySaga) - .provide([ - [select(getPendingPurchases), [transakPurchase]], - [call(getIdentityOrRedirect), {}] - ]) - .dispatch(load({})) - .dispatch(generateIdentityFailure('', '')) - .put(pollPurchaseStatusRequest(transakPurchase)) - .put( - setPurchase({ - ...transakPurchase, - status: PurchaseStatus.COMPLETE, - txHash: mockTransakOrderResponse.data.transactionHash!, - failureReason: null - }) - ) - .put(pollPurchaseStatusSuccess()) - .silentRun() - }) + return expectSaga(gatewaySaga) + .provide([[select(getPendingPurchases), [transakPurchase]]]) + .dispatch(load({})) + .put(pollPurchaseStatusRequest(transakPurchase)) + .put( + setPurchase({ + ...transakPurchase, + status: PurchaseStatus.COMPLETE, + txHash: mockTransakOrderResponse.data.transactionHash!, + failureReason: null + }) + ) + .put(pollPurchaseStatusSuccess()) + .silentRun() }) }) }) @@ -864,13 +825,12 @@ describe('when handling the action signaling the load of the local storage into describe('when it is possible to get the order from Transak API', () => { beforeEach(() => { jest - .spyOn(MarketplaceAPI.prototype, 'getOrder') + .spyOn(Transak.prototype, 'getOrder') .mockResolvedValue(mockTransakOrderResponse) }) it('should get the order, put the action signaling the set of updated purchase, and the action signaling the success of the poll purchase status request', async () => { return expectSaga(gatewaySaga) - .provide([[call(getIdentityOrRedirect), {}]]) .put( setPurchase({ ...transakPurchase, @@ -888,13 +848,12 @@ describe('when handling the action signaling the load of the local storage into describe('when it is not possible to get the order from Transak API because the request fails', () => { beforeEach(() => { jest - .spyOn(MarketplaceAPI.prototype, 'getOrder') + .spyOn(Transak.prototype, 'getOrder') .mockRejectedValue(new Error(error)) }) it('should get the order, put the action signaling the set of updated purchase, and the action signaling the success of the poll purchase status request', async () => { return expectSaga(gatewaySaga) - .provide([[call(getIdentityOrRedirect), {}]]) .put(pollPurchaseStatusFailure(error)) .dispatch(pollPurchaseStatusRequest(transakPurchase)) .silentRun() diff --git a/src/modules/gateway/sagas.ts b/src/modules/gateway/sagas.ts index 9e2f62f9..60fe790c 100644 --- a/src/modules/gateway/sagas.ts +++ b/src/modules/gateway/sagas.ts @@ -3,9 +3,7 @@ import { delay, ForkEffect, put, - race, select, - take, takeEvery, takeLatest } from 'redux-saga/effects' @@ -67,11 +65,6 @@ import { import { isManaPurchase, purchaseEventsChannel } from './utils' import { Wallet } from '../wallet/types' import { isErrorWithMessage } from '../../lib/error' -import { - GENERATE_IDENTITY_FAILURE, - GENERATE_IDENTITY_SUCCESS, - GenerateIdentitySuccessAction -} from '../identity' const DEFAULT_POLLING_DELAY = 3000 const BUY_MANA_WITH_FIAT_FEEDBACK_MODAL_NAME = 'BuyManaWithFiatFeedbackModal' @@ -329,35 +322,13 @@ export function createGatewaySaga(config: GatewaySagasConfig) { throw new Error('Transak config not found') } - let identity: AuthIdentity | null = yield call(getIdentityOrRedirect) - - if (!identity) { - const { success } = (yield race({ - success: take(GENERATE_IDENTITY_SUCCESS), - failure: take(GENERATE_IDENTITY_FAILURE) - })) as { success: GenerateIdentitySuccessAction } - - if (success) { - identity = (yield call(getIdentityOrRedirect)) as AuthIdentity - } else { - throw new Error(NO_IDENTITY_ERROR) - } - } - - const marketplaceAPI = new MarketplaceAPI( - transakConfig.marketplaceServerURL - ) - const transak = new Transak(transakConfig, {}, identity) + const transak = new Transak(transakConfig) let statusHasChanged = false while (!statusHasChanged) { const { data: { status, transactionHash, errorMessage } - }: OrderResponse = yield call( - [marketplaceAPI, 'getOrder'], - id, - identity - ) + }: OrderResponse = yield call([transak, transak.getOrder], id) const newStatus: PurchaseStatus = yield call( [transak, transak.getPurchaseStatus], status diff --git a/src/modules/gateway/transak/Transak.spec.ts b/src/modules/gateway/transak/Transak.spec.ts index 448e0fec..0734022b 100644 --- a/src/modules/gateway/transak/Transak.spec.ts +++ b/src/modules/gateway/transak/Transak.spec.ts @@ -1,5 +1,6 @@ import { select } from 'redux-saga/effects' import { expectSaga } from 'redux-saga-test-plan' +import transakSDK from '@transak/transak-sdk' import { ChainId } from '@dcl/schemas/dist/dapps/chain-id' import { Network } from '@dcl/schemas/dist/dapps/network' import { NetworkGatewayType } from 'decentraland-ui' @@ -20,21 +21,6 @@ import { OrderData, TradeType, TransakOrderStatus } from './types' jest.mock('../../../lib/eth') -let initMock -jest.mock('@transak/transak-sdk', () => { - const actualTransakSDK = jest.requireActual('@transak/transak-sdk') - - return { - __esModule: true, - ...actualTransakSDK, - Transak: jest.fn().mockImplementation(config => { - return { - init: initMock - } - }) - } -}) - const mockGetChainIdByNetwork = getChainIdByNetwork as jest.MockedFunction< typeof getChainIdByNetwork > @@ -51,7 +37,6 @@ const mockConfig: GatewaySagasConfig = { pollingDelay: 50 }, [NetworkGatewayType.TRANSAK]: { - marketplaceServerURL: 'https://marketplace-server.decentraland.zone', apiBaseUrl: 'http://transak-base.url.xyz', key: 'transak-key', env: 'TEST', @@ -100,8 +85,8 @@ const mockOrderDataWithNftAssetInfo = { ...mockOrderData.status, isNFTOrder: true, nftAssetInfo: { - collection: 'contractAddress', - tokenId: '123', + contractAddress: 'contractAddress', + tokenId: 'anId', tradeType: TradeType.PRIMARY } } @@ -123,9 +108,9 @@ const mockNftPurchase: NFTPurchase = { ...mockManaPurchase, nft: { contractAddress: 'contractAddress', - tokenId: '123', - itemId: null, - tradeType: TradeType.SECONDARY, + itemId: 'anId', + tokenId: undefined, + tradeType: TradeType.PRIMARY, cryptoAmount: 10 } } @@ -178,33 +163,12 @@ describe('when interacting with Transak', () => { }) describe('when purchasing an NFT', () => { - let originalHref - beforeEach(() => { - jest.clearAllMocks() - originalHref = window.location.href - Object.defineProperty(window, 'location', { - writable: true, // Allow href to be writable - value: { - href: originalHref - } - }) - }) describe('when it belongs to the primary market', () => { - beforeEach(() => { - Object.defineProperty(window, 'location', { - value: { - href: - 'https://decentraland.zone/contracts/contractAddress/tokens/123' - } - }) - }) - it('should put a new message in the channel signaling the set of the purchase with the nft info and the item id', () => { transak.emitPurchaseEvent( mockOrderDataWithNftAssetInfo.status, Network.ETHEREUM ) - return expectSaga(gatewaySaga) .put(setPurchase({ ...mockNftPurchase, amount: 1 })) .silentRun() @@ -212,21 +176,13 @@ describe('when interacting with Transak', () => { }) describe('when it belongs to the primary market', () => { - beforeEach(() => { - Object.defineProperty(window, 'location', { - value: { - href: - 'https://decentraland.zone/contracts/contractAddress/items/234' - } - }) - }) it('should put a new message in the channel signaling the set of the purchase with the nft info and the item id', () => { transak.emitPurchaseEvent( { ...mockOrderDataWithNftAssetInfo.status, nftAssetInfo: { ...mockOrderDataWithNftAssetInfo.status.nftAssetInfo, - tradeType: TradeType.PRIMARY + tradeType: TradeType.SECONDARY } }, Network.ETHEREUM @@ -238,9 +194,9 @@ describe('when interacting with Transak', () => { amount: 1, nft: { ...mockNftPurchase.nft, - tokenId: null, - itemId: '234', - tradeType: TradeType.PRIMARY + tradeType: TradeType.SECONDARY, + itemId: undefined, + tokenId: 'anId' } }) ) @@ -250,14 +206,14 @@ describe('when interacting with Transak', () => { }) }) - describe('when opening the widget', () => { + describe('when opnening the widget', () => { beforeEach(() => { - initMock = jest.fn() + jest.spyOn(transakSDK.prototype, 'init').mockImplementation(() => {}) }) it('should call the method init from the Transak SDK', () => { transak.openWidget(mockAddress, Network.ETHEREUM) - expect(initMock).toHaveBeenCalled() + return expect(transakSDK.prototype.init).toHaveBeenCalled() }) }) }) diff --git a/src/modules/gateway/transak/Transak.ts b/src/modules/gateway/transak/Transak.ts index d355ba52..7d352d06 100644 --- a/src/modules/gateway/transak/Transak.ts +++ b/src/modules/gateway/transak/Transak.ts @@ -1,8 +1,4 @@ -import { - Transak as TransakSDK, - TransakConfig as TransakSDKConfig -} from '@transak/transak-sdk' -import { AuthIdentity } from 'decentraland-crypto-fetch' +import transakSDK from '@transak/transak-sdk' import Pusher from 'pusher-js' import { Network } from '@dcl/schemas/dist/dapps/network' import { NetworkGatewayType } from 'decentraland-ui' @@ -16,6 +12,7 @@ import { OrderResponse, TradeType, TransakOrderStatus, + TransakSDK, WebSocketEvents } from './types' @@ -26,13 +23,11 @@ export class Transak { private readonly customizationOptions: Partial private readonly pusher: Pusher private readonly transakAPI: BaseAPI - private readonly identity: AuthIdentity | undefined private sdk: TransakSDK constructor( config: TransakConfig, - customizationOptions?: Partial, - identity?: AuthIdentity + customizationOptions?: Partial ) { const { apiBaseUrl, @@ -44,7 +39,6 @@ export class Transak { cluster: appCluster }) this.transakAPI = new BaseAPI(apiBaseUrl) - this.identity = identity } /** @@ -53,11 +47,8 @@ export class Transak { * @param network - Network in which the trasanctions will be done */ private suscribeToEvents(network: Network) { - if (!TransakSDK.EVENTS) { - return - } - TransakSDK.on( - TransakSDK.EVENTS.TRANSAK_ORDER_CREATED, + this.sdk.on( + this.sdk.EVENTS.TRANSAK_ORDER_CREATED, (orderData: OrderData) => { const events = [ WebSocketEvents.ORDER_PAYMENT_VERIFYING, @@ -67,7 +58,6 @@ export class Transak { ] const channel = this.pusher.subscribe(orderData.status.id) - this.emitPurchaseEvent(orderData.status, network) events.forEach(event => { channel.bind(event, (orderData: OrderData['status']) => { @@ -85,7 +75,7 @@ export class Transak { } ) - TransakSDK.on(TransakSDK.EVENTS.TRANSAK_WIDGET_CLOSE, () => { + this.sdk.on(this.sdk.EVENTS.TRANSAK_WIDGET_CLOSE, () => { setTimeout(() => { document.querySelector('html')?.style.removeProperty('overflow') }, 1000) @@ -115,8 +105,7 @@ export class Transak { ): DefaultCustomizationOptions { return { apiKey: this.config.key, // Your API Key - environment: (this.config.env || - 'STAGING') as TransakSDKConfig['environment'], // STAGING/PRODUCTION + environment: this.config.env || 'STAGING', // STAGING/PRODUCTION networks: 'ethereum,matic', walletAddress: address, // Your customer's wallet address hostURL: window.location.origin, @@ -125,28 +114,6 @@ export class Transak { } } - getItemIdFromUrl(url: string): string | null { - const itemRegex = /\/items\/(\d+)/ - const itemMatch = url.match(itemRegex) - - if (itemMatch) { - return itemMatch[1] // Return the item id - } - - return null // Return null if no item id is found - } - - getTokenIdFromUrl(url: string): string | null { - const tokenRegex = /\/tokens\/(\d+)/ - const tokenMatch = url.match(tokenRegex) - - if (tokenMatch) { - return tokenMatch[1] // Return the token id - } - - return null // Return null if no token id is found - } - /** * Given the data of the order and its status, returns an object with the relevant information of the purchase. * @@ -169,10 +136,6 @@ export class Transak { paymentOptionId } = orderData - // read if there's item in the URL and set the item id otherwise set the token id - const itemId = this.getItemIdFromUrl(window.location.href) - const tokenId = this.getTokenIdFromUrl(window.location.href) - return { id, network, @@ -186,10 +149,16 @@ export class Transak { ...(isNFTOrder && nftAssetInfo ? { nft: { - contractAddress: nftAssetInfo.collection, - tokenId, - itemId, - tradeType: itemId ? TradeType.PRIMARY : TradeType.SECONDARY, + contractAddress: nftAssetInfo.contractAddress, + tokenId: + nftAssetInfo.tradeType === TradeType.SECONDARY + ? nftAssetInfo.tokenId + : undefined, + itemId: + nftAssetInfo.tradeType === TradeType.PRIMARY + ? nftAssetInfo.tokenId + : undefined, + tradeType: nftAssetInfo.tradeType, cryptoAmount } } @@ -224,14 +193,12 @@ export class Transak { ...this.defaultCustomizationOptions(address), ...this.customizationOptions } - const config = { - ...customizationOptions, - defaultNetwork: transakNetwork, - walletAddress: address, - networks: transakNetwork - } - this.sdk = new TransakSDK(config) as TransakSDK + this.sdk = new transakSDK(customizationOptions) as TransakSDK this.suscribeToEvents(network) + + this.sdk.partnerData.walletAddress = address + this.sdk.partnerData.defaultNetwork = transakNetwork + this.sdk.partnerData.networks = transakNetwork this.sdk.init() } @@ -241,15 +208,9 @@ export class Transak { * @param orderId - Transak Order ID. */ async getOrder(orderId: string): Promise { - return await this.transakAPI.request( - 'GET', - `/transak/orders/${orderId}`, - { identity: this.identity }, - { - headers: { - 'Content-Type': 'application/json' - } - } - ) + return await this.transakAPI.request('GET', '/v2/order', { + apiKey: this.config.key, + orderId + }) } } diff --git a/src/modules/gateway/transak/types.ts b/src/modules/gateway/transak/types.ts index 75d3869c..f96b956e 100644 --- a/src/modules/gateway/transak/types.ts +++ b/src/modules/gateway/transak/types.ts @@ -1,4 +1,4 @@ -import { TransakConfig } from '@transak/transak-sdk' +import { EventEmitter } from 'ws' export enum WebSocketEvents { ORDER_PAYMENT_VERIFYING = 'ORDER_PAYMENT_VERIFYING', @@ -31,7 +31,7 @@ export enum ProductsAvailed { export type CustomizationOptions = { apiKey: string // Your API Key - environment: TransakConfig['environment'] // PRODUCTION/STAGING + environment: string // PRODUCTION/STAGING networks: string walletAddress: string // Your customer's wallet address hostURL: string @@ -44,6 +44,7 @@ export type CustomizationOptions = { redirectURL?: string contractAddress?: string // NFT Contract address tradeType?: TradeType // Can be primary in case of minting and secondary in case of secondary sale + tokenId?: string // Decentraland tokenId in case of secondary sale and item id in case of primary sale (minting) productsAvailed?: ProductsAvailed // Would be BUY as NFT checkout is a special case of on ramping isNFT?: boolean // Will be true in case the bought assset is an NFT } @@ -81,8 +82,9 @@ export type OrderData = { transactionHash?: string network: 'ethereum' | 'matic' nftAssetInfo?: { - collection: string - tokenId: string[] + contractAddress: string + tokenId: string + tradeType: TradeType } paymentOptionId: string quoteId: string @@ -104,3 +106,15 @@ export type OrderResponse = { errorMessage: string | null } } + +export type TransakSDK = EventEmitter & { + init: () => void + close: () => void + partnerData: { + defaultNetwork: string + walletAddress: string + partnerOrderId: string + networks: string + } + EVENTS: Record +} diff --git a/src/modules/gateway/types.ts b/src/modules/gateway/types.ts index 92f41be4..b9f8fb44 100644 --- a/src/modules/gateway/types.ts +++ b/src/modules/gateway/types.ts @@ -52,7 +52,6 @@ export type MoonPayConfig = { } export type TransakConfig = { - marketplaceServerURL: string apiBaseUrl: string key: string env: string diff --git a/src/types/transak.d.ts b/src/types/transak.d.ts new file mode 100644 index 00000000..e0e24a15 --- /dev/null +++ b/src/types/transak.d.ts @@ -0,0 +1 @@ +declare module '@transak/transak-sdk'