blockcity-js-sdk
Version:
BlockCity JS-SDK is a web development kit based on BlockCity for web developers.
2 lines (1 loc) • 24.6 kB
JavaScript
;function isDataView(e){return e&&DataView.prototype.isPrototypeOf(e)}function normalizeName(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function normalizeValue(e){return"string"!=typeof e&&(e=String(e)),e}function iteratorFor(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return support.iterable&&(t[Symbol.iterator]=function(){return t}),t}function Headers(e){this.map={},e instanceof Headers?e.forEach(function(e,t){this.append(t,e)},this):Array.isArray(e)?e.forEach(function(e){this.append(e[0],e[1])},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}function consumed(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function fileReaderReady(e){return new Promise(function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}})}function readBlobAsArrayBuffer(e){var t=new FileReader,r=fileReaderReady(t);return t.readAsArrayBuffer(e),r}function readBlobAsText(e){var t=new FileReader,r=fileReaderReady(t);return t.readAsText(e),r}function readArrayBufferAsText(e){for(var t=new Uint8Array(e),r=new Array(t.length),o=0;o<t.length;o++)r[o]=String.fromCharCode(t[o]);return r.join("")}function bufferClone(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function Body(){return this.bodyUsed=!1,this._initBody=function(e){this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:support.blob&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:support.formData&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:support.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():support.arrayBuffer&&support.blob&&isDataView(e)?(this._bodyArrayBuffer=bufferClone(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):support.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(e)||isArrayBufferView(e))?this._bodyArrayBuffer=bufferClone(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):support.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},support.blob&&(this.blob=function(){var e=consumed(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?consumed(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(readBlobAsArrayBuffer)}),this.text=function(){var e=consumed(this);if(e)return e;if(this._bodyBlob)return readBlobAsText(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},support.formData&&(this.formData=function(){return this.text().then(decode)}),this.json=function(){return this.text().then(JSON.parse)},this}function normalizeMethod(e){var t=e.toUpperCase();return methods$1.indexOf(t)>-1?t:e}function Request(e,t){t=t||{};var r=t.body;if(e instanceof Request){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new Headers(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,r||null==e._bodyInit||(r=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new Headers(t.headers)),this.method=normalizeMethod(t.method||this.method||"GET"),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(r)}function decode(e){var t=new FormData;return e.trim().split("&").forEach(function(e){if(e){var r=e.split("="),o=r.shift().replace(/\+/g," "),a=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(o),decodeURIComponent(a))}}),t}function parseHeaders(e){var t=new Headers;return e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(e){var r=e.split(":"),o=r.shift().trim();if(o){var a=r.join(":").trim();t.append(o,a)}}),t}function Response(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new Headers(t.headers),this.url=t.url||"",this._initBody(e)}function fetch(e,t){return new Promise(function(r,o){function a(){i.abort()}var n=new Request(e,t);if(n.signal&&n.signal.aborted)return o(new DOMException("Aborted","AbortError"));var i=new XMLHttpRequest;i.onload=function(){var e={status:i.status,statusText:i.statusText,headers:parseHeaders(i.getAllResponseHeaders()||"")};e.url="responseURL"in i?i.responseURL:e.headers.get("X-Request-URL");var t="response"in i?i.response:i.responseText;r(new Response(t,e))},i.onerror=function(){o(new TypeError("Network request failed"))},i.ontimeout=function(){o(new TypeError("Network request failed"))},i.onabort=function(){o(new DOMException("Aborted","AbortError"))},i.open(n.method,n.url,!0),"include"===n.credentials?i.withCredentials=!0:"omit"===n.credentials&&(i.withCredentials=!1),"responseType"in i&&support.blob&&(i.responseType="blob"),n.headers.forEach(function(e,t){i.setRequestHeader(t,e)}),n.signal&&(n.signal.addEventListener("abort",a),i.onreadystatechange=function(){4===i.readyState&&n.signal.removeEventListener("abort",a)}),i.send(void 0===n._bodyInit?null:n._bodyInit)})}function getMobileOperatingSystem(){var e=navigator.userAgent||navigator.vendor||window.opera;return/windows phone/i.test(e)?"wp":/android/i.test(e)?"android":/iPad|iPhone|iPod/.test(e)&&!window.MSStream?"ios":"unknown"}var support={searchParams:"URLSearchParams"in self,iterable:"Symbol"in self&&"iterator"in Symbol,blob:"FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(e){return!1}}(),formData:"FormData"in self,arrayBuffer:"ArrayBuffer"in self};if(support.arrayBuffer)var viewClasses=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],isArrayBufferView=ArrayBuffer.isView||function(e){return e&&viewClasses.indexOf(Object.prototype.toString.call(e))>-1};Headers.prototype.append=function(e,t){e=normalizeName(e),t=normalizeValue(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},Headers.prototype.delete=function(e){delete this.map[normalizeName(e)]},Headers.prototype.get=function(e){return e=normalizeName(e),this.has(e)?this.map[e]:null},Headers.prototype.has=function(e){return this.map.hasOwnProperty(normalizeName(e))},Headers.prototype.set=function(e,t){this.map[normalizeName(e)]=normalizeValue(t)},Headers.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},Headers.prototype.keys=function(){var e=[];return this.forEach(function(t,r){e.push(r)}),iteratorFor(e)},Headers.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),iteratorFor(e)},Headers.prototype.entries=function(){var e=[];return this.forEach(function(t,r){e.push([r,t])}),iteratorFor(e)},support.iterable&&(Headers.prototype[Symbol.iterator]=Headers.prototype.entries);var methods$1=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];Request.prototype.clone=function(){return new Request(this,{body:this._bodyInit})},Body.call(Request.prototype),Body.call(Response.prototype),Response.prototype.clone=function(){return new Response(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new Headers(this.headers),url:this.url})},Response.error=function(){var e=new Response(null,{status:0,statusText:""});return e.type="error",e};var redirectStatuses=[301,302,303,307,308];Response.redirect=function(e,t){if(-1===redirectStatuses.indexOf(t))throw new RangeError("Invalid status code");return new Response(null,{status:t,headers:{location:e}})};var DOMException=self.DOMException;try{new DOMException}catch(e){DOMException=function(e,t){this.message=e,this.name=t;var r=Error(e);this.stack=r.stack},DOMException.prototype=Object.create(Error.prototype),DOMException.prototype.constructor=DOMException}fetch.polyfill=!0,self.fetch||(self.fetch=fetch,self.Headers=Headers,self.Request=Request,self.Response=Response);var apis={local:{ios:{closeWindow:"1.3.9",qrScan:"1.3.9",shareConfig:"1.3.10",callShare:"2.0.3",choosePay:"1.3.9",rotate:"2.0.3",getDeviceInfo:"2.0.3",getSysLanguage:"2.0.3",callAuth:"2.0.0",callContract:"2.0.0"},android:{closeWindow:"1.3.11",qrScan:"1.3.11",shareConfig:"1.3.15",callShare:"2.0.3",choosePay:"1.3.11",rotate:"2.0.3",getDeviceInfo:"2.0.3",getSysLanguage:"2.0.3",callAuth:"2.0.0",callContract:"2.0.0"}},global:{ios:{closeWindow:"2.0.0",qrScan:"2.0.0",shareConfig:"2.0.0",callShare:"2.0.0",choosePay:"2.0.0",rotate:"2.0.0",getDeviceInfo:"2.0.0",getSysLanguage:"2.0.0",callAuth:"2.0.0",callContract:"2.0.0"},android:{closeWindow:"2.0.0",qrScan:"2.0.0",shareConfig:"2.0.0",callShare:"2.0.0",choosePay:"2.0.0",rotate:"2.0.0",getDeviceInfo:"2.0.0",getSysLanguage:"2.0.0",callAuth:"2.0.0",callContract:"2.0.0"}}},_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},methods={},methodID=0,needEncode=!0;window.formatJSON=function(e){for(var t={},r=e.split("&"),o=0;o<r.length;o++){var a=r[o].split("=");a[1]=decodeURIComponent(a[1]),a[1].split("{").length>1&&a[1].split("}").length>1&&(a[1]=JSON.parse(a[1])),t[a[0]]=a[1]}return t};var nativeCallback=window.nativeCallback||function(){};window.nativeCallback=function(e){var t=Array.prototype.slice.call(arguments,1);"function"==typeof methods[e]&&methods[e].apply(this,t),nativeCallback.apply(void 0,arguments)};var Blockcity={callBridge:function(e,t,r,o){var a=methodID++,n="";methods[a]=function(){if("function"==typeof o&&o.apply(this,arguments),methods[a])try{delete methods[a]}catch(e){methods[a]=null}},"object"!==(void 0===r?"undefined":_typeof(r))&&(r={}),r._mId=a;for(var i in r)n+=needEncode?(-1!=n.indexOf("=")?"&":"")+encodeURIComponent(i)+"="+encodeURIComponent(r[i]):(-1!=n.indexOf("=")?"&":"")+i+"="+encodeURI(r[i]);var s,c=e+"://"+t+"?"+n;s=document.createElement("iframe"),s.setAttribute("src",c),s.setAttribute("style","display:none;"),s.setAttribute("height","0px"),s.setAttribute("width","0px"),s.setAttribute("frameborder","0"),document.body.appendChild(s),s.parentNode.removeChild(s),s=null},callNative:function(e,t,r){this.callBridge("native",e,t,r)},compareVersion:function(e,t){var r=e.split("."),o=t.split(".");return 1e6*r[0]+1e3*r[1]+parseInt(r[2])<=1e6*o[0]+1e3*o[1]+parseInt(o[2])},closeWindow:function(){this.callNative("exit")},qrScan:function(e){e=e||function(){},this.callNative("qrscan",{},function(t){e&&e(t)})},getDeviceInfo:function(e){e=e||function(){},this.callNative("deviceInfo",{},function(t){e&&e(t)})},choosePay:function(e){return e="object"===(void 0===e?"undefined":_typeof(e))?e:{},e.success=e.hasOwnProperty("success")?e.success:function(){},e.fail=e.hasOwnProperty("fail")?e.fail:function(){},e.cancel=e.hasOwnProperty("cancel")?e.cancel:function(){},e.hasOwnProperty("tradeNo")?"string"!=typeof e.tradeNo?void errorHandler("tradeNo is not a string"):void this.callNative("pay",{tradeNo:e.tradeNo},function(t,r,o){switch(o&&this.callNative("finish",{tradeNo:t,status:r,isThird:o},function(){}),r){case"success":e.success&&e.success();break;case"timeout":e.fail&&e.fail("TIMEOUT");break;case"failed":e.fail&&e.fail("FAILED");break;case"close":e.cancel&&e.cancel()}}):void errorHandler("tradeNo is undefined")},shareConfig:function(e){function t(t){o.callNative("shareConfig",{title:e.title,shareDes:e.shareDes,url:t,thumbUrl:e.thumbUrl},function(t){"success"===t?e.success&&e.success(a):e.fail&&e.fail(t)})}function r(){return fetch("https://blockcity.gxb.io/api/app/config/share_domain?type=sdk").then(function(e){return e.json()}).then(function(e){return e.data.share_domain}).catch(function(e){return"https://share.8ug2.cn/tmp/"})}if(e="object"===(void 0===e?"undefined":_typeof(e))?e:{},e.success=e.hasOwnProperty("success")?e.success:function(){},e.fail=e.hasOwnProperty("fail")?e.fail:function(){},!e.hasOwnProperty("title"))return void errorHandler("title is undefined");if("string"!=typeof e.title)return void errorHandler("title is not a string");if(!e.hasOwnProperty("shareDes"))return void errorHandler("shareDes is undefined");if("string"!=typeof e.shareDes)return void errorHandler("shareDes is not a string");if(!e.hasOwnProperty("url"))return void errorHandler("url is undefined");if("string"!=typeof e.url)return void errorHandler("url is not a string");if(!e.hasOwnProperty("thumbUrl"))return void errorHandler("thumbUrl is undefined");if("string"!=typeof e.thumbUrl)return void errorHandler("thumbUrl is not a string");var o=this,a=e.url,n=setTimeout(function(){needEncode=!1,r().then(function(e){t(e+encodeURIComponent(a))})},500);this.callNative("deviceInfo",{},function(e){clearTimeout(n);var i=JSON.parse(e),s=i.appName||"",c=i.platform,l=i.version;if("blockcityglobal"!==s&&!o.compareVersion(apis.local[c].shareConfig,l))return void r().then(function(e){t(e+encodeURIComponent(a))});t(a)})},callShare:function(e){var t=this;if(e="object"===(void 0===e?"undefined":_typeof(e))?e:{},e.success=e.hasOwnProperty("success")?e.success:function(){},e.fail=e.hasOwnProperty("fail")?e.fail:function(){},e.hasOwnProperty("contentType")&&0===e.contentType){if(!e.hasOwnProperty("title"))return void errorHandler("title is undefined");if("string"!=typeof e.title)return void errorHandler("title is not a string")}else{if(!e.hasOwnProperty("title"))return void errorHandler("title is undefined");if("string"!=typeof e.title)return void errorHandler("title is not a string");if(!e.hasOwnProperty("shareDes"))return void errorHandler("shareDes is undefined");if("string"!=typeof e.shareDes)return void errorHandler("shareDes is not a string");if(!e.hasOwnProperty("url"))return void errorHandler("url is undefined");if("string"!=typeof e.url)return void errorHandler("url is not a string");if(!e.hasOwnProperty("thumbUrl"))return void errorHandler("thumbUrl is undefined");if("string"!=typeof e.thumbUrl)return void errorHandler("thumbUrl is not a string")}var r=this,o=setTimeout(function(){t.callNative("share",{contentType:e.contentType||0,sceneType:e.sceneType||0,title:e.title,shareDes:e.shareDes,url:e.url,thumbUrl:e.thumbUrl},function(t){"success"===t?e.success&&e.success(t):e.fail&&e.fail(t)})},500);this.callNative("deviceInfo",{},function(t){clearTimeout(o);var a=JSON.parse(t),n=a.appName||"",i=a.platform,s=a.version;"blockcityglobal"!==n?r.compareVersion(apis.local[i].callShare,s)?r.callNative("share",{contentType:e.contentType||0,sceneType:e.sceneType||0,title:e.title,shareDes:e.shareDes,url:e.url,thumbUrl:e.thumbUrl},function(t){"success"===t?e.success&&e.success(t):e.fail&&e.fail(t)}):alert("The current version of the app is too low, please upgrade to the latest version."):r.compareVersion(apis.global[i].callShare,s)?r.callNative("share",{contentType:e.contentType||0,sceneType:e.sceneType||0,title:e.title,shareDes:e.shareDes,url:e.url,thumbUrl:e.thumbUrl},function(t){"success"===t?e.success&&e.success(t):e.fail&&e.fail(t)}):alert("The current version of the app is too low, please upgrade to the latest version.")})},rotate:function(e){var t=this;e="object"===(void 0===e?"undefined":_typeof(e))?e:{},e.hiddenNav=e.hasOwnProperty("hiddenNav")?e.hiddenNav:1,e.direction=e.hasOwnProperty("direction")?e.direction:0;var r=this,o=setTimeout(function(){t.callNative("rotate",{hiddenNav:e.hiddenNav,direction:e.direction})},500);this.callNative("deviceInfo",{},function(t){clearTimeout(o);var a=JSON.parse(t),n=a.appName||"",i=a.platform,s=a.version;"blockcityglobal"!==n?r.compareVersion(apis.local[i].rotate,s)?r.callNative("rotate",{hiddenNav:e.hiddenNav,direction:e.direction}):alert("The current version of the app is too low, please upgrade to the latest version."):r.compareVersion(apis.global[i].rotate,s)?r.callNative("rotate",{hiddenNav:e.hiddenNav,direction:e.direction}):alert("The current version of the app is too low, please upgrade to the latest version.")})},getSysLanguage:function(e){var t=this;e=e||function(){};var r=this,o=setTimeout(function(){t.callNative("currentLanguage",{},function(t){e&&e(t)})},500);this.callNative("deviceInfo",{},function(t){clearTimeout(o);var a=JSON.parse(t),n=a.appName||"",i=a.platform,s=a.version;"blockcityglobal"!==n?r.compareVersion(apis.local[i].getSysLanguage,s)?r.callNative("currentLanguage",{},function(t){e&&e(t)}):alert("The current version of the app is too low, please upgrade to the latest version."):r.compareVersion(apis.global[i].getSysLanguage,s)?r.callNative("currentLanguage",{},function(t){e&&e(t)}):alert("The current version of the app is too low, please upgrade to the latest version.")})},callAuth:function(e){var t=this;if(e="object"===(void 0===e?"undefined":_typeof(e))?e:{},e.success=e.hasOwnProperty("success")?e.success:function(){},e.fail=e.hasOwnProperty("fail")?e.fail:function(){},e.cancel=e.hasOwnProperty("cancel")?e.cancel:function(){},!e.hasOwnProperty("authItem"))return void errorHandler("authItem is undefined");if("string"!=typeof e.authItem)return void errorHandler("authItem is not a string");var r=this,o=setTimeout(function(){t.callNative("callContract",{v:"1.0",plugin:"auth",authItem:e.authItem},function(t){"string"==typeof t&&(t=JSON.stringify(formatJSON(t)));var r=JSON.parse(t);switch(parseInt(r.code)){case 0:e.cancel&&e.cancel(t);break;case 1:e.success&&e.success(t);break;default:e.fail&&e.fail(t)}})},500);this.callNative("deviceInfo",{},function(t){clearTimeout(o);var a=JSON.parse(t),n=a.appName||"",i=a.platform,s=a.version;"blockcityglobal"!==n?r.compareVersion(apis.local[i].callContract,s)?r.compareVersion("2.0.3",s)?r.callNative("callContract",{v:"1.0",plugin:"auth",authItem:e.authItem},function(t){var r=JSON.parse(t);switch(parseInt(r.code)){case 0:e.cancel&&e.cancel(t);break;case 1:e.success&&e.success(t);break;default:e.fail&&e.fail(t)}}):"ios"===i?r.callNative("callContract",{v:"1.0",plugin:"auth",authItem:e.authItem},function(t){"string"==typeof t&&(t=JSON.stringify(formatJSON(t)));var r=JSON.parse(t);switch(parseInt(r.code)){case 0:e.cancel&&e.cancel(t);break;case 1:e.success&&e.success(t);break;default:e.fail&&e.fail(t)}}):r.callNative("callContract",{v:"1.0",plugin:"auth",authItem:e.authItem},function(t){t=decodeURIComponent(JSON.stringify(t)),t=t.replace('"{',"{"),t=t.replace('}"',"}");var r=JSON.parse(t);switch(parseInt(r.code)){case 0:e.cancel&&e.cancel(t);break;case 1:e.success&&e.success(t);break;default:e.fail&&e.fail(t)}}):alert("The current version of the app is too low, please upgrade to the latest version."):r.compareVersion(apis.global[i].callContract,s)?r.callNative("callContract",{v:"1.0",plugin:"auth",authItem:e.authItem},function(t){var r=JSON.parse(t);switch(parseInt(r.code)){case 0:e.cancel&&e.cancel(t);break;case 1:e.success&&e.success(t);break;default:e.fail&&e.fail(t)}}):alert("The current version of the app is too low, please upgrade to the latest version.")})},callContract:function(e){var t=this;if(e="object"===(void 0===e?"undefined":_typeof(e))?e:{},e.success=e.hasOwnProperty("success")?e.success:function(){},e.fail=e.hasOwnProperty("fail")?e.fail:function(){},e.cancel=e.hasOwnProperty("cancel")?e.cancel:function(){},!e.hasOwnProperty("contractName"))return void errorHandler("contractName is undefined");if("string"!=typeof e.contractName)return void errorHandler("contractName is not a string");if(e.hasOwnProperty("amount"))if("object"!==_typeof(e.amount)){if(0!==e.amount)return void errorHandler("amount is not a object")}else{if(!e.amount.hasOwnProperty("amount"))return void errorHandler("amount.amount is undefined");if("number"!=typeof e.amount.amount)return void errorHandler("amount.amount is not a number");if(!e.amount.hasOwnProperty("asset_id"))return void errorHandler("amount.asset_id is undefined");if("string"!=typeof e.amount.asset_id)return void errorHandler("amount.asset_id is not a string")}else e.amount=0;if(!e.hasOwnProperty("methodName"))return void errorHandler("methodName is undefined");if("string"!=typeof e.methodName)return void errorHandler("methodName is not a string");if(!e.hasOwnProperty("methodParams"))return void errorHandler("methodParams is undefined");if("object"!==_typeof(e.methodParams))return void errorHandler("methodParams is not a object");if(e.hasOwnProperty("specifiedAccount")){if("string"!=typeof e.specifiedAccount)return void errorHandler("specifiedAccount is not a string")}else e.specifiedAccount="";var r=this,o=JSON.stringify(e.methodParams),a=JSON.stringify(e.amount),n=setTimeout(function(){var r={contract_name:e.contractName,amount:a,method_name:e.methodName,params:o,specified_account:e.specifiedAccount};e.type&&(r.type=e.type),t.callNative("callContract",r,function(t){"string"==typeof t&&(t=JSON.stringify(formatJSON(t)));var r=JSON.parse(t);switch(parseInt(r.code)){case 0:e.cancel&&e.cancel(t);break;case 1:e.success&&e.success(t);break;default:e.fail&&e.fail(decodeURIComponent(t))}})},500);this.callNative("deviceInfo",{},function(t){clearTimeout(n);var i=JSON.parse(t),s=i.appName||"",c=i.platform,l=i.version;"blockcityglobal"!==s?r.compareVersion(apis.local[c].callContract,l)?r.compareVersion("2.0.3",l)?r.callNative("callContract",{contract_name:e.contractName,amount:a,method_name:e.methodName,params:o,specified_account:e.specifiedAccount},function(t){var r=JSON.parse(t);switch(parseInt(r.code)){case 0:e.cancel&&e.cancel(t);break;case 1:e.success&&e.success(t);break;default:e.fail&&e.fail(decodeURIComponent(t))}}):"ios"===c?r.callNative("callContract",{contract_name:e.contractName,amount:a,method_name:e.methodName,params:o,specified_account:e.specifiedAccount},function(t){"string"==typeof t&&(t=JSON.stringify(formatJSON(t)));var r=JSON.parse(t);switch(parseInt(r.code)){case 0:e.cancel&&e.cancel(t);break;case 1:e.success&&e.success(t);break;default:e.fail&&e.fail(decodeURIComponent(t))}}):r.callNative("callContract",{contract_name:e.contractName,amount:a,method_name:e.methodName,params:o,specified_account:e.specifiedAccount},function(t){t=decodeURIComponent(JSON.stringify(t)),t=t.replace('"{',"{"),t=t.replace('}"',"}");var r=JSON.parse(t);switch(parseInt(r.code)){case 0:e.cancel&&e.cancel(t);break;case 1:e.success&&e.success(t);break;default:e.fail&&e.fail(decodeURIComponent(t))}}):alert("The current version of the app is too low, please upgrade to the latest version."):r.compareVersion(apis.global[c].callContract,l)?r.callNative("callContract",{contract_name:e.contractName,amount:a,method_name:e.methodName,params:o,specified_account:e.specifiedAccount},function(t){var r=JSON.parse(t);switch(parseInt(r.code)){case 0:e.cancel&&e.cancel(t);break;case 1:e.success&&e.success(t);break;default:e.fail&&e.fail(decodeURIComponent(t))}}):alert("The current version of the app is too low, please upgrade to the latest version.")})},checkJsApi:function(e){var t=this,r=e.jsApiList,o=void 0===r?[]:r,a=e.success,n=void 0===a?function(){}:a,i=e.fail,s=void 0===i?function(){}:i;getDeviceInfoSingleInstance.then(function(e){e=JSON.parse(e);var r={},a=e.platform,i=e.version,s="blockcityglobal"===e.appName?"global":"local";try{o.forEach(function(e){r[e]=t.compareVersion(apis[s][a][e],i)})}catch(e){throw e}n(r)}).catch(function(e){s(e)})}},errorHandler=function(e){console.error(JSON.stringify({errMsg:e})),alert(JSON.stringify({errMsg:e}))},getDeviceInfoSingleInstance=new Promise(function(e,t){function r(){var t=new Date;if((n=t-a)>o){clearInterval(i);var r={version:"2.0.0",platform:getMobileOperatingSystem()||"android",appName:"blockcity"};return void e(JSON.stringify(r))}Blockcity.getDeviceInfo(function(t){clearInterval(i),e(t)})}var o=3e3,a=new Date,n=0,i=setInterval(r,1e3)});module.exports=Blockcity;