@waves.exchange/provider-web 1.1.4 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -144,9 +144,10 @@ class Transport {
144
144
  } : action;
145
145
  }
146
146
  }
147
- const _TransportIframe = class extends Transport {
147
+ class TransportIframe extends Transport {
148
148
  constructor(url, queueLength) {
149
149
  super(queueLength);
150
+ __publicField(this, "_timer", null);
150
151
  __publicField(this, "_url");
151
152
  __publicField(this, "_iframe");
152
153
  __publicField(this, "_bus");
@@ -227,10 +228,10 @@ const _TransportIframe = class extends Transport {
227
228
  zIndex: "99999999"
228
229
  };
229
230
  this._applyStyle(shownStyles);
230
- if (_TransportIframe._timer != null) {
231
- clearTimeout(_TransportIframe._timer);
231
+ if (this._timer != null) {
232
+ clearTimeout(this._timer);
232
233
  }
233
- _TransportIframe._timer = setTimeout(() => {
234
+ this._timer = setTimeout(() => {
234
235
  this._applyStyle({ opacity: "1" });
235
236
  }, 0);
236
237
  }
@@ -239,10 +240,10 @@ const _TransportIframe = class extends Transport {
239
240
  opacity: "0"
240
241
  };
241
242
  this._applyStyle(hiddenStyle);
242
- if (_TransportIframe._timer != null) {
243
- clearTimeout(_TransportIframe._timer);
243
+ if (this._timer != null) {
244
+ clearTimeout(this._timer);
244
245
  }
245
- _TransportIframe._timer = setTimeout(() => {
246
+ this._timer = setTimeout(() => {
246
247
  this._applyStyle({
247
248
  width: "10px",
248
249
  height: "10px",
@@ -343,9 +344,17 @@ const _TransportIframe = class extends Transport {
343
344
  });
344
345
  });
345
346
  }
346
- };
347
- let TransportIframe = _TransportIframe;
348
- __publicField(TransportIframe, "_timer", null);
347
+ }
348
+ function isBrave() {
349
+ var _a;
350
+ return !!((_a = navigator.brave) == null ? void 0 : _a.isBrave);
351
+ }
352
+ function isSafari() {
353
+ const userAgent = navigator.userAgent.toLowerCase();
354
+ const isSafariUA = userAgent.includes("safari") && !userAgent.includes("chrome");
355
+ const iOS = navigator.platform != null && /iPad|iPhone|iPod/.test(navigator.platform);
356
+ return iOS || isSafariUA;
357
+ }
349
358
  class ProviderWeb {
350
359
  constructor(clientUrl, logs) {
351
360
  __publicField(this, "user", null);
@@ -386,9 +395,11 @@ class ProviderWeb {
386
395
  return Promise.resolve(this.user);
387
396
  }
388
397
  const iframe = this._transport.get();
389
- const win = (_a = iframe.contentWindow) == null ? void 0 : _a.open(this._clientUrl);
390
- if (!win) {
391
- throw new Error("Window was blocked");
398
+ if (isSafari() || isBrave()) {
399
+ const win = (_a = iframe.contentWindow) == null ? void 0 : _a.open(this._clientUrl);
400
+ if (!win) {
401
+ throw new Error("Window was blocked");
402
+ }
392
403
  }
393
404
  iframe.src = this._clientUrl;
394
405
  return this._transport.dialog((bus) => bus.request("login").then((userData) => {
@@ -141,9 +141,10 @@ class Transport {
141
141
  } : action;
142
142
  }
143
143
  }
144
- const _TransportIframe = class extends Transport {
144
+ class TransportIframe extends Transport {
145
145
  constructor(url, queueLength) {
146
146
  super(queueLength);
147
+ __publicField(this, "_timer", null);
147
148
  __publicField(this, "_url");
148
149
  __publicField(this, "_iframe");
149
150
  __publicField(this, "_bus");
@@ -224,10 +225,10 @@ const _TransportIframe = class extends Transport {
224
225
  zIndex: "99999999"
225
226
  };
226
227
  this._applyStyle(shownStyles);
227
- if (_TransportIframe._timer != null) {
228
- clearTimeout(_TransportIframe._timer);
228
+ if (this._timer != null) {
229
+ clearTimeout(this._timer);
229
230
  }
230
- _TransportIframe._timer = setTimeout(() => {
231
+ this._timer = setTimeout(() => {
231
232
  this._applyStyle({ opacity: "1" });
232
233
  }, 0);
233
234
  }
@@ -236,10 +237,10 @@ const _TransportIframe = class extends Transport {
236
237
  opacity: "0"
237
238
  };
238
239
  this._applyStyle(hiddenStyle);
239
- if (_TransportIframe._timer != null) {
240
- clearTimeout(_TransportIframe._timer);
240
+ if (this._timer != null) {
241
+ clearTimeout(this._timer);
241
242
  }
242
- _TransportIframe._timer = setTimeout(() => {
243
+ this._timer = setTimeout(() => {
243
244
  this._applyStyle({
244
245
  width: "10px",
245
246
  height: "10px",
@@ -340,9 +341,17 @@ const _TransportIframe = class extends Transport {
340
341
  });
341
342
  });
342
343
  }
343
- };
344
- let TransportIframe = _TransportIframe;
345
- __publicField(TransportIframe, "_timer", null);
344
+ }
345
+ function isBrave() {
346
+ var _a;
347
+ return !!((_a = navigator.brave) == null ? void 0 : _a.isBrave);
348
+ }
349
+ function isSafari() {
350
+ const userAgent = navigator.userAgent.toLowerCase();
351
+ const isSafariUA = userAgent.includes("safari") && !userAgent.includes("chrome");
352
+ const iOS = navigator.platform != null && /iPad|iPhone|iPod/.test(navigator.platform);
353
+ return iOS || isSafariUA;
354
+ }
346
355
  class ProviderWeb {
347
356
  constructor(clientUrl, logs) {
348
357
  __publicField(this, "user", null);
@@ -383,9 +392,11 @@ class ProviderWeb {
383
392
  return Promise.resolve(this.user);
384
393
  }
385
394
  const iframe = this._transport.get();
386
- const win = (_a = iframe.contentWindow) == null ? void 0 : _a.open(this._clientUrl);
387
- if (!win) {
388
- throw new Error("Window was blocked");
395
+ if (isSafari() || isBrave()) {
396
+ const win = (_a = iframe.contentWindow) == null ? void 0 : _a.open(this._clientUrl);
397
+ if (!win) {
398
+ throw new Error("Window was blocked");
399
+ }
389
400
  }
390
401
  iframe.src = this._clientUrl;
391
402
  return this._transport.dialog((bus) => bus.request("login").then((userData) => {
@@ -1 +1 @@
1
- var ut=Object.defineProperty,lt=Object.defineProperties;var ht=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var dt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable;var k=(_,u,p)=>u in _?ut(_,u,{enumerable:!0,configurable:!0,writable:!0,value:p}):_[u]=p,V=(_,u)=>{for(var p in u||(u={}))dt.call(u,p)&&k(_,p,u[p]);if(U)for(var p of U(u))ft.call(u,p)&&k(_,p,u[p]);return _},z=(_,u)=>lt(_,ht(u));var v=(_,u,p)=>(k(_,typeof u!="symbol"?u+"":u,p),p);(function(_,u){typeof exports=="object"&&typeof module!="undefined"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(_=typeof globalThis!="undefined"?globalThis:_||self,u(_.providerWeb={}))})(this,function(_){"use strict";var u=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},p={},M={},C={},E={};Object.defineProperty(E,"__esModule",{value:!0});function F(o){return Object.keys(o)}E.keys=F;var G=Math.floor(Date.now()*Math.random()),N=0;function $(o){return o+"-"+G+"-"+N++}E.uniqueId=$;function Y(o){return Array.isArray(o)?o:[o]}E.toArray=Y;function Q(){for(var o=[],t=0;t<arguments.length;t++)o[t]=arguments[t];return function(n){return o.reduce(function(r,e){return e(r)},n)}}E.pipe=Q;var j={},x={};(function(o){Object.defineProperty(o,"__esModule",{value:!0}),function(t){(function(n){n.LOG_LEVEL={PRODUCTION:0,ERRORS:1,VERBOSE:2},n.logLevel=n.LOG_LEVEL.PRODUCTION,n.methodsData={log:{save:!1,logLevel:n.LOG_LEVEL.VERBOSE},info:{save:!1,logLevel:n.LOG_LEVEL.VERBOSE},warn:{save:!1,logLevel:n.LOG_LEVEL.VERBOSE},error:{save:!0,logLevel:n.LOG_LEVEL.ERRORS}}})(t.console||(t.console={}))}(o.config||(o.config={}))})(x);var H=u&&u.__assign||function(){return H=Object.assign||function(o){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(o[e]=t[e])}return o},H.apply(this,arguments)};Object.defineProperty(j,"__esModule",{value:!0});var b=x,K=E,B=function(o){return o.console}(typeof self!="undefined"?self:u),O=Object.create(null);function J(o){O[o]||(O[o]=[])}function X(o,t){O[o].push(t)}function Z(){return K.keys(b.config.console.methodsData).reduce(function(o,t){return o[t]=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];b.config.console.logLevel<b.config.console.methodsData[t].logLevel?b.config.console.methodsData[t].save&&(J(t),X(t,n)):B[t].apply(B,n)},o},Object.create(null))}j.console=H({},Z(),{getSavedMessages:function(o){return O[o]||[]}});var I={};Object.defineProperty(I,"__esModule",{value:!0});var tt=function(){function o(t){this.size=0,this.hash=Object.create(null),t&&t.forEach(this.add,this)}return o.prototype.add=function(t){return this.hash[t]=!0,this.size=Object.keys(this.hash).length,this},o.prototype.has=function(t){return t in this.hash},o.prototype.toArray=function(){return Object.keys(this.hash)},o}();I.UniqPrimitiveCollection=tt,function(o){function t(n){for(var r in n)o.hasOwnProperty(r)||(o[r]=n[r])}Object.defineProperty(o,"__esModule",{value:!0}),t(E),t(j),t(I)}(C),function(o){Object.defineProperty(o,"__esModule",{value:!0});var t=C;(function(r){r[r.Event=0]="Event",r[r.Action=1]="Action",r[r.Response=2]="Response"})(o.EventType||(o.EventType={})),function(r){r[r.Success=0]="Success",r[r.Error=1]="Error"}(o.ResponseStatus||(o.ResponseStatus={}));var n=function(){function r(e,i){var s=this;this.id=t.uniqueId("bus"),this._timeout=i||5e3,this._adapter=e,this._adapter.addListener(function(a){return s._onMessage(a)}),this._eventHandlers=Object.create(null),this._activeRequestHash=Object.create(null),this._requestHandlers=Object.create(null),t.console.info('Create Bus with id "'+this.id+'"')}return r.prototype.dispatchEvent=function(e,i){return this._adapter.send(r._createEvent(e,i)),t.console.info('Dispatch event "'+e+'"',i),this},r.prototype.request=function(e,i,s){var a=this;return new Promise(function(c,l){var h=t.uniqueId(a.id+"-action"),d=s||a._timeout,f;(s||a._timeout)!==-1&&(f=setTimeout(function(){delete a._activeRequestHash[h];var g=new Error('Timeout error for request with name "'+e+'" and timeout '+d+"!");t.console.error(g),l(g)},d));var y=function(){f&&clearTimeout(f)};a._activeRequestHash[h]={reject:function(g){y(),t.console.error('Error request with name "'+e+'"',g),l(g)},resolve:function(g){y(),t.console.info('Request with name "'+e+'" success resolved!',g),c(g)}},a._adapter.send({id:h,type:1,name:e,data:i}),t.console.info('Request with name "'+e+'"',i)})},r.prototype.on=function(e,i,s){return this._addEventHandler(e,i,s,!1)},r.prototype.once=function(e,i,s){return this._addEventHandler(e,i,s,!0)},r.prototype.off=function(e,i){var s=this;return e?this._eventHandlers[e]?i?(this._eventHandlers[e]=this._eventHandlers[e].filter(function(a){return a.handler!==i}),this._eventHandlers[e].length||delete this._eventHandlers[e],this):(this._eventHandlers[e].slice().forEach(function(a){s.off(e,a.handler)}),this):this:(Object.keys(this._eventHandlers).forEach(function(a){return s.off(a,i)}),this)},r.prototype.registerRequestHandler=function(e,i){if(this._requestHandlers[e])throw new Error("Duplicate request handler!");return this._requestHandlers[e]=i,this},r.prototype.unregisterHandler=function(e){return this._requestHandlers[e]&&delete this._requestHandlers[e],this},r.prototype.changeAdapter=function(e){var i=this,s=new r(e,this._timeout);return Object.keys(this._eventHandlers).forEach(function(a){i._eventHandlers[a].forEach(function(c){c.once?s.once(a,c.handler,c.context):s.on(a,c.handler,c.context)})}),Object.keys(this._requestHandlers).forEach(function(a){s.registerRequestHandler(a,i._requestHandlers[a])}),s},r.prototype.destroy=function(){t.console.info("Destroy Bus"),this.off(),this._adapter.destroy()},r.prototype._addEventHandler=function(e,i,s,a){return this._eventHandlers[e]||(this._eventHandlers[e]=[]),this._eventHandlers[e].push({handler:i,once:a,context:s}),this},r.prototype._onMessage=function(e){switch(e.type){case 0:t.console.info('Has event with name "'+String(e.name)+'"',e.data),this._fireEvent(String(e.name),e.data);break;case 1:t.console.info('Start action with id "'+e.id+'" and name "'+String(e.name)+'"',e.data),this._createResponse(e);break;case 2:t.console.info('Start response with name "'+e.id+'" and status "'+e.status+'"',e.content),this._fireEndAction(e);break}},r.prototype._createResponse=function(e){var i=this,s=function(c){t.console.error(c),i._adapter.send({id:e.id,type:2,status:1,content:String(c)})};if(!this._requestHandlers[String(e.name)]){s(new Error('Has no handler for "'+String(e.name)+'" action!'));return}try{var a=this._requestHandlers[String(e.name)](e.data);r._isPromise(a)?a.then(function(c){i._adapter.send({id:e.id,type:2,status:0,content:c})},s):this._adapter.send({id:e.id,type:2,status:0,content:a})}catch(c){s(c)}},r.prototype._fireEndAction=function(e){if(this._activeRequestHash[e.id]){switch(e.status){case 1:this._activeRequestHash[e.id].reject(e.content);break;case 0:this._activeRequestHash[e.id].resolve(e.content);break}delete this._activeRequestHash[e.id]}},r.prototype._fireEvent=function(e,i){!this._eventHandlers[e]||(this._eventHandlers[e]=this._eventHandlers[e].slice().filter(function(s){try{s.handler.call(s.context,i)}catch(a){t.console.warn(a)}return!s.once}),this._eventHandlers[e].length||delete this._eventHandlers[e])},r._createEvent=function(e,i){return{type:0,name:e,data:i}},r._isPromise=function(e){return e&&e.then&&typeof e.then=="function"},r}();o.Bus=n}(M);var P={};Object.defineProperty(P,"__esModule",{value:!0});var et=function(){function o(){}return o}();P.Adapter=et;var q={},A={},R={exports:{}};(function(o,t){(function(n,r){o.exports=r()})(u,function(){return(()=>{var n={660:(e,i)=>{i.__esModule=!0,i.EventEmitter=void 0;var s=function(){function a(c){this._events=Object.create(null),this.catchHandler=c||function(){}}return a.prototype.hasListeners=function(c){return!(!this._events[c]||!this._events[c].length)},a.prototype.getActiveEvents=function(){var c=this;return Object.keys(this._events).filter(function(l){return c.hasListeners(l)})},a.prototype.trigger=function(c,l){var h=this;this._events[c]&&(this._events[c].slice().forEach(function(d){try{d.handler.call(d.context,l)}catch(f){h.catchHandler(f)}d.once&&h.off(c,d.handler)}),this._events[c].length||delete this._events[c])},a.prototype.on=function(c,l,h){this._on(c,l,h,!1)},a.prototype.once=function(c,l,h){this._on(c,l,h,!0)},a.prototype.off=function(c,l){var h=this,d=typeof c=="string"?c:null,f=typeof l=="function"?l:typeof c=="function"?c:null;if(d)if(f){if(d in this._events){var y=this._events[d].map(function(g){return g.handler}).indexOf(f);this._events[d].splice(y,1)}}else delete this._events[d];else Object.keys(this._events).forEach(function(g){h.off(g,f)})},a.prototype._on=function(c,l,h,d){this._events[c]||(this._events[c]=[]),this._events[c].push({handler:l,context:h,once:d})},a}();i.EventEmitter=s},607:function(e,i,s){var a=this&&this.__createBinding||(Object.create?function(h,d,f,y){y===void 0&&(y=f),Object.defineProperty(h,y,{enumerable:!0,get:function(){return d[f]}})}:function(h,d,f,y){y===void 0&&(y=f),h[y]=d[f]}),c=this&&this.__exportStar||function(h,d){for(var f in h)f==="default"||Object.prototype.hasOwnProperty.call(d,f)||a(d,h,f)};i.__esModule=!0;var l=s(660);c(s(660),i),i.default=l.EventEmitter}},r={};return function e(i){if(r[i])return r[i].exports;var s=r[i]={exports:{}};return n[i].call(s.exports,s,s.exports,e),s.exports}(607)})()})})(R),function(o){var t=u&&u.__extends||function(){var e=function(i,s){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,c){a.__proto__=c}||function(a,c){for(var l in c)c.hasOwnProperty(l)&&(a[l]=c[l])},e(i,s)};return function(i,s){e(i,s);function a(){this.constructor=i}i.prototype=s===null?Object.create(s):(a.prototype=s.prototype,new a)}}();Object.defineProperty(o,"__esModule",{value:!0});var n=R.exports,r=function(e){t(i,e);function i(s,a){var c=e.call(this)||this;return c.win=s,c.type=a,c.handler=function(l){c.trigger("message",l)},a===i.PROTOCOL_TYPES.LISTEN&&c.win.addEventListener("message",c.handler,!1),c}return i.prototype.dispatch=function(s){return this.win.postMessage(s,"*"),this},i.prototype.destroy=function(){this.type===i.PROTOCOL_TYPES.LISTEN&&this.win.removeEventListener("message",this.handler,!1),this.win=i._fakeWin},i._fakeWin=function(){var s=function(){return null};return{postMessage:s,addEventListener:s,removeEventListener:s}}(),i}(n.EventEmitter);o.WindowProtocol=r,function(e){e.PROTOCOL_TYPES={LISTEN:"listen",DISPATCH:"dispatch"}}(r=o.WindowProtocol||(o.WindowProtocol={})),o.WindowProtocol=r}(A);var nt=u&&u.__extends||function(){var o=function(t,n){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,e){r.__proto__=e}||function(r,e){for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i])},o(t,n)};return function(t,n){o(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}}(),L=u&&u.__assign||function(){return L=Object.assign||function(o){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(o[e]=t[e])}return o},L.apply(this,arguments)};Object.defineProperty(q,"__esModule",{value:!0});var rt=P,w=p,S=A,it=E,ot={origins:[],availableChanelId:[]},st=function(o){nt(t,o);function t(n,r,e){var i=o.call(this)||this;return i.id=w.uniqueId("wa"),i.callbacks=[],i.options=t.prepareOptions(e),i.listen=n,i.dispatch=r,i.listen.forEach(function(s){return s.on("message",i.onMessage,i)}),i}return t.prototype.addListener=function(n){return this.callbacks.push(n),w.console.info("WindowAdapter: Add iframe message listener"),this},t.prototype.send=function(n){var r=L({},n,{chanelId:this.options.chanelId});return this.dispatch.forEach(function(e){return e.dispatch(r)}),w.console.info("WindowAdapter: Send message",r),this},t.prototype.destroy=function(){this.listen.forEach(function(n){return n.destroy()}),this.dispatch.forEach(function(n){return n.destroy()}),w.console.info("WindowAdapter: Destroy")},t.prototype.onMessage=function(n){this.accessEvent(n)&&this.callbacks.forEach(function(r){try{r(n.data)}catch(e){w.console.warn("WindowAdapter: Unhandled exception!",e)}})},t.prototype.accessEvent=function(n){if(typeof n.data!="object"||n.data.type==null)return w.console.info("WindowAdapter: Block event. Wrong event format!",n.data),!1;if(!this.options.origins.has("*")&&!this.options.origins.has(n.origin))return w.console.info('SimpleWindowAdapter: Block event by origin "'+n.origin+'"'),!1;if(!this.options.availableChanelId.size)return!0;var r=!!(n.data.chanelId&&this.options.availableChanelId.has(n.data.chanelId));return r||w.console.info('SimpleWindowAdapter: Block event by chanel id "'+n.data.chanelId+'"'),r},t.createSimpleWindowAdapter=function(n,r){var e=this,i=this.getContentOrigin(n),s=this.prepareOptions(r),a=[];i&&s.origins.add(i);var c=new S.WindowProtocol(window,S.WindowProtocol.PROTOCOL_TYPES.LISTEN),l=function(h){a.push(h)};return c.on("message",l),this.getIframeContent(n).then(function(h){var d=new S.WindowProtocol(h.win,S.WindowProtocol.PROTOCOL_TYPES.DISPATCH),f=new t([c],[d],e.unPrepareOptions(s));return a.forEach(function(y){f.onMessage(y)}),c.off("message",l),f})},t.prepareOptions=function(n){n===void 0&&(n=ot);var r=function(a){return function(c){return c.reduce(function(l,h){return l.add(h)},a)}},e=function(a,c){return it.pipe(w.toArray,r(c))(a)},i=e(n.origins||[],new w.UniqPrimitiveCollection([window.location.origin])),s=e(n.availableChanelId||[],new w.UniqPrimitiveCollection);return L({},n,{origins:i,availableChanelId:s})},t.unPrepareOptions=function(n){return{origins:n.origins.toArray(),availableChanelId:n.availableChanelId.toArray(),chanelId:n.chanelId}},t.getIframeContent=function(n){return n?n instanceof HTMLIFrameElement?n.contentWindow?Promise.resolve({win:n.contentWindow}):new Promise(function(r,e){n.addEventListener("load",function(){return r({win:n.contentWindow})},!1),n.addEventListener("error",e,!1)}):Promise.resolve({win:n}):Promise.resolve({win:window.opener||window.parent})},t.getContentOrigin=function(n){if(!n)try{return new URL(document.referrer).origin}catch{return null}if(!(n instanceof HTMLIFrameElement))try{return window.top.origin}catch{return null}try{return new URL(n.src).origin||null}catch{return null}},t}(rt.Adapter);q.WindowAdapter=st,function(o){function t(n){for(var r in n)o.hasOwnProperty(r)||(o[r]=n[r])}Object.defineProperty(o,"__esModule",{value:!0}),t(M),t(P),t(q),t(A),t(x),t(C)}(p);class at{constructor(t){v(this,"_actions",[]);v(this,"_maxLength");v(this,"_active");this._maxLength=t}get length(){return this._actions.length+(this._active==null?0:1)}push(t){if(this._actions.length>=this._maxLength)throw new Error("Cant't push action! Queue is full!");return new Promise((n,r)=>{const e=()=>{this._active=void 0;const s=this._actions.map(a=>a.action).indexOf(i);s!==-1&&this._actions.splice(s,1),this.run()},i=()=>t().then(s=>{e(),n(s)},s=>{e(),r(s)});this._actions.push({action:i,reject:r}),this.length===1&&this.run()})}clear(t){t=t||new Error("Rejection with clear queue!");const n=typeof t=="string"?new Error(t):t;this._actions.splice(0,this._actions.length).forEach(r=>r.reject(n)),this._active=void 0}canPush(){return this._actions.length<this._maxLength}run(){const t=this._actions.shift();t!=null&&(this._active=t.action())}}const D=o=>o&&o.message==="SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document."?z(V({},o),{message:"Local storage is not available! It is possible that the Browser is in incognito mode!"}):o;class ct{constructor(t){v(this,"_queue");v(this,"_events",[]);v(this,"_toRunEvents",[]);this._queue=new at(t)}dropConnection(){this._queue.clear(new Error("User rejection!")),this._events.forEach(t=>this._toRunEvents.push(t)),this._dropTransportConnect()}sendEvent(t){this._events.push(t),this._toRunEvents.push(t)}dialog(t){return this._runBeforeShow(),this._getBus().then(n=>{const r=this._wrapAction(()=>t(n));return this._runEvents(n),this._queue.canPush()?this._queue.push(r).then(e=>(this._runAfterShow(),e)).catch(e=>(this._runAfterShow(),Promise.reject(D(e)))):Promise.reject(new Error("Queue is full!"))})}_runBeforeShow(){this._queue.length===0&&this._beforeShow()}_runAfterShow(){this._queue.length===0&&this._afterShow()}_runEvents(t){this._toRunEvents.splice(0,this._events.length).forEach(n=>n(t))}_wrapAction(t){return this._toRunEvents?()=>{const n=t();return n.catch(()=>{this._events.forEach(r=>this._toRunEvents.push(r))}),n}:t}}const m=class extends ct{constructor(t,n){super(n);v(this,"_url");v(this,"_iframe");v(this,"_bus");this._url=t,this._initIframe()}get(){return this._iframe||this._initIframe(),this._iframe}_dropTransportConnect(){this._iframe!=null&&(document.body.removeChild(this._iframe),this._initIframe()),this._bus&&(this._bus.destroy(),this._bus=void 0)}_getBus(){return this._bus?Promise.resolve(this._bus):p.WindowAdapter.createSimpleWindowAdapter(this._iframe).then(t=>new Promise(n=>{this._bus=new p.Bus(t,-1),this._bus.once("ready",()=>{n(this._bus)})}))}_beforeShow(){this._showIframe()}_afterShow(){this._hideIframe()}_initIframe(){this._iframe=this._createIframe(),this._addIframeToDom(this._iframe),this._listenFetchURLError(this._iframe),this._hideIframe()}_addIframeToDom(t){document.body!=null?document.body.appendChild(t):document.addEventListener("DOMContentLoaded",()=>{document.body.appendChild(t)})}_createIframe(){const t=document.createElement("iframe");return t.style.transition="opacity .2s",t.style.position="absolute",t.style.opacity="0",t.style.width="100%",t.style.height="100%",t.style.left="0",t.style.top="0",t.style.border="none",t.style.position="fixed",t}_showIframe(){const t={width:"100%",height:"100%",left:"0",top:"0",border:"none",position:"fixed",display:"block",opacity:"0",zIndex:"99999999"};this._applyStyle(t),m._timer!=null&&clearTimeout(m._timer),m._timer=setTimeout(()=>{this._applyStyle({opacity:"1"})},0)}_hideIframe(){const t={opacity:"0"};this._applyStyle(t),m._timer!=null&&clearTimeout(m._timer),m._timer=setTimeout(()=>{this._applyStyle({width:"10px",height:"10px",left:"-100px",top:"-100px",position:"absolute",opacity:"0",zIndex:"0",display:"none"})},200)}_applyStyle(t){Object.entries(t).forEach(([n,r])=>{r!=null&&this._iframe&&(this._iframe.style[n]=r)})}_renderErrorPage(t,n,r){t.parentElement&&(t.parentElement.style.height="100%"),Object.assign(t.style,{position:"relative",boxSizing:"border-box",width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center",margin:"0px"});const e=document.createElement("div");Object.assign(e.style,{position:"fixed",zIndex:"-1",height:"100%",width:"100%",overflow:"hidden",backgroundColor:"#000",opacity:"0.6"});const i=document.createElement("div");Object.assign(i.style,{position:"fixed",display:"flex",justifyContent:"center",alignItems:"center",flexDirection:"column",margin:"0",backgroundColor:"#292F3C",width:"520px",borderRadius:"6px",padding:"40px",boxSizing:"border-box"});const s=document.createElement("div");s.textContent=r,Object.assign(s.style,{fontSize:"15px",lineHeight:"20px",color:"#fff",marginBottom:"40px",fontFamily:"Roboto, sans-serif"});const a=document.createElement("button");a.textContent="OK",a.addEventListener("click",()=>n()),Object.assign(a.style,{width:"100%",fontSize:"15px",lineHeight:"48px",padding:" 0 40px",color:"#fff",backgroundColor:"#5A81EA",outline:"none",border:"none",cursor:"pointer",fontFamily:"Roboto, sans-serif",borderRadius:"4px"}),i.appendChild(s),i.appendChild(a),t.appendChild(e),t.appendChild(i)}_listenFetchURLError(t){fetch(this._url).catch(()=>{t.addEventListener("load",()=>{!t.contentDocument||(this._renderErrorPage(t.contentDocument.body,()=>this.dropConnection(),"The request could not be processed. To resume your further work, disable the installed plugins."),this._showIframe())})})}};let T=m;v(T,"_timer",null);class W{constructor(t,n){v(this,"user",null);v(this,"_transport");v(this,"_clientUrl");v(this,"emitter",new R.exports.EventEmitter);this._clientUrl=(t||"https://waves.exchange/signer/")+`?${W._getCacheClean()}`,this._transport=new T(this._clientUrl,3),n===!0&&(p.config.console.logLevel=p.config.console.LOG_LEVEL.VERBOSE)}static _getCacheClean(){return String(Date.now()%(1e3*60))}on(t,n){return this.emitter.on(t,n),this}once(t,n){return this.emitter.once(t,n),this}off(t,n){return this.emitter.once(t,n),this}connect(t){return Promise.resolve(this._transport.sendEvent(n=>n.dispatchEvent("connect",t)))}logout(){return this.user=null,Promise.resolve(this._transport.dropConnection())}login(){var r;if(this.user)return Promise.resolve(this.user);const t=this._transport.get();if(!((r=t.contentWindow)==null?void 0:r.open(this._clientUrl)))throw new Error("Window was blocked");return t.src=this._clientUrl,this._transport.dialog(e=>e.request("login").then(i=>(this.user=i,i)).catch(i=>(this._transport.dropConnection(),Promise.reject(D(i)))))}signMessage(t){return this.login().then(()=>this._transport.dialog(n=>n.request("sign-message",t)))}signTypedData(t){return this.login().then(()=>this._transport.dialog(n=>n.request("sign-typed-data",t)))}sign(t){return this.login().then(()=>this._transport.dialog(n=>n.request("sign",t)))}}_.ProviderWeb=W,Object.defineProperty(_,"__esModule",{value:!0}),_[Symbol.toStringTag]="Module"});
1
+ var lt=Object.defineProperty,ht=Object.defineProperties;var dt=Object.getOwnPropertyDescriptors;var B=Object.getOwnPropertySymbols;var ft=Object.prototype.hasOwnProperty,pt=Object.prototype.propertyIsEnumerable;var T=(_,u,p)=>u in _?lt(_,u,{enumerable:!0,configurable:!0,writable:!0,value:p}):_[u]=p,D=(_,u)=>{for(var p in u||(u={}))ft.call(u,p)&&T(_,p,u[p]);if(B)for(var p of B(u))pt.call(u,p)&&T(_,p,u[p]);return _},U=(_,u)=>ht(_,dt(u));var v=(_,u,p)=>(T(_,typeof u!="symbol"?u+"":u,p),p);(function(_,u){typeof exports=="object"&&typeof module!="undefined"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(_=typeof globalThis!="undefined"?globalThis:_||self,u(_.providerWeb={}))})(this,function(_){"use strict";var u=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},p={},W={},L={},m={};Object.defineProperty(m,"__esModule",{value:!0});function V(o){return Object.keys(o)}m.keys=V;var z=Math.floor(Date.now()*Math.random()),F=0;function G(o){return o+"-"+z+"-"+F++}m.uniqueId=G;function N(o){return Array.isArray(o)?o:[o]}m.toArray=N;function $(){for(var o=[],t=0;t<arguments.length;t++)o[t]=arguments[t];return function(n){return o.reduce(function(r,e){return e(r)},n)}}m.pipe=$;var C={},j={};(function(o){Object.defineProperty(o,"__esModule",{value:!0}),function(t){(function(n){n.LOG_LEVEL={PRODUCTION:0,ERRORS:1,VERBOSE:2},n.logLevel=n.LOG_LEVEL.PRODUCTION,n.methodsData={log:{save:!1,logLevel:n.LOG_LEVEL.VERBOSE},info:{save:!1,logLevel:n.LOG_LEVEL.VERBOSE},warn:{save:!1,logLevel:n.LOG_LEVEL.VERBOSE},error:{save:!0,logLevel:n.LOG_LEVEL.ERRORS}}})(t.console||(t.console={}))}(o.config||(o.config={}))})(j);var x=u&&u.__assign||function(){return x=Object.assign||function(o){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(o[e]=t[e])}return o},x.apply(this,arguments)};Object.defineProperty(C,"__esModule",{value:!0});var E=j,Y=m,k=function(o){return o.console}(typeof self!="undefined"?self:u),b=Object.create(null);function Q(o){b[o]||(b[o]=[])}function K(o,t){b[o].push(t)}function J(){return Y.keys(E.config.console.methodsData).reduce(function(o,t){return o[t]=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];E.config.console.logLevel<E.config.console.methodsData[t].logLevel?E.config.console.methodsData[t].save&&(Q(t),K(t,n)):k[t].apply(k,n)},o},Object.create(null))}C.console=x({},J(),{getSavedMessages:function(o){return b[o]||[]}});var I={};Object.defineProperty(I,"__esModule",{value:!0});var X=function(){function o(t){this.size=0,this.hash=Object.create(null),t&&t.forEach(this.add,this)}return o.prototype.add=function(t){return this.hash[t]=!0,this.size=Object.keys(this.hash).length,this},o.prototype.has=function(t){return t in this.hash},o.prototype.toArray=function(){return Object.keys(this.hash)},o}();I.UniqPrimitiveCollection=X,function(o){function t(n){for(var r in n)o.hasOwnProperty(r)||(o[r]=n[r])}Object.defineProperty(o,"__esModule",{value:!0}),t(m),t(C),t(I)}(L),function(o){Object.defineProperty(o,"__esModule",{value:!0});var t=L;(function(r){r[r.Event=0]="Event",r[r.Action=1]="Action",r[r.Response=2]="Response"})(o.EventType||(o.EventType={})),function(r){r[r.Success=0]="Success",r[r.Error=1]="Error"}(o.ResponseStatus||(o.ResponseStatus={}));var n=function(){function r(e,i){var s=this;this.id=t.uniqueId("bus"),this._timeout=i||5e3,this._adapter=e,this._adapter.addListener(function(a){return s._onMessage(a)}),this._eventHandlers=Object.create(null),this._activeRequestHash=Object.create(null),this._requestHandlers=Object.create(null),t.console.info('Create Bus with id "'+this.id+'"')}return r.prototype.dispatchEvent=function(e,i){return this._adapter.send(r._createEvent(e,i)),t.console.info('Dispatch event "'+e+'"',i),this},r.prototype.request=function(e,i,s){var a=this;return new Promise(function(c,l){var h=t.uniqueId(a.id+"-action"),d=s||a._timeout,f;(s||a._timeout)!==-1&&(f=setTimeout(function(){delete a._activeRequestHash[h];var y=new Error('Timeout error for request with name "'+e+'" and timeout '+d+"!");t.console.error(y),l(y)},d));var g=function(){f&&clearTimeout(f)};a._activeRequestHash[h]={reject:function(y){g(),t.console.error('Error request with name "'+e+'"',y),l(y)},resolve:function(y){g(),t.console.info('Request with name "'+e+'" success resolved!',y),c(y)}},a._adapter.send({id:h,type:1,name:e,data:i}),t.console.info('Request with name "'+e+'"',i)})},r.prototype.on=function(e,i,s){return this._addEventHandler(e,i,s,!1)},r.prototype.once=function(e,i,s){return this._addEventHandler(e,i,s,!0)},r.prototype.off=function(e,i){var s=this;return e?this._eventHandlers[e]?i?(this._eventHandlers[e]=this._eventHandlers[e].filter(function(a){return a.handler!==i}),this._eventHandlers[e].length||delete this._eventHandlers[e],this):(this._eventHandlers[e].slice().forEach(function(a){s.off(e,a.handler)}),this):this:(Object.keys(this._eventHandlers).forEach(function(a){return s.off(a,i)}),this)},r.prototype.registerRequestHandler=function(e,i){if(this._requestHandlers[e])throw new Error("Duplicate request handler!");return this._requestHandlers[e]=i,this},r.prototype.unregisterHandler=function(e){return this._requestHandlers[e]&&delete this._requestHandlers[e],this},r.prototype.changeAdapter=function(e){var i=this,s=new r(e,this._timeout);return Object.keys(this._eventHandlers).forEach(function(a){i._eventHandlers[a].forEach(function(c){c.once?s.once(a,c.handler,c.context):s.on(a,c.handler,c.context)})}),Object.keys(this._requestHandlers).forEach(function(a){s.registerRequestHandler(a,i._requestHandlers[a])}),s},r.prototype.destroy=function(){t.console.info("Destroy Bus"),this.off(),this._adapter.destroy()},r.prototype._addEventHandler=function(e,i,s,a){return this._eventHandlers[e]||(this._eventHandlers[e]=[]),this._eventHandlers[e].push({handler:i,once:a,context:s}),this},r.prototype._onMessage=function(e){switch(e.type){case 0:t.console.info('Has event with name "'+String(e.name)+'"',e.data),this._fireEvent(String(e.name),e.data);break;case 1:t.console.info('Start action with id "'+e.id+'" and name "'+String(e.name)+'"',e.data),this._createResponse(e);break;case 2:t.console.info('Start response with name "'+e.id+'" and status "'+e.status+'"',e.content),this._fireEndAction(e);break}},r.prototype._createResponse=function(e){var i=this,s=function(c){t.console.error(c),i._adapter.send({id:e.id,type:2,status:1,content:String(c)})};if(!this._requestHandlers[String(e.name)]){s(new Error('Has no handler for "'+String(e.name)+'" action!'));return}try{var a=this._requestHandlers[String(e.name)](e.data);r._isPromise(a)?a.then(function(c){i._adapter.send({id:e.id,type:2,status:0,content:c})},s):this._adapter.send({id:e.id,type:2,status:0,content:a})}catch(c){s(c)}},r.prototype._fireEndAction=function(e){if(this._activeRequestHash[e.id]){switch(e.status){case 1:this._activeRequestHash[e.id].reject(e.content);break;case 0:this._activeRequestHash[e.id].resolve(e.content);break}delete this._activeRequestHash[e.id]}},r.prototype._fireEvent=function(e,i){!this._eventHandlers[e]||(this._eventHandlers[e]=this._eventHandlers[e].slice().filter(function(s){try{s.handler.call(s.context,i)}catch(a){t.console.warn(a)}return!s.once}),this._eventHandlers[e].length||delete this._eventHandlers[e])},r._createEvent=function(e,i){return{type:0,name:e,data:i}},r._isPromise=function(e){return e&&e.then&&typeof e.then=="function"},r}();o.Bus=n}(W);var O={};Object.defineProperty(O,"__esModule",{value:!0});var Z=function(){function o(){}return o}();O.Adapter=Z;var A={},H={},q={exports:{}};(function(o,t){(function(n,r){o.exports=r()})(u,function(){return(()=>{var n={660:(e,i)=>{i.__esModule=!0,i.EventEmitter=void 0;var s=function(){function a(c){this._events=Object.create(null),this.catchHandler=c||function(){}}return a.prototype.hasListeners=function(c){return!(!this._events[c]||!this._events[c].length)},a.prototype.getActiveEvents=function(){var c=this;return Object.keys(this._events).filter(function(l){return c.hasListeners(l)})},a.prototype.trigger=function(c,l){var h=this;this._events[c]&&(this._events[c].slice().forEach(function(d){try{d.handler.call(d.context,l)}catch(f){h.catchHandler(f)}d.once&&h.off(c,d.handler)}),this._events[c].length||delete this._events[c])},a.prototype.on=function(c,l,h){this._on(c,l,h,!1)},a.prototype.once=function(c,l,h){this._on(c,l,h,!0)},a.prototype.off=function(c,l){var h=this,d=typeof c=="string"?c:null,f=typeof l=="function"?l:typeof c=="function"?c:null;if(d)if(f){if(d in this._events){var g=this._events[d].map(function(y){return y.handler}).indexOf(f);this._events[d].splice(g,1)}}else delete this._events[d];else Object.keys(this._events).forEach(function(y){h.off(y,f)})},a.prototype._on=function(c,l,h,d){this._events[c]||(this._events[c]=[]),this._events[c].push({handler:l,context:h,once:d})},a}();i.EventEmitter=s},607:function(e,i,s){var a=this&&this.__createBinding||(Object.create?function(h,d,f,g){g===void 0&&(g=f),Object.defineProperty(h,g,{enumerable:!0,get:function(){return d[f]}})}:function(h,d,f,g){g===void 0&&(g=f),h[g]=d[f]}),c=this&&this.__exportStar||function(h,d){for(var f in h)f==="default"||Object.prototype.hasOwnProperty.call(d,f)||a(d,h,f)};i.__esModule=!0;var l=s(660);c(s(660),i),i.default=l.EventEmitter}},r={};return function e(i){if(r[i])return r[i].exports;var s=r[i]={exports:{}};return n[i].call(s.exports,s,s.exports,e),s.exports}(607)})()})})(q),function(o){var t=u&&u.__extends||function(){var e=function(i,s){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,c){a.__proto__=c}||function(a,c){for(var l in c)c.hasOwnProperty(l)&&(a[l]=c[l])},e(i,s)};return function(i,s){e(i,s);function a(){this.constructor=i}i.prototype=s===null?Object.create(s):(a.prototype=s.prototype,new a)}}();Object.defineProperty(o,"__esModule",{value:!0});var n=q.exports,r=function(e){t(i,e);function i(s,a){var c=e.call(this)||this;return c.win=s,c.type=a,c.handler=function(l){c.trigger("message",l)},a===i.PROTOCOL_TYPES.LISTEN&&c.win.addEventListener("message",c.handler,!1),c}return i.prototype.dispatch=function(s){return this.win.postMessage(s,"*"),this},i.prototype.destroy=function(){this.type===i.PROTOCOL_TYPES.LISTEN&&this.win.removeEventListener("message",this.handler,!1),this.win=i._fakeWin},i._fakeWin=function(){var s=function(){return null};return{postMessage:s,addEventListener:s,removeEventListener:s}}(),i}(n.EventEmitter);o.WindowProtocol=r,function(e){e.PROTOCOL_TYPES={LISTEN:"listen",DISPATCH:"dispatch"}}(r=o.WindowProtocol||(o.WindowProtocol={})),o.WindowProtocol=r}(H);var tt=u&&u.__extends||function(){var o=function(t,n){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,e){r.__proto__=e}||function(r,e){for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i])},o(t,n)};return function(t,n){o(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}}(),P=u&&u.__assign||function(){return P=Object.assign||function(o){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(o[e]=t[e])}return o},P.apply(this,arguments)};Object.defineProperty(A,"__esModule",{value:!0});var et=O,w=p,S=H,nt=m,rt={origins:[],availableChanelId:[]},it=function(o){tt(t,o);function t(n,r,e){var i=o.call(this)||this;return i.id=w.uniqueId("wa"),i.callbacks=[],i.options=t.prepareOptions(e),i.listen=n,i.dispatch=r,i.listen.forEach(function(s){return s.on("message",i.onMessage,i)}),i}return t.prototype.addListener=function(n){return this.callbacks.push(n),w.console.info("WindowAdapter: Add iframe message listener"),this},t.prototype.send=function(n){var r=P({},n,{chanelId:this.options.chanelId});return this.dispatch.forEach(function(e){return e.dispatch(r)}),w.console.info("WindowAdapter: Send message",r),this},t.prototype.destroy=function(){this.listen.forEach(function(n){return n.destroy()}),this.dispatch.forEach(function(n){return n.destroy()}),w.console.info("WindowAdapter: Destroy")},t.prototype.onMessage=function(n){this.accessEvent(n)&&this.callbacks.forEach(function(r){try{r(n.data)}catch(e){w.console.warn("WindowAdapter: Unhandled exception!",e)}})},t.prototype.accessEvent=function(n){if(typeof n.data!="object"||n.data.type==null)return w.console.info("WindowAdapter: Block event. Wrong event format!",n.data),!1;if(!this.options.origins.has("*")&&!this.options.origins.has(n.origin))return w.console.info('SimpleWindowAdapter: Block event by origin "'+n.origin+'"'),!1;if(!this.options.availableChanelId.size)return!0;var r=!!(n.data.chanelId&&this.options.availableChanelId.has(n.data.chanelId));return r||w.console.info('SimpleWindowAdapter: Block event by chanel id "'+n.data.chanelId+'"'),r},t.createSimpleWindowAdapter=function(n,r){var e=this,i=this.getContentOrigin(n),s=this.prepareOptions(r),a=[];i&&s.origins.add(i);var c=new S.WindowProtocol(window,S.WindowProtocol.PROTOCOL_TYPES.LISTEN),l=function(h){a.push(h)};return c.on("message",l),this.getIframeContent(n).then(function(h){var d=new S.WindowProtocol(h.win,S.WindowProtocol.PROTOCOL_TYPES.DISPATCH),f=new t([c],[d],e.unPrepareOptions(s));return a.forEach(function(g){f.onMessage(g)}),c.off("message",l),f})},t.prepareOptions=function(n){n===void 0&&(n=rt);var r=function(a){return function(c){return c.reduce(function(l,h){return l.add(h)},a)}},e=function(a,c){return nt.pipe(w.toArray,r(c))(a)},i=e(n.origins||[],new w.UniqPrimitiveCollection([window.location.origin])),s=e(n.availableChanelId||[],new w.UniqPrimitiveCollection);return P({},n,{origins:i,availableChanelId:s})},t.unPrepareOptions=function(n){return{origins:n.origins.toArray(),availableChanelId:n.availableChanelId.toArray(),chanelId:n.chanelId}},t.getIframeContent=function(n){return n?n instanceof HTMLIFrameElement?n.contentWindow?Promise.resolve({win:n.contentWindow}):new Promise(function(r,e){n.addEventListener("load",function(){return r({win:n.contentWindow})},!1),n.addEventListener("error",e,!1)}):Promise.resolve({win:n}):Promise.resolve({win:window.opener||window.parent})},t.getContentOrigin=function(n){if(!n)try{return new URL(document.referrer).origin}catch{return null}if(!(n instanceof HTMLIFrameElement))try{return window.top.origin}catch{return null}try{return new URL(n.src).origin||null}catch{return null}},t}(et.Adapter);A.WindowAdapter=it,function(o){function t(n){for(var r in n)o.hasOwnProperty(r)||(o[r]=n[r])}Object.defineProperty(o,"__esModule",{value:!0}),t(W),t(O),t(A),t(H),t(j),t(L)}(p);class ot{constructor(t){v(this,"_actions",[]);v(this,"_maxLength");v(this,"_active");this._maxLength=t}get length(){return this._actions.length+(this._active==null?0:1)}push(t){if(this._actions.length>=this._maxLength)throw new Error("Cant't push action! Queue is full!");return new Promise((n,r)=>{const e=()=>{this._active=void 0;const s=this._actions.map(a=>a.action).indexOf(i);s!==-1&&this._actions.splice(s,1),this.run()},i=()=>t().then(s=>{e(),n(s)},s=>{e(),r(s)});this._actions.push({action:i,reject:r}),this.length===1&&this.run()})}clear(t){t=t||new Error("Rejection with clear queue!");const n=typeof t=="string"?new Error(t):t;this._actions.splice(0,this._actions.length).forEach(r=>r.reject(n)),this._active=void 0}canPush(){return this._actions.length<this._maxLength}run(){const t=this._actions.shift();t!=null&&(this._active=t.action())}}const M=o=>o&&o.message==="SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document."?U(D({},o),{message:"Local storage is not available! It is possible that the Browser is in incognito mode!"}):o;class st{constructor(t){v(this,"_queue");v(this,"_events",[]);v(this,"_toRunEvents",[]);this._queue=new ot(t)}dropConnection(){this._queue.clear(new Error("User rejection!")),this._events.forEach(t=>this._toRunEvents.push(t)),this._dropTransportConnect()}sendEvent(t){this._events.push(t),this._toRunEvents.push(t)}dialog(t){return this._runBeforeShow(),this._getBus().then(n=>{const r=this._wrapAction(()=>t(n));return this._runEvents(n),this._queue.canPush()?this._queue.push(r).then(e=>(this._runAfterShow(),e)).catch(e=>(this._runAfterShow(),Promise.reject(M(e)))):Promise.reject(new Error("Queue is full!"))})}_runBeforeShow(){this._queue.length===0&&this._beforeShow()}_runAfterShow(){this._queue.length===0&&this._afterShow()}_runEvents(t){this._toRunEvents.splice(0,this._events.length).forEach(n=>n(t))}_wrapAction(t){return this._toRunEvents?()=>{const n=t();return n.catch(()=>{this._events.forEach(r=>this._toRunEvents.push(r))}),n}:t}}class at extends st{constructor(t,n){super(n);v(this,"_timer",null);v(this,"_url");v(this,"_iframe");v(this,"_bus");this._url=t,this._initIframe()}get(){return this._iframe||this._initIframe(),this._iframe}_dropTransportConnect(){this._iframe!=null&&(document.body.removeChild(this._iframe),this._initIframe()),this._bus&&(this._bus.destroy(),this._bus=void 0)}_getBus(){return this._bus?Promise.resolve(this._bus):p.WindowAdapter.createSimpleWindowAdapter(this._iframe).then(t=>new Promise(n=>{this._bus=new p.Bus(t,-1),this._bus.once("ready",()=>{n(this._bus)})}))}_beforeShow(){this._showIframe()}_afterShow(){this._hideIframe()}_initIframe(){this._iframe=this._createIframe(),this._addIframeToDom(this._iframe),this._listenFetchURLError(this._iframe),this._hideIframe()}_addIframeToDom(t){document.body!=null?document.body.appendChild(t):document.addEventListener("DOMContentLoaded",()=>{document.body.appendChild(t)})}_createIframe(){const t=document.createElement("iframe");return t.style.transition="opacity .2s",t.style.position="absolute",t.style.opacity="0",t.style.width="100%",t.style.height="100%",t.style.left="0",t.style.top="0",t.style.border="none",t.style.position="fixed",t}_showIframe(){const t={width:"100%",height:"100%",left:"0",top:"0",border:"none",position:"fixed",display:"block",opacity:"0",zIndex:"99999999"};this._applyStyle(t),this._timer!=null&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._applyStyle({opacity:"1"})},0)}_hideIframe(){const t={opacity:"0"};this._applyStyle(t),this._timer!=null&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._applyStyle({width:"10px",height:"10px",left:"-100px",top:"-100px",position:"absolute",opacity:"0",zIndex:"0",display:"none"})},200)}_applyStyle(t){Object.entries(t).forEach(([n,r])=>{r!=null&&this._iframe&&(this._iframe.style[n]=r)})}_renderErrorPage(t,n,r){t.parentElement&&(t.parentElement.style.height="100%"),Object.assign(t.style,{position:"relative",boxSizing:"border-box",width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center",margin:"0px"});const e=document.createElement("div");Object.assign(e.style,{position:"fixed",zIndex:"-1",height:"100%",width:"100%",overflow:"hidden",backgroundColor:"#000",opacity:"0.6"});const i=document.createElement("div");Object.assign(i.style,{position:"fixed",display:"flex",justifyContent:"center",alignItems:"center",flexDirection:"column",margin:"0",backgroundColor:"#292F3C",width:"520px",borderRadius:"6px",padding:"40px",boxSizing:"border-box"});const s=document.createElement("div");s.textContent=r,Object.assign(s.style,{fontSize:"15px",lineHeight:"20px",color:"#fff",marginBottom:"40px",fontFamily:"Roboto, sans-serif"});const a=document.createElement("button");a.textContent="OK",a.addEventListener("click",()=>n()),Object.assign(a.style,{width:"100%",fontSize:"15px",lineHeight:"48px",padding:" 0 40px",color:"#fff",backgroundColor:"#5A81EA",outline:"none",border:"none",cursor:"pointer",fontFamily:"Roboto, sans-serif",borderRadius:"4px"}),i.appendChild(s),i.appendChild(a),t.appendChild(e),t.appendChild(i)}_listenFetchURLError(t){fetch(this._url).catch(()=>{t.addEventListener("load",()=>{!t.contentDocument||(this._renderErrorPage(t.contentDocument.body,()=>this.dropConnection(),"The request could not be processed. To resume your further work, disable the installed plugins."),this._showIframe())})})}}function ct(){var o;return!!((o=navigator.brave)==null?void 0:o.isBrave)}function ut(){const o=navigator.userAgent.toLowerCase(),t=o.includes("safari")&&!o.includes("chrome");return navigator.platform!=null&&/iPad|iPhone|iPod/.test(navigator.platform)||t}class R{constructor(t,n){v(this,"user",null);v(this,"_transport");v(this,"_clientUrl");v(this,"emitter",new q.exports.EventEmitter);this._clientUrl=(t||"https://waves.exchange/signer/")+`?${R._getCacheClean()}`,this._transport=new at(this._clientUrl,3),n===!0&&(p.config.console.logLevel=p.config.console.LOG_LEVEL.VERBOSE)}static _getCacheClean(){return String(Date.now()%(1e3*60))}on(t,n){return this.emitter.on(t,n),this}once(t,n){return this.emitter.once(t,n),this}off(t,n){return this.emitter.once(t,n),this}connect(t){return Promise.resolve(this._transport.sendEvent(n=>n.dispatchEvent("connect",t)))}logout(){return this.user=null,Promise.resolve(this._transport.dropConnection())}login(){var n;if(this.user)return Promise.resolve(this.user);const t=this._transport.get();if((ut()||ct())&&!((n=t.contentWindow)==null?void 0:n.open(this._clientUrl)))throw new Error("Window was blocked");return t.src=this._clientUrl,this._transport.dialog(r=>r.request("login").then(e=>(this.user=e,e)).catch(e=>(this._transport.dropConnection(),Promise.reject(M(e)))))}signMessage(t){return this.login().then(()=>this._transport.dialog(n=>n.request("sign-message",t)))}signTypedData(t){return this.login().then(()=>this._transport.dialog(n=>n.request("sign-typed-data",t)))}sign(t){return this.login().then(()=>this._transport.dialog(n=>n.request("sign",t)))}}_.ProviderWeb=R,Object.defineProperty(_,"__esModule",{value:!0}),_[Symbol.toStringTag]="Module"});
@@ -1,7 +1,7 @@
1
1
  import { TBus } from './interface';
2
2
  import { Transport } from './Transport';
3
3
  export declare class TransportIframe extends Transport<HTMLIFrameElement> {
4
- private static _timer;
4
+ private _timer;
5
5
  private readonly _url;
6
6
  private _iframe;
7
7
  private _bus;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waves.exchange/provider-web",
3
- "version": "1.1.4",
3
+ "version": "1.1.7",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"