@toruslabs/torus-embed
Advanced tools
Comparing version 0.2.9 to 0.2.10
@@ -11,3 +11,3 @@ import Web3 from 'web3' | ||
showWallet(path: 'transfer' | 'topup' | 'home' | 'settings' | 'history'): void | ||
initiateTopup(provider: 'simplex' | 'moonpay' | 'wyre' | 'coindirect', params?: PaymentParams): Promise<boolean> | ||
initiateTopup(provider: 'moonpay' | 'wyre' | 'coindirect', params?: PaymentParams): Promise<boolean> | ||
showTorusButton(): void | ||
@@ -14,0 +14,0 @@ hideTorusButton(): void |
@@ -14,2 +14,6 @@ "use strict"; | ||
var _web = _interopRequireDefault(require("web3")); | ||
var _randomId = _interopRequireDefault(require("random-id")); | ||
var _inpageProvider = _interopRequireDefault(require("./inpage-provider")); | ||
@@ -25,3 +29,3 @@ | ||
var _web = _interopRequireDefault(require("web3")); | ||
var _PopupHandler = _interopRequireDefault(require("./PopupHandler")); | ||
@@ -34,3 +38,3 @@ var _defaultVerifiers; | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
@@ -53,3 +57,3 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
cleanContextForImports(); | ||
var iframeIntegrity = 'sha384-05R9PLUtMt85LrNqYYrb+eVWaYKjhCimXqdE+4nhHPEbKsL4f1zGlXFq9QEdx5AV'; | ||
var iframeIntegrity = 'sha384-ui+H377gfHVy+vW34b9ZAbw4iipa/tNSAhxM8RGPBkEImnASxCC1BPrOJ8sKbdox'; | ||
var expectedCacheControlHeader = 'max-age=3600'; | ||
@@ -73,3 +77,3 @@ restoreContextAfterImports(); | ||
window.addEventListener('message', receiveMessage, false); // evt.data === 'torus:3PCunsupported' | ||
window.addEventListener('message', receiveMessage, false); | ||
@@ -91,2 +95,3 @@ var Torus = | ||
this.torusLoadingBtn = {}; | ||
this.torusUrl = ''; | ||
this.torusIframe = {}; | ||
@@ -139,3 +144,3 @@ this.torusLoginModal = {}; | ||
case 'staging': | ||
torusUrl = 'https://staging.tor.us/v0.2.8'; | ||
torusUrl = 'https://staging.tor.us/v0.2.9'; | ||
logLevel = 'info'; | ||
@@ -155,3 +160,3 @@ break; | ||
default: | ||
torusUrl = 'https://app.tor.us/v0.2.9'; | ||
torusUrl = 'https://app.tor.us/v0.2.10'; | ||
logLevel = 'error'; | ||
@@ -161,2 +166,3 @@ break; | ||
_this.torusUrl = torusUrl; | ||
_this.enabledVerifiers = _objectSpread({}, defaultVerifiers, {}, enabledVerifiers); | ||
@@ -292,7 +298,5 @@ | ||
} else reject(new Error('Some Error Occured')); | ||
statusStream.removeListener('data', statusStreamHandler); | ||
}; | ||
statusStream.on('data', statusStreamHandler); | ||
(0, _embedUtils.handleStream)(statusStream, 'data', statusStreamHandler); | ||
} | ||
@@ -386,2 +390,33 @@ }); | ||
/** | ||
* Show alert for when popup is blocked | ||
*/ | ||
}, { | ||
key: "_createPopupBlockAlert", | ||
value: function _createPopupBlockAlert(preopenInstanceId) { | ||
var _this5 = this; | ||
var torusAlert = (0, _embedUtils.htmlToElement)('<div id="torusAlert" class="torus-alert">' + '<h1>Attention Required</h1>' + '<p>You have a pending action. Please click below to complete it</p></div>'); | ||
var successAlert = (0, _embedUtils.htmlToElement)('<div><button class="torus-alert-btn">Confirm</button></div>'); | ||
torusAlert.appendChild(successAlert); | ||
var bindOnLoad = function bindOnLoad() { | ||
successAlert.addEventListener('click', function () { | ||
_this5._handleWindow(preopenInstanceId, { | ||
target: '_blank', | ||
features: 'directories=0,titlebar=0,toolbar=0,status=0,location=0,menubar=0,height=660,width=500' | ||
}); | ||
torusAlert.remove(); | ||
}); | ||
}; | ||
var attachOnLoad = function attachOnLoad() { | ||
window.document.body.appendChild(torusAlert); | ||
}; | ||
(0, _embedUtils.runOnLoad)(attachOnLoad.bind(this)); | ||
(0, _embedUtils.runOnLoad)(bindOnLoad.bind(this)); | ||
} | ||
/** | ||
* Creates the widget | ||
@@ -393,3 +428,3 @@ */ | ||
value: function _createWidget(torusUrl) { | ||
var _this5 = this; | ||
var _this6 = this; | ||
@@ -478,21 +513,21 @@ var link = window.document.createElement('link'); | ||
var bindOnLoad = function bindOnLoad() { | ||
_this5.torusLogin.addEventListener('click', function () { | ||
_this5._showLoginPopup(false); | ||
_this6.torusLogin.addEventListener('click', function () { | ||
_this6._showLoginPopup(false); | ||
}); | ||
homeBtn.addEventListener('click', function () { | ||
_this5.showWallet(); | ||
_this6.showWallet(); | ||
_this5._toggleSpeedDial(); | ||
_this6._toggleSpeedDial(); | ||
}); | ||
transferBtn.addEventListener('click', function () { | ||
_this5.showWallet('transfer'); | ||
_this6.showWallet('transfer'); | ||
_this5._toggleSpeedDial(); | ||
_this6._toggleSpeedDial(); | ||
}); | ||
_this5.keyBtn.addEventListener('click', function () { | ||
var publicKey = (0, _embedUtils.htmlToElement)('<input type="text" value="' + _this5.ethereum.selectedAddress + '">'); | ||
_this6.keyBtn.addEventListener('click', function () { | ||
var publicKey = (0, _embedUtils.htmlToElement)('<input type="text" value="' + _this6.ethereum.selectedAddress + '">'); | ||
_this5.torusWidget.prepend(publicKey); | ||
_this6.torusWidget.prepend(publicKey); | ||
@@ -504,7 +539,7 @@ publicKey.select(); | ||
_this5.torusWidget.removeChild(publicKey); | ||
_this6.torusWidget.removeChild(publicKey); | ||
tooltipCopied.classList.add('active'); | ||
tooltipNote.classList.add('active'); | ||
var self = _this5; | ||
var self = _this6; | ||
setTimeout(function () { | ||
@@ -518,4 +553,4 @@ tooltipCopied.classList.remove('active'); | ||
_this5.torusMenuBtn.addEventListener('click', function () { | ||
_this5._toggleSpeedDial(); | ||
_this6.torusMenuBtn.addEventListener('click', function () { | ||
_this6._toggleSpeedDial(); | ||
}); // Login Modal Listeners | ||
@@ -525,5 +560,5 @@ | ||
modalContainer.querySelector('#close').addEventListener('click', function () { | ||
_this5.torusLoginModal.style.display = 'none'; | ||
if (_this5.modalCloseHandler) _this5.modalCloseHandler(); | ||
delete _this5.modalCloseHandler; | ||
_this6.torusLoginModal.style.display = 'none'; | ||
if (_this6.modalCloseHandler) _this6.modalCloseHandler(); | ||
delete _this6.modalCloseHandler; | ||
}); | ||
@@ -534,3 +569,3 @@ }; | ||
window.document.head.appendChild(link); | ||
window.document.body.appendChild(_this5.torusWidget); | ||
window.document.body.appendChild(_this6.torusWidget); | ||
}; | ||
@@ -621,3 +656,3 @@ | ||
value: function _setupWeb3() { | ||
var _this6 = this; | ||
var _this7 = this; | ||
@@ -649,3 +684,3 @@ _loglevel.default.info('setupWeb3 running'); // setup background connection | ||
var originalMethod = inpageProvider[m]; | ||
var self = _this6; | ||
var self = _this7; | ||
@@ -668,5 +703,5 @@ inpageProvider[m] = function (_ref4) { | ||
inpageProvider.enable = function () { | ||
_this6._checkThirdPartyCookies(); | ||
_this7._checkThirdPartyCookies(); | ||
_this6._showLoggingIn(); | ||
_this7._showLoggingIn(); | ||
@@ -676,4 +711,4 @@ return new Promise(function (resolve, reject) { | ||
// If user is already logged in, we assume they have given access to the website | ||
_this6.web3.eth.getAccounts(function (err, res) { | ||
var _this7 = this; | ||
_this7.web3.eth.getAccounts(function (err, res) { | ||
var _this8 = this; | ||
@@ -692,11 +727,11 @@ var self = this; | ||
var handleRehydration = function handleRehydration() { | ||
_this7.isLoggedIn = true; | ||
_this8.isLoggedIn = true; | ||
if (_this7.requestedVerifier !== '' && _this7.currentVerifier !== _this7.requestedVerifier) { | ||
var requestedVerifier = _this7.requestedVerifier; | ||
if (_this8.requestedVerifier !== '' && _this8.currentVerifier !== _this8.requestedVerifier) { | ||
var requestedVerifier = _this8.requestedVerifier; | ||
_this7.logout().then(function (_) { | ||
_this7.requestedVerifier = requestedVerifier; | ||
_this8.logout().then(function (_) { | ||
_this8.requestedVerifier = requestedVerifier; | ||
_this7._showLoginPopup(true, resolve, reject); | ||
_this8._showLoginPopup(true, resolve, reject); | ||
}).catch(function (err) { | ||
@@ -721,3 +756,3 @@ return reject(err); | ||
} | ||
}.bind(_this6)); | ||
}.bind(_this7)); | ||
}); | ||
@@ -738,3 +773,9 @@ }; // Work around for web3@1.0 deleting the bound `sendAsync` but not the unbound | ||
communicationMux.setMaxListeners(20); | ||
this.communicationMux = communicationMux; // Show torus button if wallet has been hydrated/detected | ||
this.communicationMux = communicationMux; | ||
var windowStream = communicationMux.getStream('window'); | ||
windowStream.on('data', function (chunk) { | ||
if (chunk.name === 'create_window') { | ||
_this7._createPopupBlockAlert(chunk.data.preopenInstanceId); | ||
} | ||
}); // Show torus button if wallet has been hydrated/detected | ||
@@ -745,18 +786,18 @@ var statusStream = communicationMux.getStream('status'); | ||
if (status.rehydrate && status.loggedIn) { | ||
_this6.isRehydrated = status.rehydrate; | ||
_this6.currentVerifier = status.verifier; | ||
_this7.isRehydrated = status.rehydrate; | ||
_this7.currentVerifier = status.verifier; | ||
if (_this6.isRehydratedCallback) { | ||
_this6.isRehydratedCallback(); | ||
if (_this7.isRehydratedCallback) { | ||
_this7.isRehydratedCallback(); | ||
delete _this6.isRehydratedCallback; | ||
delete _this7.isRehydratedCallback; | ||
} | ||
} // normal login | ||
else if (status.loggedIn) { | ||
_this6.isLoggedIn = status.loggedIn; | ||
_this6.currentVerifier = status.verifier; | ||
_this7.isLoggedIn = status.loggedIn; | ||
_this7.currentVerifier = status.verifier; | ||
_this6._showLoggedIn(); | ||
_this7._showLoggedIn(); | ||
} // logout | ||
else _this6._showLoggedOut(); | ||
else _this7._showLoggedOut(); | ||
}); // if (typeof window.web3 !== 'undefined') { | ||
@@ -794,3 +835,3 @@ // console.log(`Torus detected another web3. | ||
value: function _showLoginPopup(calledFromEmbed, resolve, reject) { | ||
var _this8 = this; | ||
var _this9 = this; | ||
@@ -801,3 +842,3 @@ this._showLoggingIn(); | ||
this.modalCloseHandler = function () { | ||
_this8._showLoggedOut(); | ||
_this9._showLoggedOut(); | ||
@@ -807,51 +848,13 @@ if (reject) reject(new Error('Modal has been closed')); | ||
var googleHandler = function googleHandler() { | ||
_this8.requestedVerifier = GOOGLE; | ||
var _loginHandler = function _loginHandler(verifier) { | ||
_this9.requestedVerifier = verifier; | ||
_this8.googleLogin.removeEventListener('click', googleHandler); | ||
_this8._showLoginPopup(calledFromEmbed, resolve, reject); | ||
_this9._showLoginPopup(calledFromEmbed, resolve, reject); | ||
}; | ||
this.googleLogin.addEventListener('click', googleHandler); | ||
var facebookHandler = function facebookHandler() { | ||
_this8.requestedVerifier = FACEBOOK; | ||
_this8.facebookLogin.removeEventListener('click', facebookHandler); | ||
_this8._showLoginPopup(calledFromEmbed, resolve, reject); | ||
}; | ||
this.facebookLogin.addEventListener('click', facebookHandler); | ||
var twitchHandler = function twitchHandler() { | ||
_this8.requestedVerifier = TWITCH; | ||
_this8.twitchLogin.removeEventListener('click', twitchHandler); | ||
_this8._showLoginPopup(calledFromEmbed, resolve, reject); | ||
}; | ||
this.twitchLogin.addEventListener('click', twitchHandler); | ||
var redditHandler = function redditHandler() { | ||
_this8.requestedVerifier = REDDIT; | ||
_this8.redditLogin.removeEventListener('click', redditHandler); | ||
_this8._showLoginPopup(calledFromEmbed, resolve, reject); | ||
}; | ||
this.redditLogin.addEventListener('click', redditHandler); | ||
var discordHandler = function discordHandler() { | ||
_this8.requestedVerifier = DISCORD; | ||
_this8.discordLogin.removeEventListener('click', discordHandler); | ||
_this8._showLoginPopup(calledFromEmbed, resolve, reject); | ||
}; | ||
this.discordLogin.addEventListener('click', discordHandler); | ||
Object.keys(this.enabledVerifiers).forEach(function (verifier) { | ||
if (_this9.enabledVerifiers[verifier]) { | ||
(0, _embedUtils.handleEvent)(_this9["".concat(verifier, "Login")], 'click', _loginHandler, [verifier]); | ||
} | ||
}); | ||
} else { | ||
@@ -861,3 +864,3 @@ var oauthStream = this.communicationMux.getStream('oauth'); | ||
var handler = function handler(data) { | ||
var loginHandler = function loginHandler(data) { | ||
var err = data.err, | ||
@@ -878,7 +881,9 @@ selectedAddress = data.selectedAddress; | ||
} | ||
oauthStream.removeListener('data', handler); | ||
}; | ||
oauthStream.on('data', handler); | ||
(0, _embedUtils.handleStream)(oauthStream, 'data', loginHandler); | ||
var preopenInstanceId = (0, _randomId.default)(); | ||
this._handleWindow(preopenInstanceId); | ||
oauthStream.write({ | ||
@@ -888,3 +893,4 @@ name: 'oauth', | ||
calledFromEmbed: calledFromEmbed, | ||
verifier: this.requestedVerifier | ||
verifier: this.requestedVerifier, | ||
preopenInstanceId: preopenInstanceId | ||
} | ||
@@ -897,3 +903,3 @@ }); | ||
value: function setProvider() { | ||
var _this9 = this; | ||
var _this10 = this; | ||
@@ -909,14 +915,12 @@ var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
return new Promise(function (resolve, reject) { | ||
var providerChangeStream = _this9.communicationMux.getStream('show_provider_change'); | ||
var providerChangeStream = _this10.communicationMux.getStream('provider_change'); | ||
var providerChangeSuccess = _this9.communicationMux.getStream('provider_change_status'); | ||
var handler = function handler(chunk) { | ||
var _chunk$data = chunk.data, | ||
err = _chunk$data.err, | ||
success = _chunk$data.success; | ||
var handler = function handler(ev) { | ||
var _ev$data = ev.data, | ||
err = _ev$data.err, | ||
success = _ev$data.success; | ||
_loglevel.default.info(chunk); | ||
if (err) { | ||
_loglevel.default.error(err); | ||
reject(err); | ||
@@ -926,8 +930,13 @@ } else if (success) { | ||
} else reject(new Error('some error occured')); | ||
providerChangeSuccess.removeListener('data', handler); | ||
}; | ||
providerChangeSuccess.on('data', handler); | ||
if (_config.default.networkList.includes(host)) providerChangeStream.write({ | ||
(0, _embedUtils.handleStream)(providerChangeStream, 'data', handler); | ||
var preopenInstanceId = (0, _randomId.default)(); | ||
_this10._handleWindow(preopenInstanceId, { | ||
target: '_blank', | ||
features: 'directories=0,titlebar=0,toolbar=0,status=0,location=0,menubar=0,height=600,width=500' | ||
}); | ||
providerChangeStream.write({ | ||
name: 'show_provider_change', | ||
@@ -940,15 +949,6 @@ data: { | ||
}, | ||
type: _config.default.networkList.includes(host) ? undefined : 'rpc', | ||
preopenInstanceId: preopenInstanceId, | ||
override: false | ||
} | ||
});else providerChangeStream.write({ | ||
name: 'show_provider_change', | ||
data: { | ||
network: { | ||
host: host, | ||
chainId: chainId, | ||
networkName: networkName | ||
}, | ||
type: 'rpc' | ||
}, | ||
override: false | ||
}); | ||
@@ -960,3 +960,3 @@ }); | ||
value: function _setProvider() { | ||
var _this10 = this; | ||
var _this11 = this; | ||
@@ -972,15 +972,13 @@ var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
return new Promise(function (resolve, reject) { | ||
if (!_this10.isInitalized) { | ||
var providerChangeStream = _this10.communicationMux.getStream('show_provider_change'); | ||
if (!_this11.isInitalized) { | ||
var providerChangeStream = _this11.communicationMux.getStream('provider_change'); | ||
var providerChangeSuccess = _this10.communicationMux.getStream('provider_change_status'); | ||
var handler = function handler(ev) { | ||
var _ev$data2 = ev.data, | ||
err = _ev$data2.err, | ||
success = _ev$data2.success; | ||
_loglevel.default.info(ev); | ||
var _ev$data = ev.data, | ||
err = _ev$data.err, | ||
success = _ev$data.success; | ||
if (err) { | ||
_loglevel.default.error(err); | ||
reject(err); | ||
@@ -990,8 +988,6 @@ } else if (success) { | ||
} else reject(new Error('some error occured')); | ||
providerChangeSuccess.removeListener('data', handler); | ||
}; | ||
providerChangeSuccess.on('data', handler); | ||
if (_config.default.networkList.includes(host)) providerChangeStream.write({ | ||
(0, _embedUtils.handleStream)(providerChangeStream, 'data', handler); | ||
providerChangeStream.write({ | ||
name: 'show_provider_change', | ||
@@ -1004,15 +1000,5 @@ data: { | ||
}, | ||
type: _config.default.networkList.includes(host) ? undefined : 'rpc', | ||
override: true | ||
} | ||
});else providerChangeStream.write({ | ||
name: 'show_provider_change', | ||
data: { | ||
network: { | ||
host: host, | ||
chainId: chainId, | ||
networkName: networkName | ||
}, | ||
type: 'rpc', | ||
override: true | ||
} | ||
}); | ||
@@ -1024,3 +1010,2 @@ } else reject(new Error('Already initialized')); | ||
* Shows the wallet popup | ||
* @param {boolean} calledFromEmbed if called from dapp context | ||
* @param {string} path the route to open | ||
@@ -1032,2 +1017,4 @@ */ | ||
value: function showWallet(path) { | ||
var _this12 = this; | ||
var showWalletStream = this.communicationMux.getStream('show_wallet'); | ||
@@ -1041,2 +1028,15 @@ var finalPath = path ? "/".concat(path) : ''; | ||
}); | ||
var showWalletHandler = function showWalletHandler(chunk) { | ||
if (chunk.name === 'show_wallet_instance') { | ||
var instanceId = chunk.data.instanceId; | ||
var finalUrl = "".concat(_this12.torusUrl, "/wallet").concat(finalPath, "?integrity=true&instanceId=").concat(instanceId); | ||
var walletWindow = new _PopupHandler.default({ | ||
url: finalUrl | ||
}); | ||
walletWindow.open(); | ||
} | ||
}; | ||
(0, _embedUtils.handleStream)(showWalletStream, 'data', showWalletHandler); | ||
} | ||
@@ -1111,31 +1111,103 @@ }, { | ||
value: function getUserInfo(message) { | ||
var _this11 = this; | ||
var _this13 = this; | ||
return new Promise(function (resolve, reject) { | ||
if (_this11.isLoggedIn) { | ||
var userInfoStream = _this11.communicationMux.getStream('user_info'); | ||
if (_this13.isLoggedIn) { | ||
var userInfoAccessStream = _this13.communicationMux.getStream('user_info_access'); | ||
userInfoStream.write({ | ||
name: 'user_info_request', | ||
data: { | ||
message: message | ||
} | ||
userInfoAccessStream.write({ | ||
name: 'user_info_access_request' | ||
}); | ||
var userInfoHandler = function userInfoHandler(chunk) { | ||
if (chunk.name === 'user_info_response') { | ||
if (chunk.data.approved) { | ||
resolve(chunk.data.payload); | ||
} else { | ||
var userInfoAccessHandler = function userInfoAccessHandler(chunk) { | ||
var name = chunk.name, | ||
_chunk$data2 = chunk.data, | ||
approved = _chunk$data2.approved, | ||
payload = _chunk$data2.payload, | ||
rejected = _chunk$data2.rejected, | ||
newRequest = _chunk$data2.newRequest; | ||
if (name === 'user_info_access_response') { | ||
if (approved) { | ||
resolve(payload); | ||
} else if (rejected) { | ||
reject(new Error('User rejected the request')); | ||
} else if (newRequest) { | ||
var userInfoStream = _this13.communicationMux.getStream('user_info'); | ||
var userInfoHandler = function userInfoHandler(chunk) { | ||
if (chunk.name === 'user_info_response') { | ||
if (chunk.data.approved) { | ||
resolve(chunk.data.payload); | ||
} else { | ||
reject(new Error('User rejected the request')); | ||
} | ||
} | ||
}; | ||
(0, _embedUtils.handleStream)(userInfoStream, 'data', userInfoHandler); | ||
var preopenInstanceId = (0, _randomId.default)(); | ||
_this13._handleWindow(preopenInstanceId, { | ||
target: '_blank', | ||
features: 'directories=0,titlebar=0,toolbar=0,status=0,location=0,menubar=0,height=600,width=500' | ||
}); | ||
userInfoStream.write({ | ||
name: 'user_info_request', | ||
data: { | ||
message: message, | ||
preopenInstanceId: preopenInstanceId | ||
} | ||
}); | ||
} | ||
} | ||
userInfoStream.removeListener('data', userInfoHandler); | ||
}; | ||
userInfoStream.on('data', userInfoHandler); | ||
(0, _embedUtils.handleStream)(userInfoAccessStream, 'data', userInfoAccessHandler); | ||
} else reject(new Error('User has not logged in yet')); | ||
}); | ||
} | ||
}, { | ||
key: "_handleWindow", | ||
value: function _handleWindow(preopenInstanceId) { | ||
var _ref8 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
target = _ref8.target, | ||
features = _ref8.features; | ||
var windowStream = this.communicationMux.getStream('window'); | ||
var finalUrl = this.torusUrl + "/redirect?preopenInstanceId=".concat(preopenInstanceId); | ||
var handledWindow = new _PopupHandler.default({ | ||
url: finalUrl, | ||
target: target, | ||
features: features | ||
}); | ||
handledWindow.open(); | ||
windowStream.write({ | ||
name: 'opened_window', | ||
data: { | ||
preopenInstanceId: preopenInstanceId | ||
} | ||
}); | ||
var closeHandler = function closeHandler(_ref9) { | ||
var receivedId = _ref9.preopenInstanceId, | ||
close = _ref9.close; | ||
if (receivedId === preopenInstanceId && close) { | ||
handledWindow.close(); | ||
windowStream.removeListener('data', closeHandler); | ||
} | ||
}; | ||
windowStream.on('data', closeHandler); | ||
handledWindow.once('close', function () { | ||
windowStream.write({ | ||
data: { | ||
preopenInstanceId: preopenInstanceId, | ||
closed: true | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
@@ -1145,3 +1217,3 @@ * Exposes the topup api of torus | ||
* If no params are provided, it defaults to { fiatValue = MIN_FOR_PROVIDER; selectedCurrency? = 'USD'; selectedCryptoCurrency? = 'ETH'; } | ||
* @param {Enum} provider Supported options are simplex, moonpay, wyre and coindirect | ||
* @param {Enum} provider Supported options are moonpay, wyre and coindirect | ||
* @param {PaymentParams} params PaymentParams is { fiatValue?: Number; selectedCurrency?: string; selectedCryptoCurrency?: string; } | ||
@@ -1154,16 +1226,8 @@ * @returns {Promise<boolean>} boolean indicates whether user has successfully completed the topup flow | ||
value: function initiateTopup(provider, params) { | ||
var _this12 = this; | ||
var _this14 = this; | ||
return new Promise(function (resolve, reject) { | ||
if (_this12.isLoggedIn) { | ||
var topupStream = _this12.communicationMux.getStream('topup'); | ||
if (_this14.isLoggedIn) { | ||
var topupStream = _this14.communicationMux.getStream('topup'); | ||
topupStream.write({ | ||
name: 'topup_request', | ||
data: { | ||
provider: provider, | ||
params: params | ||
} | ||
}); | ||
var topupHandler = function topupHandler(chunk) { | ||
@@ -1177,7 +1241,17 @@ if (chunk.name === 'topup_response') { | ||
} | ||
topupStream.removeListener('data', topupHandler); | ||
}; | ||
topupStream.on('data', topupHandler); | ||
(0, _embedUtils.handleStream)(topupStream, 'data', topupHandler); | ||
var preopenInstanceId = (0, _randomId.default)(); | ||
_this14._handleWindow(preopenInstanceId); | ||
topupStream.write({ | ||
name: 'topup_request', | ||
data: { | ||
provider: provider, | ||
params: params, | ||
preopenInstanceId: preopenInstanceId | ||
} | ||
}); | ||
} else reject(new Error('User has not logged in yet')); | ||
@@ -1184,0 +1258,0 @@ }); |
@@ -6,4 +6,6 @@ "use strict"; | ||
}); | ||
exports.transformEthAddress = exports.htmlToElement = exports.runOnComplete = exports.runOnLoad = void 0; | ||
exports.handleStream = exports.handleEvent = exports.transformEthAddress = exports.htmlToElement = exports.runOnComplete = exports.runOnLoad = void 0; | ||
var _this = void 0; | ||
var runOnLoad = function runOnLoad(fn) { | ||
@@ -53,2 +55,24 @@ if (window.document.body != null) { | ||
exports.transformEthAddress = transformEthAddress; | ||
exports.transformEthAddress = transformEthAddress; | ||
var handleEvent = function handleEvent(handle, eventName, handler, handlerArgs) { | ||
var handlerWrapper = function handlerWrapper() { | ||
handler.apply(_this, handlerArgs); | ||
handle.removeEventListener(eventName, handlerWrapper); | ||
}; | ||
handle.addEventListener(eventName, handlerWrapper); | ||
}; | ||
exports.handleEvent = handleEvent; | ||
var handleStream = function handleStream(handle, eventName, handler) { | ||
var handlerWrapper = function handlerWrapper(chunk) { | ||
handler(chunk); | ||
handle.removeListener(eventName, handlerWrapper); | ||
}; | ||
handle.on(eventName, handlerWrapper); | ||
}; | ||
exports.handleStream = handleStream; |
{ | ||
"name": "@toruslabs/torus-embed", | ||
"version": "0.2.9", | ||
"version": "0.2.10", | ||
"description": "Embed script for Torus", | ||
@@ -34,2 +34,3 @@ "directories": { | ||
"pump": "^3.0.0", | ||
"random-id": "^1.0.3", | ||
"readable-stream": "^3.4.0", | ||
@@ -41,6 +42,6 @@ "sri-toolbox": "^0.2.0", | ||
"devDependencies": { | ||
"@babel/cli": "^7.7.0", | ||
"@babel/core": "^7.7.2", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.6.2", | ||
"@babel/preset-env": "^7.7.1", | ||
"@babel/cli": "^7.7.5", | ||
"@babel/core": "^7.7.5", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.7.4", | ||
"@babel/preset-env": "^7.7.6", | ||
"assert": "^2.0.0", | ||
@@ -51,9 +52,9 @@ "browserify": "^16.5.0", | ||
"envify": "^4.1.0", | ||
"eslint": "^6.7.0", | ||
"eslint": "^6.7.2", | ||
"eslint-config-airbnb-base": "^14.0.0", | ||
"eslint-config-prettier": "^6.7.0", | ||
"eslint-config-standard": "^14.1.0", | ||
"eslint-plugin-flowtype": "^4.4.1", | ||
"eslint-plugin-flowtype": "^4.5.2", | ||
"eslint-plugin-html": "^6.0.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-import": "^2.19.1", | ||
"eslint-plugin-mocha": "^6.2.2", | ||
@@ -66,3 +67,3 @@ "eslint-plugin-node": "^10.0.0", | ||
"husky": "^3.1.0", | ||
"lint-staged": "^9.4.3", | ||
"lint-staged": "^9.5.0", | ||
"mocha": "^6.2.2", | ||
@@ -69,0 +70,0 @@ "mocha-eslint": "^6.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82689
18
1701
12
+ Addedrandom-id@^1.0.3
+ Addedrandom-id@1.0.4(transitive)