From 611f3d0067d1255872178f44477142cd0e0929bc Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Fri, 15 Nov 2024 13:59:07 +0100 Subject: [PATCH] Revert "Revert "Revert "Revert "Feat/transak bump (#639)" (#643)" (#645)" (#648)" (#649) This reverts commit ae0a055d736aac2762db000172bb3717a80b4026. --- 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, 298 insertions(+), 420 deletions(-) delete mode 100644 src/types/transak.d.ts diff --git a/package-lock.json b/package-lock.json index 02106585..a60a0bc5 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": "^1.0.31", + "@transak/transak-sdk": "^3.1.3", "@types/flat": "0.0.28", "@types/segment-analytics": "^0.0.38", "@well-known-components/fetch-component": "^2.0.1", @@ -325,7 +325,6 @@ "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" @@ -565,7 +564,6 @@ "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", @@ -595,7 +593,6 @@ "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" } @@ -722,7 +719,6 @@ "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", @@ -749,7 +745,6 @@ "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" }, @@ -796,7 +791,6 @@ "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", @@ -4670,13 +4664,16 @@ } }, "node_modules/@transak/transak-sdk": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/@transak/transak-sdk/-/transak-sdk-1.2.3.tgz", - "integrity": "sha512-nmpMB6zUwVO/2VlTQIrlDawUbMVTGoio4IiwHxCbNRiFGzxxXwymXNqlspxCszWtznUHFHWtEMomRAdW05MAkw==", + "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==", "dependencies": { - "events": "^3.1.0", - "query-string": "^6.12.1", - "request": "^2.88.2" + "events": "^3.3.0", + "pako": "^2.1.0", + "query-string": "^8.2.0" + }, + "engines": { + "node": ">=18.0.0" } }, "node_modules/@tsconfig/node10": { @@ -5941,22 +5938,6 @@ "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", @@ -5994,19 +5975,6 @@ "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", @@ -6213,14 +6181,6 @@ } ] }, - "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", @@ -6540,11 +6500,6 @@ "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", @@ -7060,8 +7015,7 @@ "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==", - "dev": true + "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==" }, "node_modules/cookie": { "version": "0.5.0", @@ -7123,7 +7077,8 @@ "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=" + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", + "dev": true }, "node_modules/cosmiconfig": { "version": "8.0.0", @@ -7458,17 +7413,6 @@ "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", @@ -8341,15 +8285,6 @@ "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", @@ -9283,19 +9218,6 @@ "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", @@ -9334,7 +9256,8 @@ "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==" + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true }, "node_modules/fast-redact": { "version": "3.5.0", @@ -9484,14 +9407,6 @@ "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", @@ -9661,7 +9576,6 @@ "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" } @@ -9733,14 +9647,6 @@ "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", @@ -9966,47 +9872,6 @@ "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", @@ -10246,20 +10111,6 @@ "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", @@ -11095,11 +10946,6 @@ "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", @@ -12782,11 +12628,6 @@ "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", @@ -12925,11 +12766,6 @@ "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", @@ -12946,13 +12782,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=" + "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", + "dev": true }, "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" }, @@ -13011,20 +12847,6 @@ "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", @@ -16666,14 +16488,6 @@ "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", @@ -16869,6 +16683,11 @@ "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", @@ -17335,7 +17154,8 @@ "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==" + "integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==", + "dev": true }, "node_modules/punycode": { "version": "2.1.1", @@ -17408,25 +17228,47 @@ "node": ">=10.13.0" } }, - "node_modules/qs": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz", - "integrity": "sha512-qxXIEh4pCGfHICj1mAJQ2/2XVZkjCDTcEgfoSQxc/fYivUZxTkk7L3bDBJSoNrEzXI17oUO5Dp07ktqE5KzczA==", + "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": ">=0.6" + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "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" + "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==", + "engines": { + "node": ">=14.16" + } + }, + "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" }, + "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": ">=6" + "node": ">=12" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -18184,59 +18026,6 @@ "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", @@ -18450,7 +18239,8 @@ "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "dev": true }, "node_modules/saxes": { "version": "6.0.0", @@ -19207,30 +18997,6 @@ "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", @@ -19700,18 +19466,6 @@ "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", @@ -20051,22 +19805,6 @@ "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", @@ -20486,19 +20224,6 @@ "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 3ded17f8..b6be40ec 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": "^1.0.31", + "@transak/transak-sdk": "^3.1.3", "@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 2ee01522..43f23ccb 100644 --- a/src/lib/marketplaceApi.ts +++ b/src/lib/marketplaceApi.ts @@ -1,5 +1,6 @@ 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 { @@ -21,4 +22,17 @@ 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 b065a13b..978cb107 100644 --- a/src/modules/gateway/sagas.spec.ts +++ b/src/modules/gateway/sagas.spec.ts @@ -46,6 +46,7 @@ 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') @@ -788,27 +789,65 @@ describe('when handling the action signaling the load of the local storage into .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 - } + 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({})) - .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({})) + .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 + } + + 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() + }) }) }) }) @@ -825,12 +864,13 @@ 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(Transak.prototype, 'getOrder') + .spyOn(MarketplaceAPI.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, @@ -848,12 +888,13 @@ 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(Transak.prototype, 'getOrder') + .spyOn(MarketplaceAPI.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 60fe790c..9e2f62f9 100644 --- a/src/modules/gateway/sagas.ts +++ b/src/modules/gateway/sagas.ts @@ -3,7 +3,9 @@ import { delay, ForkEffect, put, + race, select, + take, takeEvery, takeLatest } from 'redux-saga/effects' @@ -65,6 +67,11 @@ 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' @@ -322,13 +329,35 @@ export function createGatewaySaga(config: GatewaySagasConfig) { throw new Error('Transak config not found') } - const transak = new Transak(transakConfig) + 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) let statusHasChanged = false while (!statusHasChanged) { const { data: { status, transactionHash, errorMessage } - }: OrderResponse = yield call([transak, transak.getOrder], id) + }: OrderResponse = yield call( + [marketplaceAPI, 'getOrder'], + id, + identity + ) 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 0734022b..448e0fec 100644 --- a/src/modules/gateway/transak/Transak.spec.ts +++ b/src/modules/gateway/transak/Transak.spec.ts @@ -1,6 +1,5 @@ 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' @@ -21,6 +20,21 @@ 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 > @@ -37,6 +51,7 @@ const mockConfig: GatewaySagasConfig = { pollingDelay: 50 }, [NetworkGatewayType.TRANSAK]: { + marketplaceServerURL: 'https://marketplace-server.decentraland.zone', apiBaseUrl: 'http://transak-base.url.xyz', key: 'transak-key', env: 'TEST', @@ -85,8 +100,8 @@ const mockOrderDataWithNftAssetInfo = { ...mockOrderData.status, isNFTOrder: true, nftAssetInfo: { - contractAddress: 'contractAddress', - tokenId: 'anId', + collection: 'contractAddress', + tokenId: '123', tradeType: TradeType.PRIMARY } } @@ -108,9 +123,9 @@ const mockNftPurchase: NFTPurchase = { ...mockManaPurchase, nft: { contractAddress: 'contractAddress', - itemId: 'anId', - tokenId: undefined, - tradeType: TradeType.PRIMARY, + tokenId: '123', + itemId: null, + tradeType: TradeType.SECONDARY, cryptoAmount: 10 } } @@ -163,12 +178,33 @@ 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() @@ -176,13 +212,21 @@ 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.SECONDARY + tradeType: TradeType.PRIMARY } }, Network.ETHEREUM @@ -194,9 +238,9 @@ describe('when interacting with Transak', () => { amount: 1, nft: { ...mockNftPurchase.nft, - tradeType: TradeType.SECONDARY, - itemId: undefined, - tokenId: 'anId' + tokenId: null, + itemId: '234', + tradeType: TradeType.PRIMARY } }) ) @@ -206,14 +250,14 @@ describe('when interacting with Transak', () => { }) }) - describe('when opnening the widget', () => { + describe('when opening the widget', () => { beforeEach(() => { - jest.spyOn(transakSDK.prototype, 'init').mockImplementation(() => {}) + initMock = jest.fn() }) it('should call the method init from the Transak SDK', () => { transak.openWidget(mockAddress, Network.ETHEREUM) - return expect(transakSDK.prototype.init).toHaveBeenCalled() + expect(initMock).toHaveBeenCalled() }) }) }) diff --git a/src/modules/gateway/transak/Transak.ts b/src/modules/gateway/transak/Transak.ts index 7d352d06..d355ba52 100644 --- a/src/modules/gateway/transak/Transak.ts +++ b/src/modules/gateway/transak/Transak.ts @@ -1,4 +1,8 @@ -import transakSDK from '@transak/transak-sdk' +import { + Transak as TransakSDK, + TransakConfig as TransakSDKConfig +} from '@transak/transak-sdk' +import { AuthIdentity } from 'decentraland-crypto-fetch' import Pusher from 'pusher-js' import { Network } from '@dcl/schemas/dist/dapps/network' import { NetworkGatewayType } from 'decentraland-ui' @@ -12,7 +16,6 @@ import { OrderResponse, TradeType, TransakOrderStatus, - TransakSDK, WebSocketEvents } from './types' @@ -23,11 +26,13 @@ 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 + customizationOptions?: Partial, + identity?: AuthIdentity ) { const { apiBaseUrl, @@ -39,6 +44,7 @@ export class Transak { cluster: appCluster }) this.transakAPI = new BaseAPI(apiBaseUrl) + this.identity = identity } /** @@ -47,8 +53,11 @@ export class Transak { * @param network - Network in which the trasanctions will be done */ private suscribeToEvents(network: Network) { - this.sdk.on( - this.sdk.EVENTS.TRANSAK_ORDER_CREATED, + if (!TransakSDK.EVENTS) { + return + } + TransakSDK.on( + TransakSDK.EVENTS.TRANSAK_ORDER_CREATED, (orderData: OrderData) => { const events = [ WebSocketEvents.ORDER_PAYMENT_VERIFYING, @@ -58,6 +67,7 @@ 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']) => { @@ -75,7 +85,7 @@ export class Transak { } ) - this.sdk.on(this.sdk.EVENTS.TRANSAK_WIDGET_CLOSE, () => { + TransakSDK.on(TransakSDK.EVENTS.TRANSAK_WIDGET_CLOSE, () => { setTimeout(() => { document.querySelector('html')?.style.removeProperty('overflow') }, 1000) @@ -105,7 +115,8 @@ export class Transak { ): DefaultCustomizationOptions { return { apiKey: this.config.key, // Your API Key - environment: this.config.env || 'STAGING', // STAGING/PRODUCTION + environment: (this.config.env || + 'STAGING') as TransakSDKConfig['environment'], // STAGING/PRODUCTION networks: 'ethereum,matic', walletAddress: address, // Your customer's wallet address hostURL: window.location.origin, @@ -114,6 +125,28 @@ 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. * @@ -136,6 +169,10 @@ 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, @@ -149,16 +186,10 @@ export class Transak { ...(isNFTOrder && nftAssetInfo ? { nft: { - contractAddress: nftAssetInfo.contractAddress, - tokenId: - nftAssetInfo.tradeType === TradeType.SECONDARY - ? nftAssetInfo.tokenId - : undefined, - itemId: - nftAssetInfo.tradeType === TradeType.PRIMARY - ? nftAssetInfo.tokenId - : undefined, - tradeType: nftAssetInfo.tradeType, + contractAddress: nftAssetInfo.collection, + tokenId, + itemId, + tradeType: itemId ? TradeType.PRIMARY : TradeType.SECONDARY, cryptoAmount } } @@ -193,12 +224,14 @@ export class Transak { ...this.defaultCustomizationOptions(address), ...this.customizationOptions } - this.sdk = new transakSDK(customizationOptions) as TransakSDK + const config = { + ...customizationOptions, + defaultNetwork: transakNetwork, + walletAddress: address, + networks: transakNetwork + } + this.sdk = new TransakSDK(config) as TransakSDK this.suscribeToEvents(network) - - this.sdk.partnerData.walletAddress = address - this.sdk.partnerData.defaultNetwork = transakNetwork - this.sdk.partnerData.networks = transakNetwork this.sdk.init() } @@ -208,9 +241,15 @@ export class Transak { * @param orderId - Transak Order ID. */ async getOrder(orderId: string): Promise { - return await this.transakAPI.request('GET', '/v2/order', { - apiKey: this.config.key, - orderId - }) + return await this.transakAPI.request( + 'GET', + `/transak/orders/${orderId}`, + { identity: this.identity }, + { + headers: { + 'Content-Type': 'application/json' + } + } + ) } } diff --git a/src/modules/gateway/transak/types.ts b/src/modules/gateway/transak/types.ts index f96b956e..75d3869c 100644 --- a/src/modules/gateway/transak/types.ts +++ b/src/modules/gateway/transak/types.ts @@ -1,4 +1,4 @@ -import { EventEmitter } from 'ws' +import { TransakConfig } from '@transak/transak-sdk' 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: string // PRODUCTION/STAGING + environment: TransakConfig['environment'] // PRODUCTION/STAGING networks: string walletAddress: string // Your customer's wallet address hostURL: string @@ -44,7 +44,6 @@ 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 } @@ -82,9 +81,8 @@ export type OrderData = { transactionHash?: string network: 'ethereum' | 'matic' nftAssetInfo?: { - contractAddress: string - tokenId: string - tradeType: TradeType + collection: string + tokenId: string[] } paymentOptionId: string quoteId: string @@ -106,15 +104,3 @@ 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 b9f8fb44..92f41be4 100644 --- a/src/modules/gateway/types.ts +++ b/src/modules/gateway/types.ts @@ -52,6 +52,7 @@ 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 deleted file mode 100644 index e0e24a15..00000000 --- a/src/types/transak.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module '@transak/transak-sdk'