(async()=>{const e=(e,t)=>new Promise(((o,i)=>{fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:t,mode:"cors"}).then((e=>{e.status>=200&&e.status<=299?e.json().then((e=>{o(e)})):i(new Error)})).catch((e=>i(e)))})),t=t=>e("https://dapp.isotopic.io/api/v1/oauth/client/check-code",JSON.stringify({one_time_code:t})),o=(t,o,i)=>e("https://dapp.isotopic.io/api/v1/oauth/client/login",JSON.stringify({username:t,password:o,one_time_code:i}));$((()=>{const e=e=>$(`#one-time-code-inp-${e<0?0:e>5?5:e}`);$(".one-time-code-inp").val("");let i=$("#message-bottom").text();const a=$("#login-page-container"),n=$("#code-page-container"),r=$("#final-page-container"),s=$("#inp-username"),c=$("#inp-pass");let l="";function p(){n.show(),a.hide(),r.hide(),h(),u(!0),$("body").css("background","url(https://dapp.isotopic.io/media/game-characters-isotopic.jpg)")}function d(t){f(i,!1);let o=t?.originalEvent?.clipboardData?.getData("text")??$(this).val(),a=null!=t?.originalEvent?.clipboardData?.getData("text"),n=parseInt($(this).attr("code-index"));if([8,46].includes(t.keyCode)){for(let t=n;t<6;t++)5!=t?e(t).val(e(t+1).val()):e(5).val("");return e(n-1>=0?n-1:0).focus(),void g()}let r=o.replace(/[^0-9]/g,"");if(r.length>1&&a){let t=0;for(let o=n;o<6;o++)t{try{f(i,!1)}catch{}}),3500)}function f(e,t=!1){$("#message-bottom").text(e),t?$("#message-bottom").css("color","red"):$("#message-bottom").css("color","unset")}async function g(){let o=!0,i="";for(let t=0;t<6;t++){let a=e(t).val();""==a&&(o=!1),i+=a}if(!o)return;u(!1);let s=await t(i);return"fail"==s.result?(f("Incorrect Code. Check again, or request a new code from the app you are trying to connect.",!0),h(),void u(!0)):"fail"==s.app_details.result?(f("Incorrect code. The app you are trying to connect to is not registered at Isotopic.",!0),h(),void u(!0)):(l=i,n.hide(),a.show(),r.hide(),$("#submit-diff-code-button").click((()=>{p()})),m(),b(""),v(!0),$("body").css("background",`url(https://dapp.isotopic.io/api/v1/store/files/${s.app_details.id}/page_images/?index=0)`),$(".header-app-title").text("Authenticate App"),void $(".header-app-paragraph").html(`${s.app_details.title} is requesting to authenticate your Isotopic Account. Only login here if you requested this authentication. The app does not get access to any of your private account information.`))}function m(){s.val(""),c.val("")}function v(e){s.prop("disabled",!e),c.prop("disabled",!e)}function b(e){$("#login-error-p").text(e)}$("#login-button").click((async()=>{let e=s.val(),t=c.val();if(""==e||""==t)return void b("Not all fields are set.");v(!1);let i=await o(e,t,l);if("fail"==i.result)return m(),b(i.error),void v(!0);n.hide(),a.hide(),r.show()})),p(),$(".one-time-code-inp").keyup(d),$(".one-time-code-inp").on("paste",d)}))})();