import"./chunks/modulepreload-polyfill-B5Qt9EMX.js";const a=t=>document.getElementById(t),u=a("import-form"),l=a("wallet-image"),r=a("image-password"),s=a("import-button"),i=a("notice");m("status").then(t=>{const e=t;a("selected-network").textContent=e.networkName}).catch(t=>{i.textContent=d(t)});function w(t){let e="";for(let o=0;o<t.length;o+=32768)e+=String.fromCharCode(...t.subarray(o,o+32768));return btoa(e)}function d(t){return t instanceof Error?t.message:String(t)}async function m(t,e={}){const n=await chrome.runtime.sendMessage({type:t,...e});if(!(n!=null&&n.ok))throw new Error((n==null?void 0:n.error)??"Wallet request failed.");return n.result}l.addEventListener("change",()=>{var t,e;a("image-file-name").textContent=((e=(t=l.files)==null?void 0:t[0])==null?void 0:e.name)??"Choose wallet image",i.textContent=""});a("reveal-password").addEventListener("click",t=>{const e=t.currentTarget,n=r.type==="text";r.type=n?"password":"text",e.textContent=n?"Show":"Hide"});u.addEventListener("submit",t=>{t.preventDefault(),(async()=>{var c;const e=(c=l.files)==null?void 0:c[0];if(!e)throw new Error("Choose a wallet image.");if(!r.value.trim())throw new Error("Enter the wallet image encryption key.");i.textContent="",s.disabled=!0,s.textContent="Importing wallet...";const n=w(new Uint8Array(await e.arrayBuffer())),o=await m("import-wallet-image",{imageBase64:n,imagePassword:r.value,password:r.value});r.value="",a("imported-address").textContent=o.address??"Imported wallet",a("import-panel").hidden=!0,a("success-panel").hidden=!1})().catch(e=>{i.textContent=d(e),s.disabled=!1,s.textContent="Import wallet"})});a("close-page").addEventListener("click",()=>window.close());
