-
Notifications
You must be signed in to change notification settings - Fork 6
/
478.031049bb71f8ceae72d9.js
1 lines (1 loc) · 27.7 KB
/
478.031049bb71f8ceae72d9.js
1
"use strict";(this.webpackChunkRuDEX3_light=this.webpackChunkRuDEX3_light||[]).push([[478],{10125:(e,t,n)=>{n.d(t,{Z:()=>I});var a=n(67294),s=n(89449),l=n(43393),r=n.n(l),c=n(94184),i=n.n(c),o=n(112),m=n.n(o),u=n(52531),p=n(79618),h=n(44034),d=n(54742),_=n(33983),g=n(21019),y=n(58074),E=n.n(y);class b extends a.Component{UNSAFE_componentWillReceiveProps(e){e.claim_account_name&&this.onClaimAccount(e.claim_account_name,e.checked)}render(){if(void 0===this.props.balances||!this.props.total_by_account_asset.size)return a.createElement("div",null);let e=-1;return a.createElement("div",null,a.createElement("table",{className:"table"},a.createElement("thead",null,a.createElement("tr",null,a.createElement("th",null),a.createElement("th",{style:{textAlign:"center"}},a.createElement(E(),{content:"wallet.unclaimed"})),a.createElement("th",{style:{textAlign:"center"}},a.createElement(E(),{content:"wallet.unclaimed_vesting"})),a.createElement("th",{style:{textAlign:"center"}},a.createElement(E(),{content:"account.name"})))),a.createElement("tbody",null,this.props.total_by_account_asset.map(((t,n)=>a.createElement("tr",{key:++e},a.createElement("td",null,a.createElement("input",{type:"checkbox",checked:!!this.props.checked.get(e),onChange:this.onCheckbox.bind(this,e,t.balances)})),a.createElement("td",{style:{textAlign:"right"}},t.unclaimed?a.createElement(g.Z,{color:"info",amount:t.unclaimed,asset:n.get(1)}):null),a.createElement("td",{style:{textAlign:"right"}},t.vesting.unclaimed?a.createElement("div",null,a.createElement(g.Z,{color:"info",amount:t.vesting.unclaimed,hide_asset:!0,asset:n.get(1)}),a.createElement("span",null," of "),a.createElement(g.Z,{color:"info",amount:t.vesting.total,asset:n.get(1)})):null),a.createElement("td",null," ",n.get(0)," ")))).toArray())))}onCheckbox(e,t){let n=this.props.checked;n=n.get(e)?n.delete(e):n.set(e,t),_.Z.setSelectedBalanceClaims(n)}onClaimAccount(e,t){if(t.size)return;let n=-1;this.props.total_by_account_asset.forEach(((a,s)=>{n++,s.get(0)===e&&(a.unclaimed||a.vesting.unclaimed)&&(t=t.set(n,a.balances))})),t.size&&_.Z.setSelectedBalanceClaims(t)}}const k=b=(0,s.$)(b,{listenTo:()=>[d.Z],getProps(){let e=d.Z.getState(),{balances:t,address_to_pubkey:n}=e,a=p.Z.getState().keys,s=r().Map().asMutable();return t&&(e.total_by_account_asset=t.groupBy((e=>{let t="",l=n.get(e.owner),c=a.get(l);c&&c.import_account_names&&(t=c.import_account_names.join(", "));let i=Math.ceil(((e,t)=>{let n=s.get(e);return n||(n=r().Set().asMutable(),s.set(e,n)),n.add(t),n.size})(r().List([t,e.balance.asset_id]),e.owner)/60);return r().List([t,e.balance.asset_id,i])})).map((e=>e.reduce(((e,t)=>(t.public_key_string=n.get(t.owner),e.balances=e.balances.add(t),null!=t.vested_balance?(e.vesting.unclaimed+=Number(t.vested_balance.amount),e.vesting.total+=Number(t.balance.amount)):e.unclaimed+=Number(t.balance.amount),e)),{unclaimed:0,vesting:{unclaimed:0,total:0},balances:r().Set()}))).sortBy((e=>e))),e}});var f=n(28969),v=n(32793),w=n(23037),C=n(47449),S=n(82267),x=n(45697),A=n.n(x);class N extends a.Component{static propTypes={accounts:w.Z.ChainAccountsList.isRequired,onChange:A().func.isRequired};render(){var e=this.props.accounts.filter((e=>!!e)).filter((e=>v.Z.isMyAccount(e))).map((e=>e.get("name"))).sort();return a.createElement("span",null,a.createElement(C.Z,{onChange:this.onAccountSelect.bind(this),account_names:e,center:!0}))}onAccountSelect(e){this.props.onChange(e)}}const Z=(0,S.Z)(N);var B=n(76660);class K extends a.Component{UNSAFE_componentWillMount(){let e=p.Z.getState().keys.keySeq();_.Z.setPubkeys(e),this.existing_keys=e}UNSAFE_componentWillReceiveProps(e){let t=p.Z.getState().keys.keySeq();t.equals(this.existing_keys)||(this.existing_keys=t,_.Z.setPubkeys(t))}render(){if(!this.props.account_refs.size)return a.createElement("div",null,a.createElement("h5",null,a.createElement(E(),{content:"wallet.no_balance"})));if(this.props.loading)return a.createElement("div",null,a.createElement("br",null),a.createElement("h5",null,a.createElement(E(),{content:"wallet.loading_balances"}),"…"),a.createElement("br",null),a.createElement(u.Z,{type:"three-bounce"}));if(!this.props.balances||!this.props.balances.size)return a.createElement("div",null,a.createElement("br",null),a.createElement("h5",null,a.createElement(E(),{content:"wallet.no_balance"})));let e=this.props.selected_balances.size&&this.props.claim_account_name,t=e?` (${this.props.claim_account_name})`:null;return a.createElement("div",null,a.createElement("div",{className:"content-block center-content"},a.createElement("h3",{className:"no-border-bottom"},a.createElement(E(),{content:"wallet.claim_balances"}))),a.createElement("div",{className:"grid-block vertical"},a.createElement("div",{className:"grid-content",style:{overflowY:"hidden !important"}},a.createElement("div",{className:"full-width-content center-content"},a.createElement(Z,{key:this.props.balances,accounts:r().List(this.props.account_refs),onChange:this.onClaimAccountChange.bind(this)})),a.createElement("br",null)),a.createElement("br",null),a.createElement(k,null)),a.createElement("br",null),a.createElement("br",null),a.createElement("div",{className:i()("button success",{disabled:!e}),onClick:this.onClaimBalance.bind(this)},a.createElement(E(),{content:"wallet.claim_balance"}),t),a.createElement("div",{className:"button cancel",onClick:this.onBack.bind(this)},a.createElement(E(),{content:"wallet.cancel"})))}onBack(e){e.preventDefault(),window.history.back()}onClaimAccountChange(e){_.Z.claimAccountChange(e)}onClaimBalance(){f.Z.importBalance(this.props.claim_account_name,this.props.selected_balances,!0).catch((e=>{console.error("claimBalance",e);let t=e;try{t=e.data.message}catch(e){}throw B.Notification.error({message:m().translate("notifications.balance_claim_error",{error_msg:t})}),e}))}}const I=K=(0,s.$)(K,{listenTo:()=>[d.Z,h.Z,p.Z],getProps(){let e=d.Z.getState();return e.account_refs=h.Z.getAccountRefs(),e}})},30478:(e,t,n)=>{n.r(t),n.d(t,{ExistingAccountOptions:()=>L,default:()=>H});var a=n(67294),s=n(73727),l=n(89449),r=n(39238),c=n(10125),i=n(58074),o=n.n(i),m=n(5977),u=n(21705),p=n(43393),h=n.n(p),d=n(94184),_=n.n(d),g=n(57296);const y=g.Z.createActions(class{setBrainkey(e){return e}});var E=n(30806),b=n(16912);class k{static instances=new Map;static getInstance(e){var t=k.instances.get(e);t||(t=g.Z.createStore(f,"BrainkeyStore"),k.instances.set(e,t));var n=e+" subscribed_instance";if(!k.instances.get(n)){var a=t.chainStoreUpdate.bind(t);E.ChainStore.subscribe(a),k.instances.set(n,a)}return t}static closeInstance(e){var t=k.instances.get(e);if(!t)throw new Error("unknown instance "+e);var n=e+" subscribed_instance",a=k.instances.get(n);k.instances.delete(n),E.ChainStore.unsubscribe(a),t.clearCache()}}class f extends b.Z{constructor(){super(),this.clearCache(),this.bindListeners({onSetBrainkey:y.setBrainkey}),this._export("inSync","chainStoreUpdate","clearCache")}clearCache(){this.state={brnkey:"",account_ids:h().Set()},this.derived_keys=new Array,this.account_ids_by_key=null}onSetBrainkey(e){this.clearCache(),this.setState({brnkey:e}),this.deriveKeys(e),this.chainStoreUpdate()}inSync(){return this.derived_keys.forEach((e=>{if(w(e))return!1})),!0}chainStoreUpdate(){this.derived_keys.length&&this.account_ids_by_key!==E.ChainStore.account_ids_by_key&&(this.account_ids_by_key=E.ChainStore.account_ids_by_key,this.updateAccountIds())}deriveKeys(e=this.state.brnkey){var t,n,a=this.derived_keys.length,s=(t=E.key.get_brainPrivateKey(e,a),n=t.toPublicKey().toPublicKeyString(),{private_key:t,public_string:n});this.derived_keys.push(s),this.derived_keys.length<10&&this.deriveKeys(e)}updateAccountIds(){var e=h().Set().withMutations((e=>{this.derived_keys.forEach((t=>{return n=t.public_string,void((a=E.ChainStore.getAccountRefsOfKey(n))&&a.forEach((t=>{e.add(t)})));var n,a}))}));e.equals(this.state.account_ids)||(this.state.account_ids=e,this.setState({account_ids:e}))}}var v,w=e=>void 0===E.ChainStore.getAccountRefsOfKey(e.public_string),C=n(82267),S=n(23037),x=n(45697),A=n.n(x);class N extends a.Component{static propTypes={onChange:A().func.isRequired};constructor(){super(),this.state={brnkey:"",loading:!0}}UNSAFE_componentWillMount(){fetch("dictionary.json").then((e=>e.json().then((e=>{v=new Set(e.en.split(",")),this.setState({loading:!1})})))).catch((e=>{console.log("fetch dictionary error:",e)}))}_checkBrainKey(){let e,t=this.state.brnkey.split(" "),n=[];t.forEach(((e,t)=>{if(""===e)return;let s=e.toLowerCase();s=s.match(/[a-z]+/),null===s||v.has(s[0])?n.push(a.createElement("span",{key:t,style:{padding:"1px",margin:"1px"}},e)):n.push(a.createElement(Z,{key:t},e))}));let s=!0,l=!0;return n.length>0&&(this.state.brnkey.length<50?(e=this.state.brnkey.length+" characters (50 minimum)",l=!1):n.length<16?e=n.length+" words (16 recommended)":(e=n.length+" words",s=!1)),{warn:s,valid:l,word_count_label:e,checked_words:n}}render(){if(this.state.loading||!v)return a.createElement("div",{style:{padding:20}},"Fetching dictionary....");let{warn:e,word_count_label:t,checked_words:n}=this._checkBrainKey();return a.createElement("span",{className:""},a.createElement("div",null,a.createElement("textarea",{tabIndex:this.props.tabIndex||1,onChange:this.formChange.bind(this),value:this.state.brnkey,id:"brnkey",style:{height:100,minWidth:450}}),a.createElement("div",{style:{textAlign:"left"},className:"grid-content no-padding no-overflow"},n),this.state.check_digits&&!this.props.hideCheckDigits?a.createElement("div",null,a.createElement("br",null),a.createElement("pre",{className:"no-overflow"},this.state.check_digits," * Check Digits"),a.createElement("br",null)):null,a.createElement("p",null,a.createElement("i",{className:_()({error:e})},t))))}formChange(e){var{id:t,value:n}=e.target;let{valid:a}=this._checkBrainKey();var s={};if(s[t]=n,"brnkey"===t){var l=E.key.normalize_brainKey(n);this.props.onChange(l.length<50?null:l),s.check_digits=l.length<50?null:E.hash.sha1(l).toString("hex").substring(0,4)}this.setState(s),this.props.errorCallback&&this.props.errorCallback(a)}}class Z extends a.Component{render(){return a.createElement("span",{style:{borderBottom:"1px dotted #ff0000",padding:"1px",margin:"1px"}},a.createElement("span",{style:{borderBottom:"1px dotted #ff0000"}},this.props.children))}}var B=n(44015),K=n(50379),I=n(32793);class P extends a.Component{static propTypes={account:S.Z.ChainAccount.isRequired};onCardClick(e){e.preventDefault();let t=this.props.account.get("name");this.props.history.push(`/account/${t}`)}render(){let e=null,t=null,n=!1;if(this.props.account){e=this.props.account.get("name");let s=this.props.account.get("balances");s&&(t=s.map((e=>E.ChainStore.getObject(e).get("balance")?a.createElement("li",{key:e},a.createElement(B.Z,{balance:e})):null)).toArray()),n=I.Z.isMyAccount(this.props.account)}return a.createElement("div",{className:"grid-content account-card",onClick:this.onCardClick.bind(this)},a.createElement("div",{className:"card"+(n?" my-account":"")},a.createElement("h4",{className:"text-center"},e),a.createElement("div",{className:"card-content clearfix"},a.createElement("div",{className:"float-left"},a.createElement(K.Z,{account:e,size:{height:64,width:64}})),a.createElement("ul",{className:"balances"},t))))}}P=(0,C.Z)(P);const T=(0,m.EN)(P),W={listenTo:()=>[k.getInstance("wmc")],getProps:()=>k.getInstance("wmc").getState()};class z extends a.Component{componentWillUnmount(){k.closeInstance("wmc")}render(){return a.createElement("span",null,a.createElement("h3",null,a.createElement(o(),{content:"wallet.brainkey"})),a.createElement(D,null,a.createElement(M,null)))}}const R=z=(0,l.$)(z,W);class M extends a.Component{render(){let e=this.props.brnkey.substring(0,10);return a.createElement("span",null,a.createElement("div",null,a.createElement("span",{className:""},e),"…"),a.createElement("p",null),this.props.account_ids.size?a.createElement(U,{accounts:h().List(this.props.account_ids.toArray())}):a.createElement("h5",null,a.createElement(o(),{content:"wallet.no_accounts"})))}}M=(0,l.$)(M,W);class U extends a.Component{static propTypes={accounts:S.Z.ChainAccountsList.isRequired};render(){let e=(0,u.Z)(this.props.accounts).filter((e=>!!e[1])).map((e=>e[1].get("name"))).sort().map((e=>a.createElement(T,{key:e,account:e})));return a.createElement("span",null,e)}}U=(0,C.Z)(U);class D extends a.Component{constructor(){super(),this.state={brnkey:"",accept:!1}}render(){if(this.state.accept)return a.createElement("span",null,this.props.children);let e=this.state.brnkey&&""!==this.state.brnkey;return a.createElement("span",{className:"grid-container"},a.createElement("div",null,a.createElement(N,{onChange:this.onBrainkeyChange.bind(this)})),a.createElement("div",{className:_()("button success",{disabled:!e}),onClick:this.onAccept.bind(this)},a.createElement(o(),{content:"wallet.accept"})))}onBrainkeyChange(e){this.setState({brnkey:e})}onAccept(){this.setState({accept:!0}),y.setBrainkey(this.state.brnkey)}}var O=n(2407),$=n(81038),j=n(60567);const F={listenTo:()=>[r.Z],getProps:()=>({wallet:r.Z.getState()})};class q extends a.Component{render(){const e=0!=this.props.wallet.wallet_names.count();return a.createElement("div",{className:"grid-container"},a.createElement("div",{className:"grid-content"},a.createElement("div",{className:"content-block center-content"},a.createElement("div",{className:"page-header"},a.createElement("h1",null,a.createElement(o(),{content:"account.welcome",wallet_name:(0,j.w)()})),e?a.createElement("h3",null,a.createElement(o(),{content:"wallet.setup_wallet"})):a.createElement("h3",null,a.createElement(o(),{content:"wallet.create_wallet_backup"}))),a.createElement("div",{className:"content-block"},a.createElement(m.rs,null,a.createElement(m.AW,{exact:!0,path:"/existing-account",component:$.aQ}),a.createElement(m.AW,{exact:!0,path:"/existing-account/import-backup",component:L}),a.createElement(m.AW,{exact:!0,path:"/existing-account/import-keys",component:O.Z}),a.createElement(m.AW,{exact:!0,path:"/existing-account/brainkey",component:R}),a.createElement(m.AW,{exact:!0,path:"/existing-account/balance-claim",component:c.Z})),this.props.children))))}}q=(0,l.$)(q,F);class L extends a.Component{render(){const e=0!=this.props.wallet.wallet_names.count();return a.createElement("span",null,e?null:a.createElement("div",null,a.createElement(s.rU,{to:"existing-account/import-backup"},a.createElement(o(),{content:"wallet.import_backup",wallet_name:(0,j.w)()})),a.createElement("br",null),a.createElement("br",null),a.createElement(s.rU,{to:"existing-account/import-keys"},a.createElement(o(),{content:"wallet.import_bts1"})),a.createElement("br",null),a.createElement("br",null),a.createElement(s.rU,{to:"existing-account/import-keys"},a.createElement(o(),{content:"wallet.create_wallet"})),a.createElement("br",null),a.createElement("hr",null)),e?a.createElement(c.Z,null):null,e?a.createElement("span",null,a.createElement(s.rU,{to:"dashboard"},a.createElement("div",{className:"button outline"},a.createElement(o(),{component:"span",content:"header.dashboard"}))),a.createElement(s.rU,{to:"wallet"},a.createElement("div",{className:"button outline"},a.createElement(o(),{content:"settings.wallets"})))):null)}}L=(0,l.$)(L,F);const H=q},2407:(e,t,n)=>{n.d(t,{Z:()=>I});var a=n(67294),s=n(89449),l=n(94184),r=n.n(l),c=n(30806),i=n(91507),o=n(55420),m=n(79618),u=n(56934),p=n(66879),h=n(52531),d=n(58074),_=n.n(d),g=n(112),y=n.n(g),E=n(10125),b=n(33983),k=n(54742),f=n(21019);class v extends a.Component{render(){if(void 0===this.props.balances)return a.createElement("div",null,a.createElement(_(),{content:"wallet.loading_balances"}),"…");var e=this.props.balances.groupBy((e=>e.balance.asset_id)).map((e=>e.reduce(((e,t)=>e+Number(t.balance.amount)),0)));return e.size?a.createElement("div",null,e.map(((e,t)=>a.createElement("div",{key:t},a.createElement(f.Z,{color:"info",amount:e,asset:t})))).toArray()):a.createElement("div",null,"None")}}const w=v=(0,s.$)(v,{listenTo:()=>[k.Z],getProps:()=>k.Z.getState()});var C=n(41075),S=n(57296),x=n(16912);class A extends x.Z{constructor(){super(),this.state=this._getInitialState(),this._export("importing")}_getInitialState(){return{importing:!1}}importing(e){this.setState({importing:e})}}const N=S.Z.createStore(A,"ImportKeysStore");var Z=n(76660);n(90067);const B=({key_count:e})=>e?a.createElement("span",null,"Found ",e," private keys"):a.createElement("span",null);class K extends a.Component{constructor(){super(),this.state=this._getInitialState(),this._renderBalanceClaims=this._renderBalanceClaims.bind(this)}static defaultProps={privateKey:!0};_getInitialState(e=!1){return{keys_to_account:{},no_file:!0,account_keys:[],reset_file_name:e?this.state.reset_file_name:Date.now(),reset_password:Date.now(),password_checksum:null,import_file_message:null,import_password_message:null,imported_keys_public:{},key_text_message:null,associatedAccount:null,errorTextMessage:null,genesis_filtering:!1,genesis_filter_status:[],genesis_filter_finished:void 0,importSuccess:!1}}reset(e,t){e&&e.preventDefault();let n=this._getInitialState(t);this.setState(n,(()=>this.updateOnChange()))}onWif(e){e.preventDefault();const t=this.refs.wifInput.state.value;this.addByPattern(t)}onCancel(e){e&&e.preventDefault(),this.setState(this._getInitialState())}updateOnChange(){b.Z.setPubkeys(Object.keys(this.state.imported_keys_public))}getImportAccountKeyCount(e){let t={},n=!1;for(let a in e)for(let s of e[a].account_names)t[s]=(t[s]||0)+1,n=!0;return n?t:null}upload(e){this.reset(null,!0);let t=e.target.files[0],n=new FileReader;n.onload=e=>{let n=e.target.result;try{let e;try{e=JSON.parse(n),this._parseImportKeyUpload(e,t.name,(e=>{this.setState(e,(()=>{e.genesis_filter_finished&&this._passwordCheck()}))}))}catch(a){try{e||t.name,this._parseWalletJson(e)}catch(e){if(!this.addByPattern(n))throw e}this._passwordCheck()}}catch(e){console.error("... ImportKeys upload error",e),this.setState({import_file_message:e})}},n.readAsText(t)}_parseImportKeyUpload(e,t,n){let a,s;try{if(a=e.password_checksum,!a)throw t+" is an unrecognized format";if(!Array.isArray(e.account_keys))throw t+" is an unrecognized format";s=e.account_keys}catch(e){throw e.message||e}}_parseWalletJson(e){let t,n,a={},s={},l=function(e,t){e=o.ChainConfig.address_prefix+e.substring(3);let n=c.PublicKey.fromPublicKeyString(e).toAddressString(),a=s[t]||[];n="GPH"+n.substring(3),a.push(n),s[t]=a};try{if(!Array.isArray(e))throw new Error("Invalid wallet format");for(let s of e)if("key_record_type"==s.type&&s.data.account_address&&s.data.encrypted_private_key){let e=s.data.account_address,t=a[e]||[];t.push(s.data.encrypted_private_key),a[e]=t}else if("account_record_type"!=s.type)if("property_record_type"!=s.type||"encrypted_brainkey"!=s.data.key){if("master_key_record_type"==s.type){if(!s.data)throw file.name+" invalid master_key_record record";if(!s.data.checksum)throw file.name+" is missing master_key_record checksum";t=s.data.checksum}}else n=s.data.value;else{let e=s.data.name;l(s.data.owner_key,e);for(let t of s.data.active_key_history)l(t[1],e)}if(!n)throw"Please use a BTS 1.0 wallet_export_keys file instead";if(!t)throw file.name+" is missing password_checksum";if(!enckeys.length)throw file.name+" does not contain any private keys"}catch(e){throw e.message||e}let r=[];for(let e in s){let t=[];for(let n of s[e]){let e=a[n];if(e)for(let n of e)t.push(n)}r.push({account_name:e,encrypted_private_keys:t})}this.setState({password_checksum:t,account_keys:r})}_passwordCheck(e){e&&"preventDefault"in e&&e.preventDefault();let t=this.refs.password,n=t?t.value:"";if(this.state.password_checksum!=c.hash.sha512(c.hash.sha512(n)).toString("hex"))return this.setState({no_file:!1,import_password_message:n.length?"Incorrect password":null});this.setState({no_file:!1,reset_password:Date.now(),import_password_message:y().translate("wallet.import_pass_match")},(()=>this._decryptPrivateKeys(n)))}_decryptPrivateKeys(e){let t=c.Aes.fromSeed(e),n=!0;for(let e of this.state.account_keys){if(!e.encrypted_private_keys){let t=`Account ${e.account_name} missing encrypted_private_keys`;console.error(t),n&&(Z.Notification.error({message:t}),n=!1);continue}let a=e.account_name.trim(),s=new RegExp("^"+o.ChainConfig.address_prefix);for(let n=0;n<e.encrypted_private_keys.length;n++){let l=e.encrypted_private_keys[n],r=e.public_keys?e.public_keys[n]:null;try{let e=t.decryptHex(l);r?s.test(r)||(r=o.ChainConfig.address_prefix+r.substring(3)):r=c.PrivateKey.fromHex(e).toPublicKey().toPublicKeyString(),this.state.imported_keys_public[r]=!0;let{account_names:n}=this.state.keys_to_account[e]||{account_names:[]},i=!1;for(let e of n)e==a&&(i=!0);if(i)continue;n.push(a),this.state.keys_to_account[e]={account_names:n,public_key_string:r}}catch(e){console.log(e,e.stack);let t=e.message||e;Z.Notification.error({message:y().translate("notifications.import_keys_error",{account_name:a,error_msg:t})})}}}this.setState({import_file_message:null,import_password_message:null,password_checksum:null},(()=>this.updateOnChange()))}_saveImport(e){e.preventDefault();let t=m.Z.getState().keys,n={};for(let e in this.state.imported_keys_public)t.has(e)&&(delete this.state.imported_keys_public[e],n[e]=!0);if(0===Object.keys(this.state.imported_keys_public).length)return void Z.Notification.error({message:y().translate("notifications.import_keys_already_imported")});let a=this.state.keys_to_account;for(let e of Object.keys(a)){let{account_names:t,public_key_string:s}=a[e];n[s]&&delete a[e]}u.Z.unlock().then((()=>{N.importing(!0),setTimeout((()=>this.saveImport()),200)})).catch((()=>{}))}saveImport(){let e=this.state.keys_to_account,t=[];for(let n of Object.keys(e)){let{account_names:a,public_key_string:s}=e[n];t.push({private_plainhex:n,import_account_names:a,public_key_string:s})}this.reset(),C.Z.importKeysWorker(t).then((e=>{N.importing(!1);let n=t.length;Z.Notification.success({message:y().translate("wallet.import_key_success",{count:n})}),this.setState({importSuccess:!0})})).catch((e=>{console.log("error:",e),N.importing(!1);let t=e;try{t=e.target.error.message}catch(e){}Z.Notification.error({message:y().translate("notifications.import_keys_error_unknown",{error_msg:t})})}))}addByPattern(e){if(!e)return this.setState({errorTextMessage:y().translate("wallet.wif_import_error")}),!1;if(51!==e.length)return this.setState({errorTextMessage:y().translate("wallet.wif_length_error")}),!1;let t=0,n=0,a=/5[HJK][1-9A-Za-z]{49}/g;for(let s of e.match(a)||[])try{let e=c.PrivateKey.fromWif(s),n=e.toBuffer().toString("hex"),a=e.toPublicKey().toPublicKeyString();this.state.imported_keys_public[a]=!0,this.state.keys_to_account[n]={account_names:[],public_key_string:a};let l=[];i.Z.lookupAccountByPublicKey(a).then((async e=>{let t;t=e[0].map((e=>(0,c.FetchChain)("getAccount",e))),(await Promise.all(t)).map((e=>{let t=e.get("name");-1===l.indexOf(t)&&l.push(t)})),this.setState({associatedAccount:l})})),t++}catch(e){n++}return this.setState({key_text_message:"Found "+(t?t+" valid":"")+(n?" and "+n+" invalid":"")+" key"+(t>1||n>1?"s":"")+"."},(()=>this.updateOnChange())),this.setState({key_text_message:null,errorTextMessage:null}),t}_renderBalanceClaims(){return a.createElement("div",null,a.createElement(E.Z,null),a.createElement("div",{style:{paddingTop:15}},a.createElement(Z.Button,{type:"primary",onClick:this.onCancel.bind(this)},a.createElement(_(),{content:"wallet.done"}))))}render(){let{privateKey:e}=this.props,{keys_to_account:t}=this.state,n=Object.keys(t).length,s=this.getImportAccountKeyCount(t);if(!C.Z.getWallet())return a.createElement(p.z,{importKeys:!0,hideTitle:!0});if(this.props.importing)return a.createElement("div",null,a.createElement("div",{className:"center-content"},a.createElement(h.Z,{type:"circle"})));let l=this.state.genesis_filtering,c=(!!this.state.genesis_filter_status.length&&this.state.genesis_filter_finished,null);if(this.state.genesis_filter_status.length){c=[];for(let e of this.state.genesis_filter_status)e.count&&e.total&&c.push(a.createElement("tr",{key:e.account_name},a.createElement("td",null,e.account_name),a.createElement("td",null,l?a.createElement("span",null,"Filtering"," ",Math.round(e.count/e.total*100)," ","%"," "):a.createElement("span",null,e.count))))}let i=0!==n,o=y().translate("wallet.import_password");if(i&&(o=""),!c&&s){c=[];for(let e in s)c.push(a.createElement("tr",{key:e},a.createElement("td",null,e),a.createElement("td",null,s[e])))}let m=a.createElement(Z.Button,{onClick:this.onCancel.bind(this)},a.createElement(_(),{content:"wallet.cancel"})),u=1;return this.state.importSuccess?this._renderBalanceClaims():a.createElement("div",null,a.createElement("div",{style:{padding:"10px 0"}},a.createElement("span",null,this.state.key_text_message?this.state.key_text_message:a.createElement(B,{key_count:n})),i?a.createElement("span",null," ","(",a.createElement("a",{onClick:this.reset.bind(this)},a.createElement(_(),{content:"wallet.reset"})),")"):null,a.createElement("span",null,a.createElement("br",null),this.state.associatedAccount&&a.createElement("div",null,a.createElement(_(),{content:"wallet.wif_associated_accounts"}),this.state.associatedAccount.map(((e,t)=>a.createElement("p",{key:t},e)))))),c?a.createElement("div",null,c.length?a.createElement("div",null,a.createElement("table",{className:"table"},a.createElement("thead",null,a.createElement("tr",null,a.createElement("th",null,a.createElement(_(),{content:"explorer.account.title"})),a.createElement("th",null,a.createElement(_(),{content:"settings.restore_key_count"})))),a.createElement("tbody",null,c)),a.createElement("br",null)):y().translate("wallet.no_accounts")):null,a.createElement("br",null),i||this.state.genesis_filter_initalizing?null:a.createElement("div",null,a.createElement("div",null,a.createElement("div",null,e?a.createElement("form",{onSubmit:this.onWif.bind(this)},a.createElement(_(),{component:"label",content:"wallet.paste_private"}),a.createElement(Z.Input,{ref:"wifInput",type:"password",id:"wif",tabIndex:u++,style:{marginBottom:"16px"}}),a.createElement("div",{className:"importError"},a.createElement("span",{className:"red"},this.state.errorTextMessage)),a.createElement(Z.Button,{type:"primary",htmlType:"submit",style:{marginRight:"16px"}},a.createElement(_(),{content:"wallet.submit"})),m):a.createElement("form",{onSubmit:this._passwordCheck.bind(this)},a.createElement("label",null,a.createElement(_(),{content:"wallet.bts_09_export"}),this.state.no_file?null:a.createElement("span",null," (",a.createElement("a",{onClick:this.reset.bind(this)},"Reset"),")")),a.createElement("input",{type:"file",id:"file_input",accept:".json",style:{border:"solid",marginBottom:15},key:this.state.reset_file_name,onChange:this.upload.bind(this)}),a.createElement("div",null,this.state.import_file_message),this.state.no_file?null:a.createElement("div",null,a.createElement(Z.Input,{type:"password",ref:"password",key:this.state.reset_password,placeholder:o,onChange:()=>{this.state.import_password_message&&this.state.import_password_message.length&&this.setState({import_password_message:null})}}),a.createElement("p",{className:"facolor-error"},this.state.import_password_message)),a.createElement("div",{className:"button-group"},a.createElement(Z.Button,{type:"primary",disabled:!!this.state.no_file,htmlType:"submit",style:{marginRight:"16px"}},a.createElement(_(),{content:"wallet.submit"})),m))),a.createElement("br",null),a.createElement("br",null))),i?a.createElement("div",null,a.createElement("div",null,a.createElement("div",{className:"button-group"},a.createElement("div",{className:r()("button success",{disabled:!i}),onClick:this._saveImport.bind(this)},a.createElement(_(),{content:"wallet.import_keys"})),a.createElement("div",{className:"button secondary",onClick:this.reset.bind(this)},a.createElement(_(),{content:"wallet.cancel"})))),a.createElement("h4",null,a.createElement(_(),{content:"wallet.unclaimed"})),a.createElement(_(),{component:"p",content:"wallet.claim_later"}),a.createElement("div",{className:"grid-block"},a.createElement("div",{className:"grid-content no-overflow"},a.createElement(_(),{component:"label",content:"wallet.totals"}),a.createElement(w,null))),a.createElement("br",null)):null)}}const I=K=(0,s.$)(K,{listenTo:()=>[N],getProps:()=>({importing:N.getState().importing})})},90067:(e,t,n)=>{n.r(t)}}]);