How to use anchorController method in wpt

Best JavaScript code snippet using wpt

anchor.js

Source:anchor.js Github

copy

Full Screen

1/**2 * Created by jojopoper on 2017/02/27.3 */4var AnchorController = {5 uiViews:{},6 tabPage : [],7 tabPageIcon : [],8 tabPageDiv : [],9 assetListView : null,10 anchorAccId : null,11 assetName : null,12 searchBtnIcon : null,13 errorMsgCxt : null,14 exeMsgCxt : null,15 rmvList : null,16 rmvHashTable : {},17 rmvMsgCxt : null,18 initController : function(){19 this.initStrings();20 this.initView();21 this.initParameters();22 this.threadCheck();23 this.refreshAccInfoClick();24 setInterval(this.threadCheck,40000);25 },26 initStrings : function() {27 if(mLanguage == 'cn') {28 this.uiViews.id_tabs_itm1_text = '添加信任 ';29 this.uiViews.id_tabs_itm2_text = '移除信任 ';30 this.uiViews.id_tabs_itm3_text = '发行资产 ';31 this.uiViews.id_tab1_url_cap = '网址查找';32 this.uiViews.id_tab1_url_memo = '可以通过输入网址后查找网址发行资产;如果已知资产可以在下面直接填写。';33 this.uiViews.id_tab1_anchor_cap = '网关账户ID';34 this.uiViews.id_tab1_anchor_id_memo = '用户自己填写网关的ID信息,或者通过网站查询获取发布资产,在列表中选取对应资产。';35 this.uiViews.id_tab1_asset_name_cap = '资产名称';36 this.uiViews.id_tab1_asset_name_memo = '用户自己填写资产名称,或者通过网站查询获取发布资产,在列表中选取对应资产。';37 this.uiViews.id_confirm_changetrust_btn = '确认添加信任';38 this.uiViews.id_tab2_heading_cap = '选择需要移除的信任';39 this.uiViews.id_confirm_remove_changetrust_confirm_cap = '我已经选择并确认';40 this.uiViews.id_confirm_remove_changetrust_btn_cap = '确认移除信任';41 this.uiViews.err_server_data_invalid = '你的网络连接出现问题或者你所使用的连接已经超时,请从公众号重新发起请求。';42 this.uiViews.err_url_denie = '当前网址访问失败,请重试!';43 this.uiViews.err_url_invalid = '当前网址不存在可用资产信息。';44 this.uiViews.err_invalid_anchor_addr = '输入的信任账户ID不是有效的地址!';45 this.uiViews.err_invalid_anchor_name = '输入的信任资产名称不正确!';46 this.uiViews.err_invalid_operation = '发现当前操作非法,请从正确路径登录账户后重试!';47 this.uiViews.err_Account_not_exist = "当前账户还未激活!";48 this.uiViews.step1_title_cap = '读取当前账户有效性...';49 this.uiViews.step1_account_balance_not_enough = '当前账户余额不足,操作取消。';50 this.uiViews.step2_title_cap = '开始签名发送操作请求...';51 this.uiViews.step2_success = '添加资产成功!';52 this.uiViews.step2_Failure = '添加资产失败!';53 this.uiViews.rmv_anchor_not_select = '请选择需要移除的资产!';54 this.uiViews.step3_success = '移除资产成功!';55 this.uiViews.step3_Failure = '移除资产失败!';56 } else {57 this.uiViews.id_tabs_itm1_text = 'Add Asset ';58 this.uiViews.id_tabs_itm2_text = 'Remove Asset ';59 this.uiViews.id_tabs_itm3_text = 'Make Anchor ';60 this.uiViews.id_tab1_url_cap = 'Domain search';61 this.uiViews.id_tab1_url_memo = 'You can enter domain url to search asset; If you have obtained the exact anchor account id and asset name, you can fill in the following information directly below.';62 this.uiViews.id_tab1_anchor_cap = 'Anchor Account ID';63 this.uiViews.id_tab1_anchor_id_memo = 'If you know the anchor account ID can be filled directly, or through the domain search to query the list of account ids to choose.';64 this.uiViews.id_tab1_asset_name_cap = 'Asset Name';65 this.uiViews.id_tab1_asset_name_memo = 'If you know the anchor asset name can be filled directly, or through the domain search to query the list of assets to choose.';66 this.uiViews.id_confirm_changetrust_btn = 'CONFIRM';67 this.uiViews.id_tab2_heading_cap = 'Choose to remove';68 this.uiViews.id_confirm_remove_changetrust_confirm_cap = 'I have chosen and confirmed';69 this.uiViews.id_confirm_remove_changetrust_btn_cap = 'CONFIRM';70 this.uiViews.err_server_data_invalid = 'Your network connection has problems or your connection has timed out, please restart the request from the subscription.';71 this.uiViews.err_url_denie = 'The URL access denied, please try again later!';72 this.uiViews.err_url_invalid = 'The URL can not find anchor information!';73 this.uiViews.err_invalid_anchor_addr = 'Your enter this anchor account id is invalid stellar format!';74 this.uiViews.err_invalid_anchor_name = 'Your enter this asset name is not invalid!';75 this.uiViews.err_invalid_operation = 'Current Account change trust is illegal operation, please login correctly and try again!';76 this.uiViews.err_Account_not_exist = "The stellar account is not activation!";77 this.uiViews.step1_title_cap = 'Reading current account information ...';78 this.uiViews.step1_account_balance_not_enough = 'Account balance is not enough, operation be canceled!';79 this.uiViews.step2_title_cap = 'Signing and send operation to server...';80 this.uiViews.step2_success = 'Add anchor success!';81 this.uiViews.step2_Failure = 'Add anchor failure!';82 this.uiViews.rmv_anchor_not_select = 'Please select anchor at first!';83 this.uiViews.step3_success = 'Remove anchor success!';84 this.uiViews.step3_Failure = 'Remove anchor failure!';85 }86 },87 initView : function() {88 if(mLanguage == 'cn'){89 $(document).attr("title","资产 - LumenStar");90 } else {91 $(document).attr("title","Anchor - LumenStar");92 }93 this.tabPage[0] = $('#id_tabs_itm1');94 this.tabPage[1] = $('#id_tabs_itm2');95 this.tabPage[2] = $('#id_tabs_itm3');96 this.tabPageIcon[0] = $('#id_tabs_itm1_icon');97 this.tabPageIcon[1] = $('#id_tabs_itm2_icon');98 this.tabPageIcon[2] = $('#id_tabs_itm3_icon');99 this.tabPageDiv[0] = $('#id_tab1');100 this.tabPageDiv[1] = $('#id_tab2');101 this.tabPageDiv[2] = $('#id_tab3');102 this.assetListView = $('#id_tab1_url_asset_select_dd');103 this.anchorAccId = $('#id_tab1_anchor_id_input');104 this.assetName = $('#id_tab1_asset_name_input');105 this.searchBtnIcon = $('#id_tab1_url_search_btn_icon');106 this.errorMsgCxt = $('#id_confirm_error');107 this.exeMsgCxt = $('#id_execute_msg_context');108 this.rmvList = $('#id_tab2_rmv_list');109 this.rmvMsgCxt = $('#id_tab2_execute_context');110 $("#id_tabs_itm1_text")[0].innerText = this.uiViews.id_tabs_itm1_text;111 $("#id_tabs_itm2_text")[0].innerText = this.uiViews.id_tabs_itm2_text;112 $("#id_tabs_itm3_text")[0].innerText = this.uiViews.id_tabs_itm3_text;113 $("#id_tab1_url_cap")[0].innerText = this.uiViews.id_tab1_url_cap;114 $("#id_tab1_url_memo")[0].innerText = this.uiViews.id_tab1_url_memo;115 $("#id_tab1_anchor_cap")[0].innerText = this.uiViews.id_tab1_anchor_cap;116 $("#id_tab1_anchor_id_memo")[0].innerText = this.uiViews.id_tab1_anchor_id_memo;117 $("#id_tab1_asset_name_cap")[0].innerText = this.uiViews.id_tab1_asset_name_cap;118 $("#id_tab1_asset_name_memo")[0].innerText = this.uiViews.id_tab1_asset_name_memo;119 $("#id_confirm_changetrust_btn")[0].innerText = this.uiViews.id_confirm_changetrust_btn;120 $("#id_tab2_heading_cap")[0].innerText = this.uiViews.id_tab2_heading_cap;121 $("#id_confirm_remove_changetrust_confirm_cap")[0].innerText = this.uiViews.id_confirm_remove_changetrust_confirm_cap;122 $("#id_confirm_remove_changetrust_btn_cap")[0].innerText = this.uiViews.id_confirm_remove_changetrust_btn_cap;123 },124 threadCheck : function() {125 if (mUserID == null || mUserID == undefined) {126 if (mLanguage == "cn"){127 parent.location = '../error.html?details='+ encodeURIComponent("用户信息获取失败或者失去和服务器连接!");128 } else {129 parent.location = '../error.html?details='+ encodeURIComponent("Can not read user informations or lost connection with server!");130 }131 return;132 }133 $.ajax({134 url: CurrentServer + '/validation',135 type: 'POST',136 data: 't=refuserinfo&userid=' + encodeURIComponent(mUserID) + '&l=' + mLanguage,137 async : true,138 cache :false,139 success: function(data, status,xhr){140 checkSuccess(data,status,xhr, "../error.html", AnchorController.uiViews.err_server_data_invalid);141 saveKeyDatas();142 },143 error: function (xhr, status, e) {144 errorResponse(xhr, status, e, "../error.html", "Lost connection with server");145 }146 })147 },148 initParameters : function() {149 settype = getUrlParam('settype');150 if(settype =='remove') {151 this.tabClick(2);152 } else {153 this.tabClick(1);154 accid = getUrlParam('accid');155 if(accid != '' && accid != undefined) {156 this.anchorAccId.val(accid);157 }158 assetname = getUrlParam('assetname');159 if(assetname != '' && assetname != undefined) {160 this.assetName.val(assetname);161 }162 }163 },164 tabClick : function (page) {165 for( var idx = 0 ; idx < this.tabPage.length ; idx++) {166 if(idx == page-1) {167 this.tabPage[idx].attr('class','active');168 this.tabPageIcon[idx].attr('class','fa fa-check');169 this.tabPageDiv[idx].css('display','block');170 } else {171 this.tabPage[idx].removeAttr('class');172 this.tabPageIcon[idx].removeAttr('class');173 this.tabPageDiv[idx].css('display','none');174 }175 }176 },177 scanQRcode : function () {178 wx.scanQRCode({179 needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,180 scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有181 success: function (res) {182 var result = AnchorController.splitAnchorAsset(res.resultStr);183 if(result.aid != '' && result.aname != '') {184 AnchorController.anchorAccId.val(result.aid);185 AnchorController.assetName.val(result.aname);186 } else {187 AnchorController.anchorAccId.val(res.resultStr);188 }189 }190 });191 },192 appendAsset: function(assetname) {193 appInfo = '<div class="radio" style="word-wrap: break-word; word-break: break-all"><label><input type="radio" name="optionsRadios" onclick="AnchorController.changeAssetInfoClick(\''+ assetname +'\')">' + assetname + '</label></div>';194 this.assetListView[0].innerHTML = this.assetListView[0].innerHTML + appInfo;195 },196 changeAssetInfoClick : function(str) {197 ret = this.splitAnchorAsset(str);198 this.anchorAccId.val(ret.aid);199 this.assetName.val(ret.aname);200 },201 makeAnchorAsset : function(aid, aname) {202 return aname + ' - ' + aid;203 },204 splitAnchorAsset : function(str) {205 ret = {206 aid: '',207 aname: '',208 };209 index = str.lastIndexOf(' - ');210 if(index > 0) {211 ret.aname = str.substr(0,index);212 ret.aid = str.substring(index+3)213 }214 return ret215 },216 searchUrlBtnClick : function() {217 if(this.searchBtnIcon.attr('class') == 'fa fa-spinner fa-pulse fa-fw') {218 return;219 }220 this.searchBtnIcon.attr('class', 'fa fa-spinner fa-pulse fa-fw');221 this.assetListView[0].innerHTML = '';222 urlheader = $('#id_tab1_url_header')[0].innerText;223 domainurl = $('#id_tab1_url_input').val();224 if(domainurl == undefined || domainurl == '') {225 this.searchBtnIcon.attr('class', 'fa fa-search');226 return;227 }228 this.searchUrlExecute(urlheader + domainurl,1)229 },230 searchUrlExecute : function(baseurl,cnter) {231 $.ajax({232 url: baseurl + '/.well-known/stellar.toml',233 type: 'GET',234 async : true,235 cache :false,236 success: function(data, status,xhr){237 assetArray = AnchorController.resovleTomlContext(data);238 cnter = 2;239 if(assetArray.length == 0) {240 AnchorController.assetListView[0].innerHTML = '<p style="color: red;">' + AnchorController.uiViews.err_url_invalid + '</p>';241 } else {242 for(var idx = 0 ; idx < assetArray.length ; idx++) {243 AnchorController.appendAsset(AnchorController.makeAnchorAsset(assetArray[idx].aid,assetArray[idx].aname));244 }245 }246 },247 error: function (xhr, status, e) {248 if(cnter == 2) {249 AnchorController.assetListView[0].innerHTML = '<p style="color: red;">' + AnchorController.uiViews.err_url_denie + '</p>';250 } else {251 urlheadbtn = $('#id_tab1_url_header')[0];252 if(urlheadbtn.innerText == 'http://') {253 urlheadbtn.innerText='https://'254 } else {255 urlheadbtn.innerText='http://'256 }257 AnchorController.searchUrlExecute(urlheadbtn.innerText + $('#id_tab1_url_input').val(),2);258 }259 },260 complete: function() {261 if(cnter == 2) {262 AnchorController.searchBtnIcon.attr('class', 'fa fa-search');263 }264 }265 });266 },267 resovleTomlContext : function(tomlDatas) {268 tdatas = tomlDatas;269 result = [];270 var index = tdatas.indexOf('[[CURRENCIES]]');271 var iret = 0;272 while(index >= 0) {273 result[iret] = {};274 tmpIndex = tdatas.indexOf('[[CURRENCIES]]',index+1);275 if(tmpIndex > 0) {276 subStr = tdatas.substring(index,tmpIndex);277 } else {278 subStr = tdatas.substring(index);279 }280 result[iret].aname = subStr.match(/code=\"(\w*)\"/)[1];281 result[iret].aid = subStr.match(/issuer=\"(\w*)\"/)[1];282 iret++;283 index = tmpIndex;284 }285 return result286 },287 checkAnchorAddress : function(p) {288 anchorAddress = this.anchorAccId.val();289 if(anchorAddress == null || anchorAddress == "" || anchorAddress == undefined) {290 return null;291 }292 if(StellarSdk.Keypair.isValidPublicKey(anchorAddress)){293 p.anchorAddr = anchorAddress;294 return p;295 }296 return null;297 },298 clearErrorMsg : function() {299 this.errorMsgCxt.css('display','none');300 },301 setErrorMsg : function(emsg) {302 this.errorMsgCxt.css('display','block');303 this.errorMsgCxt[0].innerText = emsg;304 },305 clearMsgContext : function() {306 this.exeMsgCxt.css('display','none');307 this.exeMsgCxt[0].innerText = '';308 },309 appendMsgContext : function(msg) {310 this.exeMsgCxt.css('display','block');311 this.exeMsgCxt[0].innerText = this.exeMsgCxt[0].innerText + '\r\n ' + msg;312 },313 getChangeTrustOperation : function(p, isRemove) {314 if(isRemove) {315 return StellarSdk.Operation.changeTrust({316 asset: new StellarSdk.Asset(p.anchorName, p.anchorAddr),317 limit: '0',318 source: p.srcAddr319 });320 }321 return StellarSdk.Operation.changeTrust({322 asset: new StellarSdk.Asset(p.anchorName, p.anchorAddr),323 source: p.srcAddr324 });325 },326 addConfirmClick : function() {327 if(mAddress == '' || mAddress == undefined || mKey1 == '' || mKey1 == undefined) {328 errorResponse(null, null, '', "../error.html", this.uiViews.err_invalid_operation);329 return;330 }331 this.clearErrorMsg();332 this.clearMsgContext();333 var operaInfo = {334 anchorAddr: '',335 anchorName: '',336 srcAddr : mAddress,337 skey : mKey1338 };339 operaInfo = this.checkAnchorAddress(operaInfo);340 if(operaInfo == null) {341 this.setErrorMsg(this.uiViews.err_invalid_anchor_addr);342 return;343 }344 if(this.assetName.val() == '' || this.assetName.val() == null || this.assetName.val() == undefined) {345 this.setErrorMsg(this.uiViews.err_invalid_anchor_name);346 return;347 }348 operaInfo.anchorName = this.assetName.val();349 ctBtnIcon = $('#id_confirm_changetrust_btnIcon');350 if(ctBtnIcon.attr('class') == 'fa fa-spinner fa-pulse fa-fw') {351 return;352 }353 ctBtnIcon.attr('class','fa fa-spinner fa-pulse fa-fw');354 setStellarNetwork("LIVE");355 this.Step1(operaInfo,ctBtnIcon, 2);356 /* for test in test net357 GBEVGGCOFHH2ERVCKSZ73WBBEXG2AKWNCHPRGVVLQFUHHVE5L2CFDRN5358 SATQI7CQR6AWRUADWP62ELHHJHAUCGHO2NIBH3DXF3LM36MJG7GOQIXQ359 GC4BKCKTTHQYG4FYE6VBS6WZ2TYFRGHRNYRYT7SEH3ALAIAB7Z6CBIP6360 SDTYDBNVVGH4EEPRXUNGWLZUZVOF4RW2AL6QZYZ4A5C5PZKKZEQT3ISZ361 * */362 },363 // 检查当前账户是否可用364 Step1 : function(p,btnicon, toStep) {365 if(toStep == 2) {366 AnchorController.appendMsgContext(AnchorController.uiViews.step1_title_cap);367 } else if(toStep == 3) {368 AnchorController.appendRvmMsg(AnchorController.uiViews.step1_title_cap);369 }370 getUrl = StellarCurrentNetworkUrl + StellarAccounts + '/' + p.srcAddr;371 $.ajax({372 url: getUrl,373 dataType: 'json',374 cache :false,375 async : true,376 success: function(data, status, xhr) {377 if(data.balances != null && data.sequence != null) {378 accInfo = AccountInfoDecode(data);379 switch (toStep) {380 case 0:381 {382 for(var idx = 1 ; idx < accInfo.Credits.length ; idx++) {383 AnchorController.appendRemoveAssetList(AnchorController.makeAnchorAsset(accInfo.Credits[idx].issuer,accInfo.Credits[idx].asset_code))384 }385 }386 break;387 case 2:388 {389 p.sequence = accInfo.Sequence;390 if (accInfo.LumensBalance > 30){391 AnchorController.Step2(p, btnicon);392 }else{393 AnchorController.appendMsgContext(AnchorController.uiViews.step1_account_balance_not_enough);394 btnicon.attr('class','fa fa-check-circle-o');395 }396 }397 break;398 case 3:399 {400 p.sequence = accInfo.Sequence;401 if (accInfo.LumensBalance > 20){402 AnchorController.Step3(p, btnicon);403 }else{404 AnchorController.appendRvmMsg(AnchorController.uiViews.step1_account_balance_not_enough);405 btnicon.attr('class','fa fa-check-circle-o');406 }407 }408 break;409 }410 } else {411 if(toStep == 2) {412 AnchorController.setErrorMsg(AnchorController.uiViews.err_Account_not_exist);413 btnicon.attr('class','fa fa-check-circle-o');414 } else if(toStep == 3) {415 AnchorController.appendRvmMsg(AnchorController.uiViews.err_Account_not_exist);416 btnicon.attr('class','fa fa-check-circle-o');417 }418 }419 },420 error: function(xhr, status, e) {421 if(toStep == 2) {422 if(xhr.status == 404 && xhr.statusText == 'Not Found') {423 AnchorController.setErrorMsg(AnchorController.uiViews.err_Account_not_exist);424 } else {425 AnchorController.setErrorMsg(e);426 }427 btnicon.attr('class','fa fa-check-circle-o');428 } else if(toStep == 3) {429 if(xhr.status == 404 && xhr.statusText == 'Not Found') {430 AnchorController.appendRvmMsg(AnchorController.uiViews.err_Account_not_exist);431 } else {432 AnchorController.appendRvmMsg(e);433 }434 btnicon.attr('class','fa fa-check-circle-o');435 }436 },437 complete: function() {438 if(toStep == 0) {439 btnicon.attr('class','fa fa-refresh fa-2x fa-pull-right');440 }441 }442 });443 },444 // 发送change trust业务到网络445 Step2 : function(p, btnicon) {446 AnchorController.appendMsgContext(AnchorController.uiViews.step2_title_cap);447 ctOpera = AnchorController.getChangeTrustOperation(p,false);448 trans = new StellarSdk.TransactionBuilder(new StellarSdk.Account(p.srcAddr, p.sequence));449 trans.addOperation(ctOpera);450 trans = trans.build();451 uencKey = TransDecrypt(mKey0.substr(0,16), p.skey, true);452 trans.sign(StellarSdk.Keypair.fromSeed(uencKey));453 uencKey = '';454 base64 = trans.toEnvelope().toXDR().toString("base64");455 urlpost = StellarCurrentNetworkUrl + StellarTransactions;456 $.ajax({457 url: urlpost,458 type: 'POST',459 data: 'tx=' + encodeURIComponent(base64),460 async : true,461 cache :false,462 success: function(data, status,xhr){463 AnchorController.appendMsgContext(AnchorController.uiViews.step2_success);464 },465 error: function (xhr, status, e) {466 AnchorController.setErrorMsg(AnchorController.uiViews.step2_Failure);467 AnchorController.setErrorMsg(xhr.responseText);468 },469 complete: function() {470 btnicon.attr('class','fa fa-check-circle-o');471 }472 })473 },474 // 发送取消change trust业务到网络475 Step3 : function(p, btnicon) {476 AnchorController.appendRvmMsg(AnchorController.uiViews.step2_title_cap);477 trans = new StellarSdk.TransactionBuilder(new StellarSdk.Account(p.srcAddr, p.sequence));478 for(var idx = 0; idx < p.anchorAddr.length; idx++){479 rmctOpera = AnchorController.getChangeTrustOperation({anchorAddr: p.anchorAddr[idx], anchorName: p.anchorName[idx]},true);480 trans.addOperation(rmctOpera);481 }482 trans = trans.build();483 uencKey = TransDecrypt(mKey0.substr(0,16), p.skey, true);484 trans.sign(StellarSdk.Keypair.fromSeed(uencKey));485 uencKey = '';486 base64 = trans.toEnvelope().toXDR().toString("base64");487 urlpost = StellarCurrentNetworkUrl + StellarTransactions;488 $.ajax({489 url: urlpost,490 type: 'POST',491 data: 'tx=' + encodeURIComponent(base64),492 async : true,493 cache :false,494 success: function(data, status,xhr){495 AnchorController.appendRvmMsg(AnchorController.uiViews.step3_success);496 setTimeout(AnchorController.refreshAccInfoClick,1000);497 },498 error: function (xhr, status, e) {499 AnchorController.appendRvmMsg(AnchorController.uiViews.step3_Failure);500 AnchorController.appendRvmMsg(xhr.responseText);501 },502 complete: function() {503 btnicon.attr('class','fa fa-check-circle-o');504 }505 })506 },507 refreshAccInfoClick : function() {508 headingBtn = $('#id_tab2_heading_btn');509 if(headingBtn.attr('class') == 'fa fa-spinner fa-pulse fa-fw fa-2x fa-pull-right') {510 return;511 }512 headingBtn.attr('class','fa fa-spinner fa-pulse fa-fw fa-2x fa-pull-right');513 AnchorController.rmvList[0].innerHTML = '';514 AnchorController.rmvHashTable = {};515 cfmBtn = $('#id_confirm_remove_ct_cfm')[0];516 cfmBtn.checked = false;517 AnchorController.confirmRemoveClick();518 AnchorController.clearRvmMsg();519 AnchorController.Step1({srcAddr:mAddress},headingBtn, 0);520 },521 appendRemoveAssetList : function(msg) {522 rmInfo = '<div class="checkbox" style="word-wrap: break-word; word-break: break-all">';523 rmInfo += '<label><input type="checkbox" onclick="AnchorController.selectRemoveItem(\''+msg+'\',this)"/>' + msg + '</label>';524 rmInfo += '</div>';525 AnchorController.rmvList[0].innerHTML = AnchorController.rmvList[0].innerHTML + rmInfo;526 AnchorController.rmvHashTable[msg] = false;527 },528 confirmRemoveClick : function() {529 cfmBtn = $('#id_confirm_remove_ct_cfm')[0];530 if(cfmBtn.checked == true) {531 $('#id_confirm_remove_changetrust_btn').removeAttr('disabled')532 } else {533 $('#id_confirm_remove_changetrust_btn').attr('disabled','disabled')534 }535 },536 selectRemoveItem : function(citm, obj) {537 if(obj == null || obj == undefined) {538 return;539 }540 this.rmvHashTable[citm] = obj.checked;541 this.clearRvmMsg();542 },543 appendRvmMsg : function(msg) {544 this.rmvMsgCxt.css('display','block');545 this.rmvMsgCxt[0].innerText = this.rmvMsgCxt[0].innerText + '\r\n ' + msg;546 },547 clearRvmMsg : function() {548 this.rmvMsgCxt.css('display','none');549 this.rmvMsgCxt[0].innerText = '';550 },551 removeAnchorConfirmBtnClick : function() {552 if(mAddress == '' || mAddress == undefined || mKey1 == '' || mKey1 == undefined) {553 errorResponse(null, null, '', "../error.html", this.uiViews.err_invalid_operation);554 return;555 }556 this.clearRvmMsg();557 var operaInfo = {558 anchorAddr: [],559 anchorName: [],560 srcAddr : mAddress,561 skey : mKey1562 };563 for(var ikey in this.rmvHashTable) {564 if(this.rmvHashTable[ikey] == true) {565 rmvItmInfo = this.splitAnchorAsset(ikey);566 operaInfo.anchorAddr[operaInfo.anchorAddr.length] = rmvItmInfo.aid;567 operaInfo.anchorName[operaInfo.anchorName.length] = rmvItmInfo.aname;568 }569 }570 if(operaInfo.anchorAddr.length == 0) {571 this.appendRvmMsg(this.uiViews.rmv_anchor_not_select);572 return;573 }574 rvmBtnIcon = $('#id_confirm_remove_changetrust_btnIcon');575 if(rvmBtnIcon.attr('class') == 'fa fa-spinner fa-pulse fa-fw') {576 return;577 }578 rvmBtnIcon.attr('class','fa fa-spinner fa-pulse fa-fw');579 setStellarNetwork("LIVE");580 this.Step1(operaInfo, rvmBtnIcon, 3)581 }...

Full Screen

Full Screen

anchor.controller.spec.ts

Source:anchor.controller.spec.ts Github

copy

Full Screen

1import { Test, TestingModule } from '@nestjs/testing';2import { AnchorController } from './anchor.controller';3import { AnchorService } from './anchor.service';4import { AnchorLibProvider } from './anchorlib.provider';5const sampleWalletAddress = 'nomatter';6describe('AnchorController', () => {7 let anchorController: AnchorController;8 let anchorService: AnchorService;9 beforeEach(async () => {10 const module: TestingModule = await Test.createTestingModule({11 controllers: [AnchorController],12 providers: [AnchorService, AnchorLibProvider],13 }).compile();14 anchorController = module.get<AnchorController>(AnchorController);15 anchorService = module.get<AnchorService>(AnchorService);16 });17 it('should be defined', () => {18 expect(anchorController).toBeDefined();19 expect(anchorService).toBeDefined();20 });21 describe('getApy', () => {22 it('returned value should have a property apy', async () => {23 const apy = 1;24 jest.spyOn(anchorService, 'getApy').mockImplementation(async () => apy);25 expect(await anchorController.getApy()).toMatchObject({26 apy,27 });28 });29 });30 describe('getCollateralValue', () => {31 it('returned value should have a property collateralValue', async () => {32 const collateralValue = 1;33 jest34 .spyOn(anchorService, 'getCollateralValue')35 .mockImplementation(async () => collateralValue);36 expect(37 await anchorController.getCollateralValue(sampleWalletAddress),38 ).toMatchObject({39 collateralValue,40 });41 });42 it('should throw an error if the wallet address does not exist', async () => {43 const collateralValue = null;44 jest45 .spyOn(anchorService, 'getCollateralValue')46 .mockImplementation(async () => collateralValue);47 await expect(48 anchorController.getBorrowedValue(sampleWalletAddress),49 ).rejects.toThrow();50 });51 });52 describe('getBorrowedValue', () => {53 it('should return number', async () => {54 const borrowedValue = 1;55 jest56 .spyOn(anchorService, 'getBorrowedValue')57 .mockImplementation(async () => borrowedValue);58 expect(59 await anchorController.getBorrowedValue(sampleWalletAddress),60 ).toMatchObject({61 borrowedValue,62 });63 });64 it('should throw an error if the wallet address does not exist', async () => {65 const borrwedValue = null;66 jest67 .spyOn(anchorService, 'getBorrowedValue')68 .mockImplementation(async () => borrwedValue);69 await expect(70 anchorController.getBorrowedValue(sampleWalletAddress),71 ).rejects.toThrow();72 });73 });74 describe('getLtv', () => {75 it('should return number', async () => {76 const fakeValue = 1;77 jest78 .spyOn(anchorService, 'getBorrowLimit')79 .mockImplementation(async () => fakeValue);80 jest81 .spyOn(anchorService, 'getBorrowedValue')82 .mockImplementation(async () => fakeValue);83 jest84 .spyOn(anchorService, 'getLtv')85 .mockImplementation(async () => fakeValue);86 expect(await anchorController.getLtv(sampleWalletAddress)).toMatchObject({87 borrowLimit: fakeValue,88 borrowedValue: fakeValue,89 ltv: fakeValue,90 });91 });92 it('should throw an error if the wallet address does not exist', async () => {93 const fakeValue = null;94 jest95 .spyOn(anchorService, 'getBorrowLimit')96 .mockImplementation(async () => fakeValue);97 jest98 .spyOn(anchorService, 'getBorrowedValue')99 .mockImplementation(async () => fakeValue);100 jest101 .spyOn(anchorService, 'getLtv')102 .mockImplementation(async () => fakeValue);103 await expect(104 anchorController.getLtv(sampleWalletAddress),105 ).rejects.toThrow();106 });107 });...

Full Screen

Full Screen

page-anchor-component.js

Source:page-anchor-component.js Github

copy

Full Screen

1(function() {2 'use strict';3 angular4 .module('editor.ui')5 .component('otusPageAnchor', {6 templateUrl: 'app/editor/ui/page-anchor-item/page-anchor-template.html',7 controller: AnchorController,8 bindings: {9 id: '<'10 }11 });12 AnchorController.$inject = [13 '$element',14 'PageAnchorService'15 ];16 function AnchorController($element, PageAnchorService) {17 var self = this;18 self.$onInit = function() {19 $element.attr('tabindex', -1);20 PageAnchorService.anchorRegistry($element);21 };22 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3}, function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log('Test status: ' + data.statusText);8 console.log('Test ID: ' + data.data.testId);9 console.log('Test URL: ' + data.data.summary);10 console.log('First View: ' + data.data.runs[1].firstView);11 console.log('Repeat View: ' + data.data.runs[1].repeatView);12 }13});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3 lighthouseConfig: {4 settings: {5 },6 },7}, function(err, data) {8 if (err) return console.log(err);9 console.log(data.data.median.firstView);10 console.log(data.data.median.firstView.SpeedIndex);11 console.log(data.data.median.firstView.LighthousePerformance);12 console.log(data.data.median.firstView.LighthouseSeo);13 console.log(data.data.median.firstView.videoFrames);14 console.log(data.data.median.firstView.videoCPU);15 console.log(data.data.median.firstView.videoSpeed);16 console.log(data.data.median.firstView.videoScreenShot);17 console.log(data.data.median.firstView.video);18 console.log(data.data.median.firstView.videoURL);19 console.log(data.data.median.firstView.videoViewable);20 console.log(data.data.median.firstView.SpeedIndex);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('localhost');3var options = {4};5wpt.runTest(url, options, function(err, data) {6 if (err) return console.error(err);7 console.log(data);8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('localhost');11var options = {12};13wpt.runTest(url, options, function(err, data) {14 if (err) return console.error(err);15 console.log(data);16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var wpt = new wpt('API_KEY');3wpt.getAnchorController(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var WebPageTest = require('webpagetest');11var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');12var wpt = new wpt('API_KEY');13wpt.getAnchorController(function(err, data) {14 if (err) {15 console.log(err);16 } else {17 console.log(data);18 }19});20var wpt = require('./wpt.js');21var wpt = new wpt('API_KEY');22wpt.getAnchorController(function(err, data) {23 if (err) {24 console.log(err);25 } else {26 console.log(data);27 }28});29var WebPageTest = require('webpagetest');30var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');31var wpt = new wpt('API_KEY');32wpt.getAnchorController(function(err, data) {33 if (err) {34 console.log(err);35 } else {36 console.log(data);37 }38});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptAPI = require('wpt-api');2var anchorController = new wptAPI.anchorController();3anchorController.getAnchorList(function(error, response, context) {4 console.log(response);5});6anchorController.getAnchorListByPageId(1, function(error, response, context) {7 console.log(response);8});9anchorController.getAnchorListByAnchorId(1, function(error, response, context) {10 console.log(response);11});12anchorController.getAnchorListByAnchorText('test', function(error, response, context) {13 console.log(response);14});15anchorController.getAnchorListByAnchorTextAndPageId('test', 1, function(error, response, context) {16 console.log(response);17});18anchorController.getAnchorListByAnchorTextAndPageUrl('test', 'test', function(error, response, context) {19 console.log(response);20});21anchorController.getAnchorListByAnchorTextAndPageUrlAndAnchorId('test', 'test', 1, function(error, response, context) {22 console.log(response);23});24anchorController.getAnchorListByPageIdAndAnchorId(1, 1, function(error, response, context) {25 console.log(response);26});27anchorController.getAnchorListByPageIdAndAnchorText(1, 'test', function(error, response, context) {28 console.log(response);29});30anchorController.getAnchorListByPageIdAndAnchorTextAndAnchorId(1, 'test', 1, function(error, response, context) {31 console.log(response);32});33anchorController.getAnchorListByPageUrl('test', function(error, response, context) {34 console.log(response);35});36anchorController.getAnchorListByPageUrlAndAnchorId('test', 1, function(error, response, context) {37 console.log(response);38});39anchorController.getAnchorListByPageUrlAndAnchorText('test', 'test', function(error, response, context) {40 console.log(response);41});42anchorController.getAnchorListByPageUrlAndAnchorTextAndAnchorId('test', 'test', 1, function(error, response, context) {43 console.log(response);44});

Full Screen

Using AI Code Generation

copy

Full Screen

1var anchorController = require('./controllers/wptController').anchorController;2anchor.then(function(result){3 console.log(result);4});5function anchorController(url, selector) {6 var anchor = new Promise(function(resolve, reject) {7 wpt.runTest(url, {8 videoParams: {9 },10 }, function(err, data) {11 if (err) {12 console.error(err);13 reject(err);14 } else {15 var result = data.data.median.firstView[selector];16 resolve(result);17 }18 });19 });20 return anchor;21}22module.exports = {23}24 at Object.<anonymous> (test.js:3:23)25 at Module._compile (module.js:413:34)26 at Object.Module._extensions..js (module.js:422:10)27 at Module.load (module.js:357:32)28 at Function.Module._load (module.js:314:12)29 at Function.Module.runMain (module.js:447:10)30 at startup (node.js:139:18)

Full Screen

Using AI Code Generation

copy

Full Screen

1 .then(function(result) {2 console.log(result);3 })4 .catch(function(err) {5 console.log(err);6 });

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful