-
Notifications
You must be signed in to change notification settings - Fork 13
/
settings.edd7ccf66e57e5d90e6e.js
1 lines (1 loc) · 94.4 KB
/
settings.edd7ccf66e57e5d90e6e.js
1
"use strict";(this.webpackChunkBitShares2_light=this.webpackChunkBitShares2_light||[]).push([[472,660,594],{2644:(e,t,a)=>{a.r(t),a.d(t,{default:()=>le});var s=a(96540),n=a(74248),o=a(92646),r=a(57127),i=a(37346);var l=a(10658),c=a.n(l),d=a(64157),m=a(80849),h=a.n(m),p=a(84259),u=a(64514),_=a(91001),g=a(14431),b=a.n(g),f=a(9476),w=a(72090),y=a(46128),E=a(589);class A extends s.Component{constructor(e){super(e),this.state={showModal:!1,current_asset:w.ChainStore.assets_by_symbol.get(e.fee_asset)||"1.3.0"}}shouldComponentUpdate(){return!0}render(){const e=w.ChainStore.getAsset(this.state.current_asset);return s.createElement("div",{style:{display:"flex",flexDirection:"row",alignItems:"center"}},s.createElement(h(),{component:"span",content:"settings.current_fee_asset",style:{marginRight:"10px"}}),e?s.createElement(_.A,{name:e.get("symbol")}):null,s.createElement(y.Button,{style:{margin:"15px"},key:"open_change_fee_asset",type:"secondary",onClick:()=>{this.setState({showModal:!0})}},c().translate("settings.change_default_fee_asset")),this.state.showModal&&s.createElement(E.A,{key:"change_fee_asset_modal",className:"modal",show:this.state.showModal,current_asset:this.state.current_asset,displayFees:!1,forceDefault:!0,onChange:e=>{this.setState({current_asset:e})},close:()=>{this.setState({showModal:!1})}}))}}const v=(0,f.N)(A,{listenTo:()=>[n.A],getProps:e=>({fee_asset:n.A.getState().settings.get("fee_asset")})});var C=a(17829);const S=y.Form.Item,k=y.Select.Option;class x extends s.Component{constructor(){super(),this.state={message:null,isGatewaySelectorModalVisible:!1,isGatewaySelectorModalRendered:!1},this.handleNotificationChange=this.handleNotificationChange.bind(this)}hideGatewaySelectorModal(){this.setState({isGatewaySelectorModalVisible:!1})}showGatewaySelectorModal(){this.setState({isGatewaySelectorModalRendered:!0,isGatewaySelectorModalVisible:!0})}_setMessage(e){this.setState({message:c().translate(e)}),this.timer=setTimeout((()=>{this.setState({message:null})}),4e3)}componentWillUnmount(){clearTimeout(this.timer)}handleNotificationChange(e){return t=>{this.props.onNotificationChange(e,!!t.target.checked)}}shouldComponentUpdate(e,t,a){return"filteredServiceProviders"!==e.setting||t.isGatewaySelectorModalVisible!==this.state.isGatewaySelectorModalVisible}render(){let e,t,a,{defaults:n,setting:o,settings:r}=this.props,i=r.get(o),l=null;switch(o){case"locale":t=i,e=n.map((e=>{let t="languages."+e,a=c().translate(t);return s.createElement(k,{key:e,value:e},a)}));break;case"themes":t=i,e=n.map((e=>{let t="settings."+e,a=c().translate(t);return s.createElement(k,{key:e,value:e},a)}));break;case"browser_notifications":t=i,l=s.createElement("div",{className:"settings--notifications"},s.createElement("div",{className:"settings--notifications--group"},s.createElement("div",{className:"settings--notifications--item"},s.createElement(y.Checkbox,{id:"browser_notifications.allow",checked:!!t.allow,onChange:this.handleNotificationChange("allow")},c().translate("settings.browser_notifications_allow"))),s.createElement("div",{className:"settings--notifications--group"},s.createElement("div",{className:"settings--notifications--item"},s.createElement(y.Checkbox,{id:"browser_notifications.additional.transferToMe",disabled:!t.allow,checked:!!t.additional.transferToMe,onChange:this.handleNotificationChange("additional.transferToMe")},c().translate("settings.browser_notifications_additional_transfer_to_me"))))),!!t.allow&&b().needsPermission&&s.createElement("a",{href:"https://goo.gl/zZ7NHY",target:"_blank",rel:"noopener noreferrer",className:"external-link"},s.createElement(h(),{component:"div",className:"settings--notifications--no-browser-support",content:"settings.browser_notifications_disabled_by_browser_notify"})));break;case"fee_asset":e=null,t=!0,l=s.createElement(v,{key:"fee_asset_component"});break;case"filteredServiceProviders":e=null,t=!0,l=s.createElement(s.Fragment,null,s.createElement(y.Button,{onClick:this.showGatewaySelectorModal.bind(this)},"Choose external Service Providers"),this.state.isGatewaySelectorModalRendered&&s.createElement(C.A,{visible:this.state.isGatewaySelectorModalVisible,hideModal:this.hideGatewaySelectorModal.bind(this)}));break;case"defaultMarkets":e=null,t=null;break;case"walletLockTimeout":t=i,a=s.createElement(y.Input,{type:"text",className:"settings--input",value:i,onChange:this.props.onChange.bind(this,o)});break;default:"number"==typeof i?t=n[i]:"boolean"==typeof i?t=i?n[0]:n[1]:"string"==typeof i&&(t=i),n?e=n.map((e=>{let t=e.translate?c().translate(`settings.${e.translate}`):e;"unit"!==o&&"fee_asset"!==o||(t=s.createElement(_.A,{name:e}));let a=e.translate?e.translate:e;return s.createElement(k,{value:e.translate?e.translate:e,key:a},t)})):a=s.createElement("input",{className:"settings-input",type:"text",defaultValue:t,onBlur:this.props.onChange.bind(this,o)})}if("number"!=typeof t&&!t&&!e)return null;t&&t.translate&&(t=t.translate);const d=({noHeader:e,setting:t,children:a})=>s.createElement(s.Fragment,null,e&&a||s.createElement(S,{label:c().translate(`settings.${t}`)},a));return s.createElement("section",{className:"no-border-bottom"},s.createElement(d,{noHeader:!1,setting:o},e?s.createElement("ul",{className:"unstyled-list"},s.createElement("li",{className:"with-dropdown"},void 0,s.createElement(y.Select,{value:t,className:"settings--select",onChange:this.props.onChange.bind(this,o)},e),void 0)):null,a?s.createElement("ul",{className:"unstyled-list"},s.createElement("li",null,a)):null,l||null),s.createElement("div",{className:"facolor-success"},this.state.message))}}var N=a(54625),M=a(55840),T=a(99429),I=a(87040);class B extends s.Component{shouldComponentUpdate(e){return!I.A.are_equal_shallow(e.myAccounts,this.props.myAccounts)||e.hiddenAccounts!==this.props.hiddenAccounts}onToggleHide(e,t,a){a.preventDefault(),T.A.toggleHideAccount(e,t)}render(){let{myAccounts:e,hiddenAccounts:t}=this.props,a=t.toArray().concat(e).sort();return a.length?s.createElement("table",{className:"table"},s.createElement("tbody",null,a.map((e=>{let a=t.has(e),n=s.createElement("a",{onClick:a?this.onToggleHide.bind(this,e,!1):this.onToggleHide.bind(this,e,!0)},s.createElement(h(),{content:"account."+(a?"unignore":"ignore")}));return s.createElement("tr",{key:e},s.createElement("td",null,e),s.createElement("td",null,s.createElement(N.N_,{to:`/account/${e}/permissions`},s.createElement(h(),{content:"settings.view_keys"}))),s.createElement("td",null,n))})))):s.createElement("div",null,s.createElement(h(),{content:"settings.no_accounts"}))}}const D=B=(0,f.N)(B,{listenTo:()=>[M.A],getProps:()=>({myAccounts:M.A.getMyAccounts(),hiddenAccounts:M.A.getState().myHiddenAccounts})});var O=a(92511),F=a(62390),R=a(46863);const P=y.Form.Item;class V extends s.Component{constructor(){super(),this.state={lookupActive:!1,resetMessage:null}}onLookup(){this.setState({lookupActive:!0})}onResetBrainkeySequence(){R.A.resetBrainKeySequence(),this.setState({resetMessage:c().translate("wallet.brainkey_reset_success")})}render(){let{lookupActive:e}=this.state,{deprecated:t}=this.props;return t?s.createElement("div",null,s.createElement(O.ChangeActiveWallet,null),s.createElement(O.WalletDelete,null)):s.createElement("div",null,s.createElement(O.ChangeActiveWallet,null),s.createElement(O.WalletDelete,null),s.createElement(P,{label:c().translate("wallet.balance_claims"),className:"no-offset",style:{padding:"15px 0"}},s.createElement("div",{style:{paddingBottom:10}},s.createElement(h(),{content:"settings.lookup_text"}),":"),s.createElement(y.Button,{onClick:this.onLookup.bind(this)},s.createElement(h(),{content:"wallet.balance_claim_lookup"}))),e?s.createElement(F.A,null):null,s.createElement(P,{label:c().translate("wallet.brainkey_seq_reset"),className:"no-offset",style:{paddingBottom:"15px"}},s.createElement("div",{style:{paddingBottom:10}},s.createElement("p",null,s.createElement(h(),{unsafe:!0,content:"wallet.brainkey_seq_reset_text"})),s.createElement(y.Button,{onClick:this.onResetBrainkeySequence.bind(this)},s.createElement(h(),{content:"wallet.brainkey_seq_reset_button"})),this.state.resetMessage?s.createElement("p",{style:{paddingTop:10},className:"facolor-success"},this.state.resetMessage):null)))}}var j=a(42578);class z extends s.Component{render(){return s.createElement(j.A,null)}}var L=a(99425),W=a(87133),H=a(11186);class U extends s.Component{constructor(e){super(e),this.state={json:null,error:null}}upload(e){this.setState({error:!1,json:null});let t=e.target.files[0],a=new FileReader;a.onload=e=>{let t=e.target.result;try{let e=JSON.parse(t);for(var a in e){let t=e[a],{quote:s,base:n}=t;if(!s||!n)throw new Error("Cannot parse json data.")}this.setState({json:e})}catch(e){this.setState({error:!0})}},a.readAsText(t)}finish(){const{json:e}=this.state;for(var t in p.A.clearStarredMarkets(),e){let a=e[t],{quote:s,base:n}=a;p.A.addStarMarket(s,n)}y.Notification.success({message:c()("settings.backup_favorites_success")})}render(){const{state:e}=this;return s.createElement("div",null,s.createElement("input",{type:"file",id:"file_input",accept:".json",style:{border:"solid",marginBottom:15},onChange:this.upload.bind(this)}),e.error&&s.createElement("h5",null,s.createElement(h(),{content:"settings.backup_favorites_error"})),e.json&&s.createElement("p",null,s.createElement(y.Button,{type:"primary",onClick:this.finish.bind(this)},s.createElement(h(),{content:"settings.backup_favorites_finish"}))))}}const K=U,q=y.Select.Option;class G extends s.Component{constructor(){super(),this.state={restoreType:0,types:["backup","key","legacy","brainkey","favorites"]}}_setWalletMode(){p.A.changeSetting({setting:"passwordLogin",value:!1})}_changeType(e){this.setState({restoreType:this.state.types.indexOf(e)})}render(){let{passwordLogin:e}=this.props;if(e)return s.createElement("div",null,s.createElement(h(),{content:"settings.wallet_required",component:"h4"}),s.createElement("p",{className:"dark-text-color"},s.createElement(h(),{content:"settings.wallet_required_text"}),":"),s.createElement(y.Button,{type:"primary",className:"button",onClick:this._setWalletMode},s.createElement(h(),{content:"settings.enable_wallet"})));let t,{types:a,restoreType:n}=this.state,o=a.map((e=>s.createElement(q,{key:e,value:e},c().translate(`settings.backup_${e}`)," ")));switch(a[n]){case"backup":t=s.createElement("div",null,s.createElement(L.jY,null));break;case"brainkey":t=s.createElement("div",null,s.createElement("p",{style:{maxWidth:"40rem",paddingBottom:10}},s.createElement(h(),{content:"settings.restore_brainkey_text"})),s.createElement(H.P,{nested:!0}));break;case"favorites":t=s.createElement("div",null,s.createElement(K,null));break;default:t=s.createElement(W.A,{privateKey:1===n})}return s.createElement("div",null,s.createElement(y.Select,{onChange:this._changeType.bind(this),className:"bts-select",value:a[n]},o),t)}}var J=a(31329);class $ extends s.Component{constructor(){super(),this.state={message:null}}_setMessage(e){this.setState({message:c().translate(e)}),this.timer=setTimeout((()=>{this.setState({message:null})}),4e3)}componentWillUnmount(){clearTimeout(this.timer)}render(){return s.createElement("section",{className:"no-border-bottom"},s.createElement("header",null,s.createElement(h(),{component:"span",style:{fontWeight:"normal",fontFamily:"Roboto-Medium, arial, sans-serif",fontStyle:"normal"},content:"settings.reset_text_description",generalName:c().translate("settings.general"),with:{generalName:c().translate("settings.general"),accessName:c().translate("settings.access"),faucetName:c().translate("settings.faucet_address")}})),s.createElement(y.Button,{type:"primary",style:{height:60,width:"100%",marginTop:"30px"},onClick:()=>{p.A.clearSettings().then((()=>{this._setMessage("settings.restore_default_success"),setTimeout((()=>{(0,J.A)(!1)}),50)}))}},c().translate("settings.reset")),s.createElement("div",{className:"facolor-success",style:{marginTop:"20px",height:"18px"}},this.state.message))}}var Z=a(13796),Y=a(91936);class Q extends s.Component{makeBackup(){let e=this.props.starredMarkets.toJS(),t=new Blob([JSON.stringify(e)],{type:"application/json; charset=us-ascii"});(0,Y.saveAs)(t,"favorites.json")}render(){return s.createElement("div",null,s.createElement("p",null,s.createElement(h(),{content:"settings.backup_favoritestext"})),s.createElement(y.Button,{type:"primary",onClick:this.makeBackup.bind(this)},s.createElement(h(),{content:"settings.backup_favoritesbtn"})))}}const X=(0,f.N)(Q,{listenTo:()=>[n.A],getProps:()=>({starredMarkets:n.A.getState().starredMarkets})}),ee=y.Select.Option;class te extends s.Component{constructor(){super(),this.state={restoreType:0,types:["backup","brainkey","favorites"]}}_changeType(e){this.setState({restoreType:this.state.types.indexOf(e)})}render(){let e,{types:t,restoreType:a}=this.state,n=t.map((e=>s.createElement(ee,{key:e,value:e},c().translate(`settings.backupcreate_${e}`)," ")));switch(t[a]){case"backup":e=s.createElement(L.J7,null);break;case"brainkey":e=s.createElement(Z.A,null);break;case"favorites":e=s.createElement(X,null)}return s.createElement("div",null,s.createElement(y.Select,{onChange:this._changeType.bind(this),className:"bts-select",value:t[a],style:{marginBottom:"16px"}},n),e)}}var ae=a(94999),se=a(45964);function ne(){return ne=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var s in a)Object.prototype.hasOwnProperty.call(a,s)&&(e[s]=a[s])}return e},ne.apply(this,arguments)}class oe extends s.Component{constructor(e){super();let t=this._getMenuEntries(e),a=0,s=e.match.params.tab?t.indexOf(e.match.params.tab):e.viewSettings.get("activeSetting",0);s>=0&&(a=s);let n=["locale","unit","fee_asset","filteredServiceProviders","browser_notifications","showSettles","walletLockTimeout","themes","showAssetPercent","viewOnlyMode","showProposedTx"];(0,se.B7)().length>1&&n.push("passwordLogin"),n.push("reset"),this.state={isAddNodeModalVisible:!1,isRemoveNodeModalVisible:!1,removeNode:{name:null,url:null},apiServer:e.settings.get("apiServer"),activeSetting:a,menuEntries:t,settingEntries:{general:n,access:["apiServer","faucet_address"]}},this.showAddNodeModal=this.showAddNodeModal.bind(this),this.hideAddNodeModal=this.hideAddNodeModal.bind(this),this.showRemoveNodeModal=this.showRemoveNodeModal.bind(this),this.hideRemoveNodeModal=this.hideRemoveNodeModal.bind(this),this._handleNotificationChange=this._handleNotificationChange.bind(this)}componentDidUpdate(e){e.match.params.tab!==this.props.match.params.tab&&this.props.match.params.tab&&this._onChangeMenu(this.props.match.params.tab)}UNSAFE_componentWillReceiveProps(e){if(e.settings.get("passwordLogin")!==this.props.settings.get("passwordLogin")){const t=this._getMenuEntries(this.props),a=this._getMenuEntries(e),s=t[this.state.activeSetting],n=a.indexOf(s),o=a[n];this.setState({menuEntries:a}),n&&n!==this.state.activeSetting?this.setState({activeSetting:a.indexOf(s)}):(!o||this.state.activeSetting>a.length-1)&&this.setState({activeSetting:0})}}showAddNodeModal(){this.setState({isAddNodeModalVisible:!0})}hideAddNodeModal(){this.setState({isAddNodeModalVisible:!1})}showRemoveNodeModal(e,t){this.setState({isRemoveNodeModalVisible:!0,removeNode:{url:e,name:t}})}hideRemoveNodeModal(){this.setState({isRemoveNodeModalVisible:!1,removeNode:{url:null,name:null}})}_getMenuEntries(e){if(e.deprecated)return["wallet","backup"];let t=[];return t.push("general"),e.settings.get("passwordLogin")||t.push("wallet"),t.push("accounts"),e.settings.get("passwordLogin")||t.push("password"),e.settings.get("passwordLogin")||t.push("backup"),e.settings.get("passwordLogin")||t.push("restore"),t.push("access"),(0,se.rk)().show&&t.push("faucet_address"),t.push("reset"),t}triggerModal(e,...t){this.refs.ws_modal.show(e,...t)}_handleNotificationChange(e,t){let a=function(e,t,a){return null==e?e:(0,i.A)(e,t,a)}(this.props.settings.get("browser_notifications"),e,t);p.A.changeSetting({setting:"browser_notifications",value:a})}_handleSettingsEntryChange(e,t){t.target?this._onChangeSetting(e,t):this._onChangeSetting(e,{target:{value:t}})}_onChangeSetting(e,t){t.preventDefault&&t.preventDefault();let{defaults:a}=this.props,s=null;function n(e,t){if(!t)return e;if(!t[0].translate)return t.indexOf(e);for(var a=0;a<t.length;a++)if(c().translate(`settings.${t[a].translate}`)===e)return a}switch(e){case"locale":let o=c().getLocale();t.target.value!==o&&(d.A.switchLocale(t.target.value),p.A.changeSetting({setting:"locale",value:t.target.value}));break;case"themes":p.A.changeSetting({setting:"themes",value:t.target.value});break;case"defaultMarkets":case"filteredServiceProviders":break;case"walletLockTimeout":let r=parseInt(t.target.value,10);isNaN(r)&&(r=0),isNaN(r)||"number"!=typeof r||p.A.changeSetting({setting:"walletLockTimeout",value:r});break;case"inverseMarket":case"confirmMarketOrder":s=0===n(t.target.value,a[e]);break;case"apiServer":p.A.changeSetting({setting:"apiServer",value:t.target.value}),this.setState({apiServer:t.target.value});break;case"showProposedTx":case"showSettles":case"showAssetPercent":case"passwordLogin":case"viewOnlyMode":let i=a[e][0];i.translate&&(i=i.translate),p.A.changeSetting({setting:e,value:t.target.value===i});break;case"fee_asset":case"unit":const l=a.unit;let m=n(t.target.value,l);p.A.changeSetting({setting:e,value:l[m]});break;default:s=n(t.target.value,a[e])}null!==s&&p.A.changeSetting({setting:e,value:s})}onReset(){p.A.clearSettings()}_redirectToEntry(e){this.props.history.push("/settings/"+e)}_onChangeMenu(e){let t=this.state.menuEntries.indexOf(e);this.setState({activeSetting:t}),p.A.changeViewSetting({activeSetting:t})}render(){let{settings:e,defaults:t}=this.props;const{menuEntries:a,activeSetting:n,settingEntries:o}=this.state;let r,i=a[n]||a[0];switch(i){case"accounts":r=s.createElement(D,null);break;case"wallet":r=s.createElement(V,this.props);break;case"password":r=s.createElement(z,null);break;case"backup":r=s.createElement(te,null);break;case"restore":r=s.createElement(G,{passwordLogin:this.props.settings.get("passwordLogin")});break;case"access":r=s.createElement(ae.A,{faucet:e.get("faucet_address"),nodes:t.apiServer,onChange:this._onChangeSetting.bind(this),showAddNodeModal:this.showAddNodeModal,showRemoveNodeModal:this.showRemoveNodeModal});break;case"faucet_address":r=s.createElement(y.Input,{disabled:!(0,se.rk)().editable,type:"text",defaultValue:e.get("faucet_address"),onChange:(0,se.rk)().editable?this._onChangeSetting.bind(this,"faucet_address"):null});break;case"reset":r=s.createElement($,null);break;default:r=o[i].map((a=>s.createElement(x,ne({key:a,setting:a,settings:e,defaults:t["fee_asset"===a?"unit":a],onChange:this._handleSettingsEntryChange.bind(this),onNotificationChange:this._handleNotificationChange,locales:this.props.localesObject},this.state))))}return s.createElement(y.Form,{layout:"vertical"},s.createElement("div",{className:this.props.deprecated?"":"grid-block settings-container"},s.createElement("div",{className:"grid-block main-content margin-block wrap"},s.createElement("div",{className:"grid-content shrink settings-menu",style:{paddingRight:"2rem"}},s.createElement(h(),{style:{paddingBottom:10,paddingLeft:10},component:"h3",content:"header.settings",className:"panel-bg-color"}),s.createElement("ul",null,a.map(((e,t)=>s.createElement("li",{className:t===n?"active":"",onClick:this._redirectToEntry.bind(this,e),key:e},s.createElement(h(),{content:"settings."+e})))))),s.createElement("div",{className:"grid-content",style:{height:"100%"}},s.createElement("div",{className:"grid-block small-12 no-margin vertical",style:{maxWidth:1e3}},s.createElement(h(),{component:"h3",content:"settings."+a[n]}),"access"!=i&&s.createElement(h(),{unsafe:!0,style:{paddingTop:5,marginBottom:30},content:`settings.${a[n]}_text`,className:"panel-bg-color"}),r))),s.createElement(u.A,{removeNode:this.state.removeNode,isAddNodeModalVisible:this.state.isAddNodeModalVisible,isRemoveNodeModalVisible:this.state.isRemoveNodeModalVisible,onAddNodeClose:this.hideAddNodeModal,onRemoveNodeClose:this.hideRemoveNodeModal,apis:t.apiServer,api:t.apiServer.filter((e=>e.url===this.state.apiServer)).reduce(((e,t)=>t&&t.url),null),changeConnection:e=>{this.setState({apiServer:e})}})))}}const re=oe;class ie extends s.Component{render(){return s.createElement(r.A,{stores:[n.A],inject:{settings:()=>n.A.getState().settings,viewSettings:()=>n.A.getState().viewSettings,defaults:()=>n.A.getState().defaults,localesObject:()=>o.A.getState().localesObject,apiLatencies:()=>n.A.getState().apiLatencies}},s.createElement(re,this.props))}}const le=ie},62426:(e,t,a)=>{a.r(t),a.d(t,{default:()=>N});var s=a(45572),n=a(65124),o=a(21888),r=a(38446);const i=function(e,t){var a=-1,s=(0,r.A)(e)?Array(e.length):[];return(0,o.A)(e,(function(e,n,o){s[++a]=t(e,n,o)})),s};var l=a(92049);const c=function(e,t){return((0,l.A)(e)?s.A:i)(e,(0,n.A)(t,3))};var d=a(96540),m=a(80849),h=a.n(m),p=a(46128),u=a(1951),_=a(84181),g=a(10658),b=a.n(g),f=a(55840),w=a(72090),y=a(49585),E=a(24609),A=a(87040),v=a(15483),C=a(89247),S=a(8080),k=a(48287).Buffer;function x(e,t){if(e)return e/Math.pow(10,t)}class N extends d.Component{constructor(){super(),this.state={from_name:"",to_name:"",from_account:null,to_account:null,from_barter:[{index:0,from_amount:"",from_asset_id:null,from_asset:null,from_feeAsset:new E.Vd({amount:0,asset_id:"1.3.0"}),from_hasPoolBalance:null,from_balanceError:!1}],to_barter:[{index:0,to_amount:"",to_asset_id:null,to_asset:null,to_feeAsset:new E.Vd({amount:0,asset_id:"1.3.0"}),to_hasPoolBalance:null,to_balanceError:!1}],amount_counter:[],amount_index:0,from_error:null,to_error:null,memo:{from_barter:[{message:"",shown:!1}],to_barter:[{message:"",shown:!1}],escrow:[{message:"",shown:!1}]},proposal_fee:{amount:0,asset_id:"1.3.0"},showEscrow:!1,escrow_account_name:"",escrow_account:null,send_to_escrow:!1,escrow_payment:0,escrow_payment_changed:!1,escrowFeeAssetId:"1.3.0",balanceWarning:{peer1:[],peer2:[]}},this._checkBalance=this._checkBalance.bind(this),this.onTrxIncluded=this.onTrxIncluded.bind(this)}UNSAFE_componentWillMount(){let e=f.A.getState().currentAccount;this.state.from_name||this.setState({from_name:e})}fromChanged(e){this.setState({from_name:e})}escrowAccountChanged(e){this.setState({escrow_account_name:e})}onFromAccountChanged(e){this.setState({from_account:e,from_barter:[{from_amount:"",from_asset_id:null,from_asset:null,from_feeAsset:new E.Vd({amount:0,asset_id:"1.3.0"}),from_hasPoolBalance:null,from_balanceError:!1}]})}onEscrowAccountChanged(e){this.setState({escrow_account:e})}toChanged(e){this.setState({to_name:e})}onToAccountChanged(e){this.setState({to_account:e,to_barter:[{to_amount:"",to_asset_id:null,to_asset:null,to_feeAsset:new E.Vd({amount:0,asset_id:"1.3.0"}),to_hasPoolBalance:null,to_balanceError:!1}]})}onFromAmountChanged(e,t){const a=t.asset,s=t.amount;if(!a)return;let n=[...this.state.from_barter];n[e]={index:e,from_amount:s,from_asset:a,from_asset_id:a.get("id"),from_balanceError:!1,from_feeAsset:n[e].from_feeAsset},this.setState({from_barter:n,from_error:null},(()=>{this._checkBalance(n[e].from_feeAsset,s,this.state.from_account,a,e,!0,n[e].from_feeAsset.asset_id,n),this.checkAmountsTotal()}))}onToAmountChanged(e,t){const a=t.asset,s=t.amount;if(!a)return;let n=[...this.state.to_barter];n[e]={index:e,to_amount:s,to_asset:a,to_asset_id:a.get("id"),to_feeAsset:n[e].to_feeAsset,to_balanceError:!1},this.setState({to_barter:n,to_error:null},(()=>{this._checkBalance(n[e].to_feeAsset,s,this.state.to_account,a,e,!1,n[e].to_feeAsset.asset_id,n),this.checkAmountsTotal()}))}_checkBalance(e,t,a,s,n,o,r,i){if(!s||!a)return;const l=a.getIn(["balances",s.get("id")]),c=a.getIn(["balances",e.asset_id]);if(!s||!a)return;if(!l)return o?(i[n].from_balanceError=!0,this.setState({from_barter:i})):(i[n].to_balanceError=!0,this.setState({to_barter:i}));let d=w.ChainStore.getObject(l),m=c?w.ChainStore.getObject(c):null;if(m&&0!==m.get("balance")||(o?this.setState({from_barter:i}):this.setState({to_barter:i})),!d||!e)return;if(!t)return o?(i[n].from_balanceError=!1,this.setState({from_barter:i})):(i[n].to_balanceError=!1,this.setState({to_barter:i}));const h=(0,v.rT)(t,s,e,d);return null!==h?o?(i[n].from_balanceError=!h,this.setState({from_barter:i})):(i[n].to_balanceError=!h,this.setState({to_barter:i})):void 0}_getAvailableAssets(e=this.state){const{from_account:t,from_error:a,to_account:s,to_error:n}=e;let o=(e,t)=>{let a=[],s=[];if(!e||!e.get("balances")||t)return{asset_types:a,fee_asset_types:s};let n=e.get("balances").toJS();a=Object.keys(n).sort(A.A.sortID),s=Object.keys(n).sort(A.A.sortID);for(let e in n){let t=w.ChainStore.getObject(n[e]);t&&0===t.get("balance")&&(a.splice(a.indexOf(e),1),-1!==s.indexOf(e)&&s.splice(s.indexOf(e),1))}return{asset_types:a,fee_asset_types:s}},r=o(t,a),i=o(s,n);return{from_asset_types:r.asset_types||[],to_asset_types:i.asset_types||[],from_fee_asset_types:r.fee_asset_types||[],to_fee_asset_types:i.fee_asset_types||[]}}addFromAmount(){this.state.from_barter.push({from_amount:"",from_asset_id:null,from_asset:null,from_feeAsset:new E.Vd({amount:0,asset_id:"1.3.0"})}),this.setState({from_barter:this.state.from_barter})}addToAmount(){this.state.to_barter.push({to_amount:"",to_asset_id:null,to_asset:null,to_feeAsset:new E.Vd({amount:0,asset_id:"1.3.0"})}),this.setState({to_barter:this.state.to_barter})}onSubmit(e){let t;e.preventDefault(),this.setState({from_error:null,to_error:null});let a=[],s=f.A.getState().currentAccount,n=this.state.from_account,o=this.state.memo.escrow[0]&&this.state.memo.escrow[0].message;if(this.state.showEscrow&&this.state.send_to_escrow&&(n=this.state.escrow_account),this.state.showEscrow){let e=this.state.escrow_payment_changed?new E.Vd({real:this.state.escrow_payment}).getAmount():fee(!0);e>0&&a.push({from_account:this.state.from_account.get("id"),to_account:this.state.escrow_account.get("id"),amount:e,asset:"1.3.0",memo:o?new k(o,"utf-8"):null,feeAsset:this.state.escrowFeeAssetId,propose_account:s})}this.state.from_barter.forEach(((e,r)=>{const i=e.from_asset;let l=e.from_amount;t=new E.Vd({real:l,asset_id:i.get("id"),precision:i.get("precision")});let c=this.state.memo.from_barter[r]&&this.state.memo.from_barter[r].message;this.state.showEscrow&&this.state.send_to_escrow&&a.push({from_account:this.state.from_account.get("id"),to_account:this.state.escrow_account.get("id"),amount:t.getAmount(),asset:i.get("id"),memo:o?new k(o,"utf-8"):null,feeAsset:e.from_feeAsset?e.from_feeAsset.asset_id:"1.3.0"}),a.push({from_account:n.get("id"),to_account:this.state.to_account.get("id"),amount:t.getAmount(),asset:i.get("id"),memo:c?new k(c,"utf-8"):null,feeAsset:e.from_feeAsset?e.from_feeAsset.asset_id:"1.3.0",propose_account:s})})),this.state.showEscrow&&!this.state.send_to_escrow&&a.push({from_account:this.state.escrow_account.get("id"),to_account:this.state.from_account.get("id"),amount:1,asset:"1.3.0",memo:null,feeAsset:this.state.escrowFeeAssetId,propose_account:s}),this.state.to_barter.forEach(((e,n)=>{const o=e.to_asset;let r=e.to_amount,i=this.state.memo.to_barter[n]&&this.state.memo.to_barter[n].message;t=new E.Vd({real:r,asset_id:o.get("id"),precision:o.get("precision")}),a.push({from_account:this.state.to_account.get("id"),to_account:this.state.from_account.get("id"),amount:t.getAmount(),asset:o.get("id"),memo:i?new k(i,"utf-8"):null,feeAsset:e.to_feeAsset?e.to_feeAsset.asset_id:"1.3.0",propose_account:s})})),S.A.transfer_list(a,this.state.proposal_fee.asset_id)}onTrxIncluded(e){(e.included&&e.broadcasted_transaction||e.closed)&&(TransactionConfirmStore.unlisten(this.onTrxIncluded),TransactionConfirmStore.reset())}onMemoChanged=(e,t)=>a=>{const s=Object.assign({},this.state.memo);s[e][t]={message:a.target.value,shown:!0},this.setState({memo:s})};renderMemoField(e,t){const{memo:a}=this.state,s=a[e][t]&&a[e][t].message?a[e][t].message:"";return d.createElement("div",{className:"content-block transfer-input"},d.createElement(h(),{className:"left-label",component:"label",content:"transfer.memo"}),d.createElement("textarea",{style:{marginBottom:0},rows:"1",value:s,onChange:this.onMemoChanged(e,t)}))}handleMemoOpen=(e,t)=>a=>{const s=Object.assign({},this.state.memo);s[e][t]={message:"",shown:!0},this.setState({memo:s})};getBalance(e,t){return w.ChainStore.getAccountBalance(e,t)}checkAmountsTotal(){const{from_barter:e,to_barter:t,from_account:a,to_account:s}=this.state;let n={},o={};e.forEach((function(e){e.from_amount&&(n.hasOwnProperty(e.from_asset_id)?n[e.from_asset_id]={amount:Number(n[e.from_asset_id].amount)+Number(e.from_amount),precision:e.from_asset.get("precision"),symbol:e.from_asset.get("symbol")}:n[e.from_asset_id]={amount:Number(e.from_amount),precision:e.from_asset.get("precision"),symbol:e.from_asset.get("symbol")})}));let r=c(n,((e,t)=>{let s=this.getBalance(a,t),n=Math.max(0,e.precision),o=s?x(s,n):0;return e.assetId=t,e.amount>o&&(e.warning=!0,e.balance=o),e}));t.forEach((function(e){e.to_amount&&(o.hasOwnProperty(e.to_asset_id)?o[e.to_asset_id]={amount:Number(o[e.to_asset_id].amount)+Number(e.to_amount),precision:e.to_asset.get("precision"),symbol:e.to_asset.get("symbol")}:o[e.to_asset_id]={amount:Number(e.to_amount),precision:e.to_asset.get("precision"),symbol:e.to_asset.get("symbol")})}));let i=c(o,((e,t)=>{let a=this.getBalance(s,t),n=Math.max(0,e.precision),o=a?x(a,n):0;return e.assetId=t,e.amount>o&&(e.warning=!0,e.balance=o),e}));this.setState({balanceWarning:{peer1:r,peer2:i}})}renderBalanceWarnings(){const{balanceWarning:{peer1:e,peer2:t}}=this.state;let a=e.some((e=>!!e.warning)),s=t.some((e=>!!e.warning)),n=b().translate("showcases.barter.peer_left"),o=b().translate("showcases.barter.peer_right"),r=a?d.createElement("div",{style:{maxWidth:"25rem"}},b().translate("showcases.barter.balance_warning_tooltip",{peer:n}),d.createElement("br",null),e.map((e=>{if(e.warning)return d.createElement(d.Fragment,null,d.createElement("br",null),d.createElement("span",{style:{marginRight:"10px"},key:e.assetId}," - "+b().translate("showcases.barter.balance_warning_line",{asset_symbol:e.symbol,asset_balance:e.balance,asset_amount:e.amount})))}))):null,i=s?d.createElement("div",{style:{maxWidth:"25rem"}},b().translate("showcases.barter.balance_warning_tooltip",{peer:o}),t.map((e=>{if(e.warning)return d.createElement("span",{style:{marginRight:"10px"},key:e.assetId},d.createElement("br",null),d.createElement("br",null),b().translate("showcases.barter.balance_warning_line",{asset_symbol:e.symbol,asset_balance:e.balance,asset_amount:e.amount}),";")}))):null;return d.createElement("span",{className:"barter-balance-warning"},a&&d.createElement(p.Popover,{content:r,title:b().translate("showcases.barter.balance_warning")},d.createElement("span",{style:{cursor:"help"}},d.createElement(p.Alert,{style:{display:"inline",marginRight:"1rem"},message:n+" "+b().translate("showcases.barter.balance_warning"),type:"warning",showIcon:!0}))),s&&d.createElement(p.Popover,{content:i,title:b().translate("showcases.barter.balance_warning")},d.createElement("span",{style:{cursor:"help"}},d.createElement(p.Alert,{style:{display:"inline"},message:o+" "+b().translate("showcases.barter.balance_warning"),type:"warning",showIcon:!0}))))}onFeeChangedPeer1CreateProposal(e){this.setState({proposal_fee:e})}onFeeChangedPeer1InProposal(e){let t=this.state.from_barter.map((t=>(t.to_feeAsset=e,t)));this.setState({from_barter:t})}onFeeChangedPeer2InProposal(e){let t=this.state.to_barter.map((t=>(t.to_feeAsset=e,t)));this.setState({to_barter:t})}onEscrowFeeChanged(e){this.setState({escrowFeeAssetId:e.asset_id})}render(){let{from_name:e,to_name:t,from_account:a,to_account:s,from_barter:n,to_barter:o,amount_index:r,from_error:i,to_error:l}=this.state,{from_asset_types:c,to_asset_types:m}=this._getAvailableAssets(),g=window.innerWidth<850,f=[],E=[];const A=()=>{for(let e of n){const t=parseFloat(String.prototype.replace.call(e.from_amount,/,/g,""));if(isNaN(t)||0===t)return!1}for(let e of o){const t=parseFloat(String.prototype.replace.call(e.to_amount,/,/g,""));if(isNaN(t)||0===t)return!1}return!0},v=e=>{console.log(n);let t=0;return e?n.forEach((e=>{t+=e.from_feeAsset._real_amount})):o.forEach((e=>{t+=e.to_feeAsset._real_amount})),t};let S=this.state.showEscrow&&!this.state.escrow_account;const k=!a||!s||a.get("id")==s.get("id")||l||!A()||i||S,x=(e,t,a,s)=>{if(e&&e.get("balances")){let n=e.get("balances").toJS(),o=t?"has-error":"";if(1===a.length&&(s=w.ChainStore.getAsset(a[0])),a.length>0){let e=s?s.get("id"):a[0];return d.createElement("span",null,d.createElement(h(),{component:"span",content:"transfer.available"}),":"," ",d.createElement("span",{className:o,style:{borderBottom:"#A09F9F 1px dotted",cursor:"pointer"}},d.createElement(C.A,{balance:n[e]})))}return d.createElement("span",null,d.createElement("span",{className:o},d.createElement(h(),{content:"transfer.errors.noFunds"})))}};let N=n.map(((e,t)=>{let s="";e.from_asset&&(s=e.from_asset.get("symbol"),f.push([e.from_amount||0,s].join(" ")));let n=this.state.memo.from_barter[t]&&this.state.memo.from_barter[t].shown;return d.createElement("div",{key:r++},d.createElement("div",{style:{position:"relative"}},!n&&d.createElement(p.Tooltip,{title:b().translate("tooltip.add_memo_field"),placement:"topLeft"},d.createElement(p.Button,{onClick:this.handleMemoOpen("from_barter",t),size:"small",icon:"message",className:"add-memo-btn"})),d.createElement(y.A,{label:"showcases.barter.bartering_asset",style:{marginBottom:"1rem"},amount:e.from_amount,onChange:this.onFromAmountChanged.bind(this,t),asset:c.length>0&&e.from_asset?e.from_asset.get("id"):e.from_asset_id?e.from_asset_id:c[0],assets:c,display_balance:x(a,e.from_balanceError,c,e.from_asset),allowNaN:!0})),n&&this.renderMemoField("from_barter",t))})),M=o.map(((e,t)=>{let a="";e.to_asset&&(e.to_asset.get("symbol"),E.push([e.to_amount||0,e.to_asset.get("symbol")].join(" ")));let n=this.state.memo.to_barter[t]&&this.state.memo.to_barter[t].shown;return d.createElement("div",{key:r++},d.createElement("div",{style:{position:"relative"}},!n&&d.createElement(p.Tooltip,{title:b().translate("tooltip.add_memo_field"),placement:"topLeft"},d.createElement(p.Button,{onClick:this.handleMemoOpen("to_barter",t),size:"small",icon:"message",className:"add-memo-btn"})),d.createElement(y.A,{label:"showcases.barter.bartering_asset",style:{marginBottom:"1rem"},amount:e.to_amount,onChange:this.onToAmountChanged.bind(this,t),asset:m.length>0&&e.to_asset?e.to_asset.get("id"):e.to_asset_id?e.to_asset_id:m[0],assets:m,display_balance:x(s,e.to_balanceError,m,e.to_asset),allowNaN:!0})),n&&this.renderMemoField("to_barter",t))})),T=d.createElement(p.Card,{style:{borderRadius:"10px"}},d.createElement(h(),{content:"showcases.barter.peer_left"}),d.createElement(u.A,{label:"showcases.barter.account",placeholder:"placeholder",style:{marginTop:"0.5rem",marginBottom:"1rem"},allowPubKey:!0,allowUppercase:!0,account:a,accountName:e,onChange:this.fromChanged.bind(this),onAccountChanged:this.onFromAccountChanged.bind(this),hideImage:!0,typeahead:!0}),a&&d.createElement("div",null,N,d.createElement("div",{style:{paddingTop:"10px",paddingBottom:"10px"}},d.createElement(p.Button,{onClick:this.addFromAmount.bind(this),disabled:!a||!this.state.from_barter[this.state.from_barter.length-1].from_amount},"+ Add asset")))),I=d.createElement(p.Card,{style:{borderRadius:"10px"}},d.createElement(h(),{content:"showcases.barter.peer_right"}),d.createElement(u.A,{label:"showcases.barter.account",placeholder:"placeholder",style:{marginTop:"0.5rem",marginBottom:"1rem"},allowPubKey:!0,allowUppercase:!0,account:s,accountName:t,onChange:this.toChanged.bind(this),onAccountChanged:this.onToAccountChanged.bind(this),hideImage:!0,typeahead:!0}),s&&d.createElement("div",null,M,d.createElement("div",{style:{paddingTop:"10px",paddingBottom:"10px"}},d.createElement(p.Button,{onClick:this.addToAmount.bind(this),disabled:!s||!this.state.to_barter[this.state.to_barter.length-1].to_amount},"+ Add asset")))),B="showcases.barter.not_complete";k&&(a?s?a.get("id")==s.get("id")?B="showcases.barter.error_same_name":A()?S?B="showcases.barter.error_fill_in_escrow_name":!this.state.showEscrow||a.get("id")!=this.state.escrow_account.get("id")&&s.get("id")!=this.state.escrow_account.get("id")||(B="showcases.barter.error_same_name_escrow"):B="showcases.barter.error_fill_in_valid_asset_amount":B="showcases.barter.error_fill_in_peer_right_name":B="showcases.barter.error_fill_in_peer_left_name");let D=d.createElement(p.Card,{style:{borderRadius:"10px"}},!k&&d.createElement("div",{className:"left-label",style:{fontSize:"1rem"}},b().translate("showcases.barter.action",{peer_left:e,assets_left:f.join(", "),peer_right:t,assets_right:E.join(", ")}),this.state.showEscrow&&!this.state.send_to_escrow&&b().translate("showcases.barter.escrow_as_witness",{escrow:this.state.escrow_account.get("name")}),this.state.showEscrow&&this.state.send_to_escrow&&b().translate("showcases.barter.escrow_as_custodian",{escrow:this.state.escrow_account.get("name")})),k&&d.createElement("div",{className:"left-label",style:{fontSize:"1rem"}},b().translate(B)),d.createElement(p.Tooltip,{title:b().translate("showcases.barter.add_escrow_tooltip"),placement:"topRight"},d.createElement(p.Button,{key:this.state.showEscrow?"remove_escrow":"add_escrow",onClick:this.toggleEscrow.bind(this),style:{float:"right"}},b().translate(this.state.showEscrow?"showcases.barter.remove_escrow":"showcases.barter.add_escrow"))),500===n.length&&500===o.length?d.createElement("div",{className:"amount-selector",style:this.props.style},d.createElement(h(),{className:"left-label",component:"label",content:"transfer.explict_price"}),d.createElement("div",{className:"inline-label input-wrapper"},d.createElement(p.Input,{disabled:!1,type:"text",value:(()=>{let e="";return A()&&(e=parseFloat(n[0].from_amount)/parseFloat(o[0].to_amount)),e})()}),d.createElement("div",{className:"form-label select floating-dropdown"},d.createElement("div",{className:"dropdown-wrapper inactive"},d.createElement("div",null,"/"))))):""),O=d.createElement(p.Card,{style:{borderRadius:"10px"}},d.createElement(h(),{content:"showcases.barter.peer_left"}),d.createElement(p.Tooltip,{title:b().translate(this.state.send_to_escrow?"showcases.barter.fee_due_now_tooltip":"showcases.barter.fee_when_proposal_executes_tooltip")},d.createElement("div",{className:"barter-fee-selector"},d.createElement(_.A,{label:this.state.send_to_escrow?"showcases.barter.fee_due_now":"showcases.barter.fee_when_proposal_executes",account:a,transaction:{type:"transfer",options:["price_per_kbyte"],data:{type:"memo",content:null}},onChange:this.onFeeChangedPeer1InProposal.bind(this),multiplier:n.length}))),d.createElement(p.Tooltip,{title:b().translate("showcases.barter.proposal_fee_tooltip")},d.createElement("div",{className:"barter-fee-selector"},d.createElement(_.A,{label:"showcases.barter.proposal_fee",account:a,transaction:{type:"proposal_create",options:["price_per_kbyte"],data:{type:"memo",content:null}},onChange:this.onFeeChangedPeer1CreateProposal.bind(this)}))),d.createElement(p.Tooltip,{title:b().translate("showcases.barter.total_fees_tooltip")},d.createElement("span",{style:{marginTop:"1rem"}},d.createElement(h(),{content:"showcases.barter.total_fees",className:"left-label",component:"label",fee:v(!0)+this.state.proposal_fee._real_amount,asset:"BTS"})))),F=d.createElement(p.Card,{style:{borderRadius:"10px"}},d.createElement(h(),{content:"showcases.barter.peer_right"}),d.createElement(p.Tooltip,{title:b().translate("showcases.barter.fee_when_proposal_executes_tooltip")},d.createElement("div",{className:"barter-fee-selector"},d.createElement(_.A,{label:"showcases.barter.fee_when_proposal_executes",account:s,transaction:{type:"transfer",options:["price_per_kbyte"],data:{type:"memo",content:null}},onChange:this.onFeeChangedPeer2InProposal.bind(this),multiplier:o.length})))),R=null;this.state.showEscrow&&(R=d.createElement(p.Card,{style:{borderRadius:"10px"}},d.createElement(h(),{content:"showcases.barter.escrow_account"}),d.createElement(p.Tooltip,{title:b().translate("showcases.barter.fee_when_proposal_executes_tooltip")},d.createElement("div",{className:"barter-fee-selector"},d.createElement(_.A,{label:"showcases.barter.fee_when_proposal_executes",account:this.state.escrow_account,transaction:{type:"transfer",options:["price_per_kbyte"],data:{type:"memo",content:null}},onChange:this.onEscrowFeeChanged.bind(this),multiplier:n.length})))));let P=d.createElement(p.Card,{style:{borderRadius:"10px"}},d.createElement(p.Tooltip,{title:b().translate("showcases.barter.new_barter_tooltip"),placement:"bottom"},d.createElement("h2",{style:{textAlign:"center"}},d.createElement(h(),{content:"showcases.barter.new_barter"})," ",d.createElement(p.Icon,{type:"question-circle",theme:"filled"})))),V=null,j=this.state.memo.escrow[0]&&this.state.memo.escrow[0].shown,z=this.state.escrow_payment_changed?this.state.escrow_payment:v(!0);return this.state.showEscrow&&(V=d.createElement(p.Card,{style:{borderRadius:"10px"}},d.createElement(u.A,{label:"showcases.barter.escrow_account",placeholder:"placeholder",style:{marginBottom:"1rem"},allowPubKey:!0,allowUppercase:!0,account:this.state.escrow_account,accountName:this.state.escrow_account_name,onChange:this.escrowAccountChanged.bind(this),onAccountChanged:this.onEscrowAccountChanged.bind(this),hideImage:!0,typeahead:!0}),d.createElement(p.Tooltip,{title:b().translate("showcases.barter.send_to_escrow_tooltip")},d.createElement("span",null,d.createElement(p.Switch,{style:{margin:6},checked:this.state.send_to_escrow,onChange:this.onToggleSendToEscrow.bind(this)}),d.createElement(h(),{content:"showcases.barter.send_to_escrow"}))),d.createElement("div",{style:{position:"relative"}},!j&&d.createElement(p.Tooltip,{title:b().translate("tooltip.add_memo_field"),placement:"topLeft"},d.createElement(p.Button,{onClick:this.handleMemoOpen("escrow",0),size:"small",icon:"message",className:"add-memo-btn"})),d.createElement(p.Tooltip,{title:b().translate("showcases.barter.escrow_payment_tooltip"),placement:"topLeft"},d.createElement("div",null,d.createElement(y.A,{label:"showcases.barter.escrow_payment",disabled:!1,amount:z,onChange:this._updateEscrowFee.bind(this),style:{margin:"1rem 0"},asset:"1.3.0",assets:["1.3.0"],error:!1===this.state.hasPoolBalance?"transfer.errors.insufficient":null,scroll_length:2}))),j&&this.renderMemoField("escrow",0)))),d.createElement("div",{className:"center",style:{padding:"10px",maxWidth:"80rem",width:"100%",margin:"0 auto"}},d.createElement(p.Card,null,g?d.createElement("div",null,d.createElement(p.Row,null,d.createElement(p.Col,{style:{padding:"10px"}},P)),d.createElement(p.Row,null,d.createElement(p.Col,{style:{padding:"10px"}},T)),d.createElement(p.Row,null,d.createElement(p.Col,{style:{padding:"10px"}},I)),d.createElement(p.Row,null,d.createElement(p.Col,{style:{padding:"10px"}},D)),V&&d.createElement(p.Row,null,d.createElement(p.Col,{style:{padding:"10px"}},V)),d.createElement(p.Row,null,d.createElement(p.Col,{style:{padding:"10px"}},O)),d.createElement(p.Row,null,d.createElement(p.Col,{style:{padding:"10px"}},F)),null!=R&&d.createElement(p.Row,null,d.createElement(p.Col,{style:{padding:"10px"}},R))):d.createElement("div",null,d.createElement(p.Row,null,d.createElement(p.Col,{style:{padding:"10px"}},P)),d.createElement(p.Row,null,d.createElement(p.Col,{span:12,style:{padding:"10px"}},T),d.createElement(p.Col,{span:12,style:{padding:"10px"}},I)),d.createElement(p.Row,null,d.createElement(p.Col,{style:{padding:"10px"}},D)),V&&d.createElement(p.Row,null,d.createElement(p.Col,{style:{padding:"10px"}},V)),d.createElement(p.Row,null,d.createElement(p.Col,{span:12,style:{padding:"10px"}},O),d.createElement(p.Col,{span:12,style:{padding:"10px"}},F,R))),d.createElement("div",{className:"barter-footer"},d.createElement(p.Tooltip,{title:b().translate("showcases.barter.propose_tooltip"),placement:"topLeft"},d.createElement(p.Button,{key:"propose",disabled:k,onClick:k?null:this.onSubmit.bind(this)},b().translate("propose"))),!k&&this.renderBalanceWarnings())))}_updateEscrowFee(e){this.setState({escrow_payment_changed:!0,escrow_payment:e.amount})}onToggleSendToEscrow(){this.setState({send_to_escrow:!this.state.send_to_escrow})}toggleEscrow(){this.setState({showEscrow:!this.state.showEscrow})}}},82859:(e,t,a)=>{a.r(t),a.d(t,{default:()=>w});var s=a(96540),n=a(10658),o=a.n(n),r=a(80849),i=a.n(r),l=a(46128),c=a(83599),d=(a(60819),a(9476)),m=a(72090),h=a(51579),p=a(35277),u=a(55840),_=a(36234),g=a(79260),b=a(40961);class f extends s.Component{constructor(){super(),this.state={isBorrowBaseModalVisible:!1,selectedAsset:null,step:0},this.steps=[{key:"introduction",icon:"borrow"},{key:"concept",has_legend:!0},{key:"setup",has_legend:!0},{key:"benefits",has_legend:!0},{key:"risks",has_legend:!0}],this.showBorrowModal=this.showBorrowModal.bind(this),this.hideBorrowModal=this.hideBorrowModal.bind(this)}showBorrowModal(){this.props.currentAccount?this.setState({isBorrowBaseModalVisible:!0}):h.A.unlock().then((()=>{this.setState({isBorrowBaseModalVisible:!0})})).catch((()=>{}))}hideBorrowModal(){this.setState({isBorrowBaseModalVisible:!1})}next(){let e=this.state.step+1;e>=this.steps.length&&(e=this.steps.length),this.setState({step:e})}prev(){let e=this.state.step-1;e<0&&(e=0),this.setState({step:e})}onAssetChange(e){this.setState({selectedAsset:e})}render(){let e=m.ChainStore.getAccount(this.props.currentAccount),t=!(!e||"string"==typeof e);const a=this.state.step,n=window.innerWidth<=800,r=this.state.step>0,c=m.ChainStore.getAsset(this.state.selectedAsset);let d=this.steps,h=null;if(a<d.length)try{d[a].has_legend&&(h=o().translate("showcases.borrow.steps_"+d[a].key+".text_legend"),h=h.split("\n").map((e=>e.split(":"))))}catch(e){h=o().translate("showcases.borrow.steps_"+d[a].key+".text_legend")}let u=null;return a>=d.length&&(u=s.createElement(l.Card,null,s.createElement("div",{className:"center-content"},s.createElement(i(),{content:"showcases.borrow.choose",component:"h4"})),s.createElement("div",{style:{display:"flex",justifyContent:"center"}},s.createElement("div",null,s.createElement(g.A,{style:{width:"12rem",marginBottom:"1rem"},assets:["1.3.113","1.3.120","1.3.121","1.3.1325","1.3.105","1.3.106","1.3.103","1.3.5641","1.3.5649","1.3.5650","1.3.5651","1.3.5652","1.3.5659","1.3.5660","1.3.5661","1.3.5662","1.3.6289","1.3.6290","1.3.4633","1.3.4634","1.3.4635","1.3.1382"],value:this.state.selectedAsset,onChange:this.onAssetChange.bind(this)}),s.createElement(l.Tooltip,{title:o().translate("showcases.borrow.borrow_tooltip"),placement:"bottom"},s.createElement(l.Button,{type:"primary",style:{width:"12rem"},disabled:null===this.state.selectedAsset||!t||"1.2.3"===e.get("id"),onClick:this.showBorrowModal},s.createElement(i(),{content:"exchange.borrow"}))))))),s.createElement("div",{style:{align:"center",display:"flex",paddingTop:"1rem",justifyContent:"center"},onKeyDown:this.onKeyDown.bind(this)},s.createElement(l.Card,{style:{borderRadius:"50px",width:"70%",maxWidth:"70rem",paddingTop:"1rem",paddingBottom:"1rem"}},s.createElement("div",{style:{display:"flex",justifyContent:"center"}},s.createElement(i(),{component:"h1",content:null!=u?"showcases.borrow.now_ready":"showcases.borrow.title_long"})),r&&(n?a<this.steps.length?s.createElement(s.Fragment,null,a+". ",s.createElement(i(),{content:"showcases.borrow.steps_"+d[a].key+".title"})):null:s.createElement(l.Steps,{progressDot:!0,current:a-1},d.map(((e,t)=>0==t?null:s.createElement(l.Steps.Step,{key:e.key,title:o().translate("showcases.borrow.steps_"+e.key+".title")}))))),s.createElement("div",{style:{paddingTop:"1rem",paddingBottom:"1rem"}},null!=u&&u,null==u&&s.createElement(l.Card,{onKeyDown:this.onKeyDown.bind(this)},!!d[a].icon&&s.createElement(_.A,{name:"steps[current].icon"}),s.createElement(i(),{component:"h2",content:"showcases.borrow.steps_"+d[a].key+".title_within"}),s.createElement(i(),{component:"p",content:"showcases.borrow.steps_"+d[a].key+".text"}),!!d[a].has_legend&&s.createElement(s.Fragment,null,h.map(((e,t)=>s.createElement("p",{key:"borrow_subp_"+t},s.createElement("strong",null,e[0]),": ",e[1])))))),s.createElement("div",{className:"steps-action"},a<d.length&&s.createElement(l.Tooltip,{title:0==a?o().translate("showcases.borrow.navigate_with_keys"):null},s.createElement(l.Button,{type:"primary",onClick:()=>this.next(),tabIndex:"0",ref:"next",onKeyDown:this.onKeyDown.bind(this)},0==a&&s.createElement(i(),{content:"showcases.borrow.get_started"}),a>0&&a<d.length-1&&s.createElement(i(),{content:"showcases.borrow.next"}),a===d.length-1&&s.createElement(i(),{content:"showcases.borrow.do_it"}))),a>0&&s.createElement(l.Button,{style:{marginLeft:8},onClick:()=>this.prev(),ref:"previous",onKeyDown:this.onKeyDown.bind(this)},s.createElement(i(),{content:"showcases.borrow.previous"})))),t&&!!c&&s.createElement(p.A,{visible:this.state.isBorrowBaseModalVisible,hideModal:this.hideBorrowModal,quoteAssetObj:c.get("id"),backingAssetObj:c.getIn(["bitasset","options","short_backing_asset"]),accountObj:e}))}componentDidMount(){this.focusDiv()}componentDidUpdate(){this.focusDiv()}focusDiv(){let e=this.state.step,t=this.steps;e<t.length&&this.refs.next?b.findDOMNode(this.refs.next).focus():e==t.length&&this.refs.previous&&b.findDOMNode(this.refs.previous).focus()}onKeyDown(e){39===e.keyCode||"ArrowRight"==e.key?(e.preventDefault(),e.stopPropagation(),this.next()):37!==e.keyCode&&"ArrowLeft"!=e.key||(e.preventDefault(),e.stopPropagation(),this.prev())}}f=(0,c.Ay)(f,50,{leading:!1});const w=(0,d.N)(f,{listenTo:()=>[u.A],getProps:()=>({currentAccount:u.A.getState().currentAccount||u.A.getState().passwordAccount})})},72295:(e,t,a)=>{a.r(t),a.d(t,{default:()=>K});var s=a(96540),n=a(62716),o=a(46128),r=a(10658),i=a.n(r),l=a(72090),c=a(87040),d=a(65924),m=a(80849),h=a.n(m),p=a(49585),u=a(96366),_=a(62611),g=(a(9404),a(60819),a(5556)),b=a.n(g);class f extends s.Component{static propTypes={label:b().string,placeholder:b().string,onChange:b().func,tabIndex:b().number,error:b().string,scroll_length:b().number};static defaultProps={disabled:!1,tabIndex:0};getNumericEventValue(e){return""==e.target.value||null==e.target.value||e.target.value<0?"":0===e.target.value?0:parseFloat(e.target.value)==e.target.value?e.target.value.trim():parseFloat(e.target.value.trim().replace(/[^\d.-]/g,""))||0}onInputChange=e=>{const{onChange:t,periodType:a}=this.props;t&&t({amount:this.getNumericEventValue(e),type:a})};onTypeChange=e=>{const{onChange:t,inputValue:a}=this.props;t&&t({amount:a,type:e})};render(){const{inputValue:e,values:t,entries:a,periodType:n,tabIndex:o,placeholder:r,disabled:i,scroll_length:l}=this.props;return s.createElement("div",{className:"amount-selector",style:this.props.style},s.createElement(h(),{className:"left-label",component:"label",content:this.props.label}),s.createElement("div",{className:"inline-label input-wrapper"},s.createElement("span",{className:"input-addon-before"},"Each"),s.createElement("input",{disabled:i,type:"number",value:e||"",placeholder:r,onChange:this.onInputChange,tabIndex:o,style:{paddingLeft:"70px"}}),s.createElement("div",{className:"form-label select floating-dropdown"},s.createElement(_.A,{entries:a,values:t,value:n&&n.name,onChange:this.onTypeChange,scroll_length:l}))))}}const w=f;var y=a(84181),E=a(55840),A=a(1951),v=a(18483),C=a(24609),S=a(15483),k=a(89247),x=a(9476),N=a(74248),M=a(10344),T=a(8080),I=a(95093),B=a.n(I);class D extends s.Component{constructor(e){super(e),this.state=this.getInitialState(e),this.onTrxIncluded=this.onTrxIncluded.bind(this),this._checkBalance=this._checkBalance.bind(this),this._isMounted=!1}getInitialState(){return{to_name:"",from_account:null,to_account:null,amount:"",asset_id:null,asset:null,error:null,fee_asset_id:l.ChainStore.assets_by_symbol.get(this.props.fee_asset_symbol)||"1.3.0",feeAmount:new C.Vd({amount:0}),feeStatus:{},maxAmount:!1,num_of_periods:"",period:{amount:"",type:{seconds:604800,name:"Week"}},period_start_time:B()().add("seconds",120),permissionId:"",balanceError:!1}}onSubmit=e=>{e.preventDefault();let{from_account:t,to_account:a,amount:s,asset:n,asset_id:o,fee_asset_id:r,period:i,num_of_periods:l,period_start_time:d,permissionId:m}=this.state;const{operation:{type:h}}=this.props;"create"===h?T.A.createWithdrawPermission(t,a,o,c.A.convert_typed_to_satoshi(s,n),i.type.seconds*Number(i.amount),l,d.valueOf(),r).then((e=>{this.props.hideModal()})).catch((e=>{console.error(e)})):"update"===h&&T.A.updateWithdrawPermission(m,t,a,o,c.A.convert_typed_to_satoshi(s,n),i.type.seconds*Number(i.amount),l,d.valueOf(),r).then((e=>{this.props.hideModal()})).catch((e=>{console.error(e)}))};componentDidMount(){this._isMounted=!0}componentDidUpdate(e,t){const{operation:a,currentAccount:s}=this.props;if(s===e.currentAccount&&null!=this.state.from_account||this.setState({from_account:l.ChainStore.getAccount(s)}),a&&"update"===a.type&&a.payload.id!==t.permissionId){const e=l.ChainStore.getAccount(a.payload.authorized_account);if(e&&e.get){const t=B().utc(a.payload.period_start_time).valueOf(),s=(B().utc(a.payload.expiration).valueOf()-t)/(1e3*a.payload.withdrawal_period_sec),n=[{seconds:604800,name:"Week"},{seconds:86400,name:"Day"},{seconds:3600,name:"Hour"},{seconds:60,name:"Minute"}];let o,r,i;for(let e=0;e<n.length;e++)if(a.payload.withdrawal_period_sec>=n[e].seconds){let t=n[e];r=t.name,o=t.seconds,i=Math.round(a.payload.withdrawal_period_sec/t.seconds);break}let d=l.ChainStore.getAsset(a.payload.withdrawal_limit.asset_id);this.setState({to_account:e,to_name:e.get("name"),asset:d,permissionId:a.payload.id,amount:c.A.convert_satoshi_to_typed(a.payload.withdrawal_limit.amount,d),asset_id:a.payload.withdrawal_limit.asset_id,num_of_periods:s,period:{amount:i,type:{seconds:o,name:r}},period_start_time:B().utc(a.payload.period_start_time)})}}}componentWillUnmount(){this._isMounted=!1}_checkBalance(){const{feeAmount:e,amount:t,from_account:a,asset:s}=this.state;if(!s||!a)return;const n=a.getIn(["balances",s.get("id")]),o=a.getIn(["balances",e.asset_id]);if(!s||!a)return;if(!n)return this.setState({balanceError:!0});let r=l.ChainStore.getObject(n),i=o?l.ChainStore.getObject(o):null;if(i&&0!==i.get("balance")||this.setState({fee_asset_id:this.state.fee_asset_id}),!r||!e)return;if(!t)return this.setState({balanceError:!1});const c=(0,S.rT)(t,s,e,r);null!==c&&this.setState({balanceError:!c})}_setTotal(e,t){const{feeAmount:a}=this.state;let s=l.ChainStore.getObject(t),n=l.ChainStore.getObject(e),o=new C.Vd({amount:s.get("balance"),asset_id:n.get("id"),precision:n.get("precision")});s&&(a.asset_id===o.asset_id&&o.minus(a),this.setState({maxAmount:!0,amount:o.getAmount({real:!0})},this._checkBalance))}_getAvailableAssets(e=this.state){const{from_account:t}=e;let a=[],s=[];if(!t||!t.get("balances"))return{asset_types:a,fee_asset_types:s};let n=e.from_account.get("balances").toJS();a=Object.keys(n).sort(c.A.sortID),s=Object.keys(n).sort(c.A.sortID);for(let e in n){let t=l.ChainStore.getObject(n[e]);t&&0===t.get("balance")&&(a.splice(a.indexOf(e),1),-1!==s.indexOf(e)&&s.splice(s.indexOf(e),1))}return{asset_types:a,fee_asset_types:s}}onToAccountChanged=e=>{this.setState({to_account:e,error:null})};onAmountChanged=({amount:e,asset:t})=>{t&&this.setState({amount:e,asset:t,asset_id:t.get("id"),error:null,maxAmount:!1},this._checkBalance)};toChanged=e=>{this.setState({to_name:e,error:null})};onFeeChanged(e){this.setState({fee_asset_id:e.asset_id,error:null})}onTrxIncluded(e){(e.included&&e.broadcasted_transaction||e.closed)&&(v.A.unlisten(this.onTrxIncluded),v.A.reset())}onNumOfPeriodsChanged=e=>{let t=parseInt(e.target.value,10);!(0,d.A)(t)&&"number"==typeof t&&t>=0&&this.setState({num_of_periods:t})};onPeriodChanged=({amount:e,type:t})=>{this.setState({period:{amount:e,type:t}})};onDatepickerRef(e){e&&e.picker.input&&(e.picker.input.readOnly=!1)}onStartDateChanged=e=>{e?this.setState({period_start_time:e}):this.setState({period_start_time:null})};render(){let{from_account:e,to_account:t,asset:a,asset_id:n,amount:r,to_name:c,fee_asset_id:m,balanceError:u,num_of_periods:_,period:g,period_start_time:b}=this.state;const{operation:f}=this.props;let{asset_types:E}=this._getAvailableAssets(),v=null,C=this.state.feeAmount.getAmount({real:!0});if(e&&e.get("balances")){let t=e.get("balances").toJS(),n=this.state.balanceError?"has-error":"";if(1===E.length&&(a=l.ChainStore.getAsset(E[0])),E.length>0){let e=a?a.get("id"):E[0],o=m;v=s.createElement("span",null,s.createElement(h(),{component:"span",content:"transfer.available"}),":"," ",s.createElement("span",{className:n,style:{borderBottom:"#A09F9F 1px dotted",cursor:"pointer"},onClick:this._setTotal.bind(this,e,t[e],C,o)},s.createElement(k.A,{balance:t[e]}))),o==e&&this.state.balanceError&&(balance_fee=s.createElement("span",null,s.createElement("span",{className:n},s.createElement(h(),{content:"transfer.errors.insufficient"}))))}else v=s.createElement("span",null,s.createElement("span",{className:n},s.createElement(h(),{content:"transfer.errors.noFunds"}))),balance_fee=s.createElement("span",null,s.createElement("span",{className:n},s.createElement(h(),{content:"transfer.errors.noFunds"})))}const S=parseFloat(String.prototype.replace.call(r,/,/g,"")),x=S&&!(0,d.A)(S),N=!e||!t||!x||!a||u||e.get("id")==t.get("id")||!g.amount||!_||!b;return s.createElement(o.Modal,{title:f&&"create"===f.type?i().translate("showcases.direct_debit.create_new_mandate"):i().translate("showcases.direct_debit.update_mandate"),visible:this.props.isModalVisible,overlay:!0,onCancel:this.props.hideModal,footer:[s.createElement(o.Button,{key:"send",disabled:N,onClick:N?null:this.onSubmit.bind(this)},f&&"create"===f.type?i().translate("showcases.direct_debit.create"):i().translate("showcases.direct_debit.update")),s.createElement(o.Button,{key:"Cancel",onClick:this.props.hideModal},s.createElement(h(),{component:"span",content:"transfer.cancel"}))]},s.createElement("div",{className:"grid-block vertical no-overflow"},s.createElement(o.Form,{className:"full-width",layout:"vertical"},s.createElement("div",null,s.createElement(o.Tooltip,{title:i().translate("showcases.direct_debit.tooltip.authorized_account"),mouseEnterDelay:.5},s.createElement("div",{className:"content-block"},s.createElement(A.A,{label:"showcases.direct_debit.authorized_account",accountName:c,account:t,onChange:this.toChanged.bind(this),onAccountChanged:this.onToAccountChanged,size:60,typeahead:!0,hideImage:!0})))),s.createElement(o.Tooltip,{title:i().translate("showcases.direct_debit.tooltip.limit_per_period"),mouseEnterDelay:.5},s.createElement("div",{className:"content-block transfer-input"},s.createElement(p.A,{label:"showcases.direct_debit.limit_per_period",amount:r,onChange:this.onAmountChanged,asset:E.length>0&&a?a.get("id"):n||E[0],assets:E,display_balance:v,allowNaN:!0}))),s.createElement(o.Tooltip,{title:i().translate("showcases.direct_debit.tooltip.period"),mouseEnterDelay:.5},s.createElement("div",{className:"content-block transfer-input"},s.createElement(w,{label:"showcases.direct_debit.period",inputValue:g.amount,entries:["Minute","Hour","Day","Week"],values:{Minute:{seconds:60,name:"Minute"},Hour:{seconds:3600,name:"Hour"},Day:{seconds:86400,name:"Day"},Week:{seconds:604800,name:"Week"}},periodType:g.type,onChange:this.onPeriodChanged}))),s.createElement(o.Tooltip,{title:i().translate("showcases.direct_debit.tooltip.num_of_periods"),mouseEnterDelay:.5},s.createElement("div",{className:"content-block transfer-input"},s.createElement("label",{className:"left-label"},i().translate("showcases.direct_debit.num_of_periods")),s.createElement("input",{type:"number",value:_,onChange:this.onNumOfPeriodsChanged}))),s.createElement("div",{className:"content-block transfer-input"},s.createElement("label",{className:"left-label"},i().translate("showcases.direct_debit.start_date")),s.createElement(o.Tooltip,{title:i().translate("showcases.direct_debit.tooltip.start_time"),mouseEnterDelay:.5},s.createElement(M.A,{value:b,showToday:!1,showTime:!0,placeholder:"",onChange:this.onStartDateChanged,className:"date-picker-width100",style:{width:"100%"},ref:e=>this.onDatepickerRef(e),disabledDate:e=>e&&e<B()().add(2,"minutes")}))),s.createElement("div",{className:"content-block transfer-input"},s.createElement("div",{className:"no-margin no-padding"},s.createElement(y.A,{account:e,transaction:{type:f&&"update"===f.type?"withdraw_permission_update":"withdraw_permission_create",options:["price_per_kbyte"],data:{type:"memo",content:null}},onChange:this.onFeeChanged.bind(this)}))))))}}const O=(0,x.N)(D,{listenTo:()=>[E.A,N.A],getProps:()=>({currentAccount:E.A.getState().currentAccount,passwordAccount:E.A.getState().passwordAccount,fee_asset_symbol:N.A.getState().settings.get("fee_asset")})});var F=a(50548);a(83599);class R extends s.Component{static propTypes={hide_asset:b().bool};static defaultProps={hide_asset:!1};render(){return s.createElement(u.A,{amount:this.props.amount,asset:this.props.assetId,asPercentage:this.props.asPercentage,assetInfo:this.props.assetInfo,replace:this.props.replace,hide_asset:this.props.hide_asset})}}const P=R;var V=a(16e3),j=a(48287).Buffer;class z extends s.Component{constructor(e){super(e),this.state=this.getInitialState(e)}getInitialState(){return{to_name:"",from_account:null,from_account_balance:null,to_account:null,amount:"",asset_id:null,asset:null,memo:"",error:null,feeAsset:null,maxAmount:!1,permissionId:"",firstPeriodError:!1,payerBalanceWarning:!1,withdrawal_limit:this.props.operation.payload.withdrawal_limit,current_period_expires:"",claimedAmount:"",errorMessage:null}}onSubmit=e=>{e.preventDefault();const{from_account:t,to_account:a,feeAsset:s,permissionId:n,amount:o,asset:r,asset_id:i,memo:l}=this.state;T.A.claimWithdrawPermission(n,t,a,i,c.A.convert_typed_to_satoshi(o,r),l?new j(l,"utf-8"):l,s.asset_id).then((e=>{this.props.hideModal()})).catch((e=>{this.setState({errorMessage:e})}))};async componentDidUpdate(e,t){const{operation:a,isModalVisible:s}=this.props;if(s&&a&&t.permissionId!==a.payload.id){const e=new Date(a.payload.period_start_time+"Z").getTime(),t=(new Date).getTime()-e;let s,n="";const o=1e3*a.payload.withdrawal_period_sec;t<0?console.log("first period is not started"):(s=Math.ceil(t/o),n=e+o*s);const r=await(0,l.FetchChain)("getAccount",a.payload.authorized_account),i=await(0,l.FetchChain)("getAccount",a.payload.withdraw_from_account),c=await(0,l.FetchChain)("getAsset",a.payload.withdrawal_limit.asset_id),d=await this._checkBalance(i,a.payload.withdrawal_limit);this.setState({to_account:r,from_account:i,permissionId:a.payload.id,withdrawal_limit:a.payload.withdrawal_limit,claimedAmount:a.payload.claimed_this_period,current_period_expires_date:n,asset:c,from_account_balance:d})}}setTotalLimit=e=>()=>{const{asset:t,claimedAmount:a}=this.state;let s=c.A.get_asset_amount(e-a,t);this.setState({maxAmount:!0,amount:s})};onAmountChanged=({amount:e,asset:t})=>{t&&this.setState({amount:e,asset:t,asset_id:t.get("id"),error:null,maxAmount:!1})};onFeeChanged(e){this.setState({feeAsset:e})}onMemoChanged(e){this.setState({memo:e.target.value})}async _checkBalance(e=null,t=null){let a=!1;null==e&&(e=this.state.from_account,a=!0),null==t&&(t=this.state.withdrawal_limit,a=!0);const s=e.getIn(["balances",t.asset_id]);let n=0;return s&&(n=(await(0,l.FetchChain)("getObject",s)).get("balance")),a&&this.setState({from_account_balance:n}),n}render(){let{from_account:e,from_account_balance:t,to_account:a,asset:n,amount:r,memo:l,payerBalanceWarning:m,withdrawal_limit:p,current_period_expires_date:u}=this.state,_=!1,g=!1,b=0;p&&(b=null!==t?Math.min(t,p.amount):p.amount,n&&r&&(_=c.A.convert_typed_to_satoshi(r,n)>b),null!==t&&t<p.amount&&(g=!0));let f=null;e&&e.get("balances")&&(f=s.createElement("span",null,s.createElement(h(),{component:"span",content:"showcases.direct_debit.limit"}),":"," ",s.createElement("span",{className:_?"has-error":"",style:{borderBottom:"#A09F9F 1px dotted",cursor:"pointer"},onClick:this.setTotalLimit(b)},s.createElement(P,{amount:b,assetId:p&&p.asset_id}))," ",g&&s.createElement(o.Tooltip,{placement:"topRight",title:s.createElement(V.A,{string:"showcases.direct_debit.payer_balance_not_sufficient",keys:[{type:"amount",value:p,arg:"limit"}]})},s.createElement(o.Icon,{type:"exclamation-circle",theme:"filled",style:{color:"#fe8c00"}}))));const w=parseFloat(String.prototype.replace.call(r,/,/g,"")),E=w&&!(0,d.A)(w),v=!e||!a||!E||!n||g||_||m||!u||e.get("id")==a.get("id");return s.createElement(o.Modal,{title:i().translate("showcases.direct_debit.claim_funds"),visible:this.props.isModalVisible,overlay:!0,onCancel:this.props.hideModal,footer:[this.state.errorMessage&&s.createElement("span",{className:"red",style:{marginRight:"10px"}},this.state.errorMessage),s.createElement(o.Button,{key:"send",disabled:v,onClick:v?null:this.onSubmit.bind(this)},i().translate("showcases.direct_debit.claim")),s.createElement(o.Button,{key:"Cancel",onClick:this.props.hideModal},s.createElement(h(),{component:"span",content:"transfer.cancel"}))]},s.createElement("div",{className:"grid-block vertical no-overflow"},s.createElement(o.Form,{className:"full-width",layout:"vertical"},s.createElement(A.A,{label:"showcases.direct_debit.authorizing_account",accountName:a?a.get("name"):"",account:a,size:60,hideImage:!0,disabled:!0,noForm:!0}),s.createElement(o.Form.Item,{label:i().translate("showcases.direct_debit.current_period_expires")},s.createElement(o.Input,{type:"text",value:u?i().localize(new Date(u),{type:"date",format:"full"}):i().translate("showcases.direct_debit.first_period_not_started"),disabled:!0,className:u?"":"error-area"})),s.createElement(F.A,{label:"showcases.direct_debit.amount_to_withdraw",amount:r,onChange:this.onAmountChanged,asset:p&&p.asset_id,assets:p&&[p.asset_id],display_balance:f,allowNaN:!0}),l&&l.length?s.createElement("label",{className:"right-label"},l.length):null,s.createElement(o.Form.Item,{label:s.createElement(o.Tooltip,{placement:"top",title:i().translate("tooltip.memo_tip")},i().translate("transfer.memo"))},s.createElement(o.Input.TextArea,{style:{marginBottom:0},rows:"3",value:l,onChange:this.onMemoChanged.bind(this)})),s.createElement(y.A,{account:a,transaction:{type:"withdraw_permission_claim",options:["price_per_kbyte"],data:{type:"memo",content:l}},onChange:this.onFeeChanged.bind(this)}))))}}const L=z;var W=a(24873),H=a(37556);class U extends s.Component{constructor(e){super(e),this.state={isModalVisible:!1,isClaimModalVisible:!1,filterString:"",operationData:"",operationClaimData:"",withdraw_permission_list:[]}}_update(){let e=this.props.currentAccount;(0,H.K)(e)&&Promise.all([n.Apis.instance().db_api().exec("get_withdraw_permissions_by_giver",[e.get("id"),"1.12.0",100]),n.Apis.instance().db_api().exec("get_withdraw_permissions_by_recipient",[e.get("id"),"1.12.0",100])]).then((e=>{let t=[];t=t.concat(e[0]),t=t.concat(e[1]),t.forEach((e=>{try{l.ChainStore.getAccount(e.authorized_account,!1),l.ChainStore.getAccount(e.withdraw_from_account,!1)}catch(e){}})),this.setState({withdraw_permission_list:t})}))}componentDidMount(){this._update()}UNSAFE_componentWillReceiveProps(){this._update()}showModal=e=>()=>{this.setState({isModalVisible:!0,operationData:e})};hideModal=()=>{this.setState({isModalVisible:!1,operation:null})};showClaimModal=e=>()=>{this.setState({isClaimModalVisible:!0,operationClaimData:e})};hideClaimModal=()=>{this.setState({isClaimModalVisible:!1})};_onFilter=e=>{e.preventDefault(),this.setState({filterString:e.target.value.toLowerCase()})};handleDeleteProposal=e=>{console.log("delete permissin"),T.A.deleteWithdrawPermission(e.id,e.withdraw_from_account,e.authorized_account).then((()=>{})).catch((e=>{this.setState({errorMessage:e.toString()}),console.error(e)}))};render(){const{isModalVisible:e,isClaimModalVisible:t,withdraw_permission_list:a,operationData:n,operationClaimData:r,filterString:d}=this.state;let m=this.props.currentAccount,h=null;a.length&&(h=a.map((e=>{const t=l.ChainStore.getObject(e.withdrawal_limit.asset_id,!1),a=l.ChainStore.getAccountName(e.authorized_account),n=l.ChainStore.getAccountName(e.withdraw_from_account),o=new Date(e.period_start_time+"Z").getTime(),r=(new Date).getTime()-o;let d="";const h=1e3*e.withdrawal_period_sec;return r<0?console.log("first period is not started"):d=o+h*Math.ceil(r/h),{key:e.id,id:e.id,type:e.authorized_account==m.get("id")?"payee":"payer",authorized:a,from:n,to:a,limit:s.createElement("span",null,c.A.get_asset_amount(e.withdrawal_limit.amount,t)+" ",s.createElement(W.A,{asset:e.withdrawal_limit.asset_id})),until:d?i().localize(new Date(d),{type:"date",format:"full"}):i().translate("showcases.direct_debit.first_period_not_started"),expires:i().localize(new Date(e.expiration+"Z"),{type:"date",format:"full"}),claimed:0==e.claimed_this_period?"-":s.createElement("span",null,c.A.get_asset_amount(e.claimed_this_period,t)+" ",s.createElement(W.A,{asset:e.withdrawal_limit.asset_id})),rawData:{...e}}})),h.length&&h.filter((e=>e.authorized&&-1!==e.authorized.indexOf(d))));const p=[{title:"#",dataIndex:"id",key:"id",sorter:(e,t)=>e.id>t.id?1:e.id<t.id?-1:0},{title:"From",dataIndex:"from",key:"from",sorter:(e,t)=>e.from>t.from?1:e.from<t.from?-1:0},{title:"To",dataIndex:"to",key:"to",sorter:(e,t)=>e.to>t.to?1:e.to<t.to?-1:0},{title:i().translate("showcases.direct_debit.current_period_expires"),dataIndex:"until",key:"until",sorter:(e,t)=>e.until>t.until?1:e.until<t.until?-1:0},{title:"Limit",dataIndex:"limit",key:"limit",sorter:(e,t)=>e.rawData.withdrawal_limit.amount-t.rawData.withdrawal_limit.amount},{title:"Claimed",dataIndex:"claimed",key:"claimed",sorter:(e,t)=>{const a=e.rawData.claimed_this_period;return e.rawData.claimed_this_period-a}},{title:i().translate("showcases.direct_debit.expires"),dataIndex:"expires",key:"expires",sorter:(e,t)=>e.expires>t.expires?1:e.expires<t.expires?-1:0},{title:"Actions",dataIndex:"action",key:"action",render:(e,t)=>t.type?"payer"===t.type?s.createElement("span",null,s.createElement(o.Button,{style:{marginRight:"10px"},onClick:()=>this.handleDeleteProposal(t.rawData)},i().translate("showcases.direct_debit.delete")),s.createElement(o.Button,{onClick:this.showModal({type:"update",payload:t.rawData})},i().translate("showcases.direct_debit.update"))):s.createElement("span",{onClick:this.showClaimModal({type:"claim",payload:t.rawData})},s.createElement(o.Button,null,i().translate("showcases.direct_debit.claim"))):null}];return s.createElement("div",{className:"direct-debit-view"},s.createElement(o.Card,{className:"direct-debit-table-card"},s.createElement(o.Row,null,s.createElement(o.Col,{span:24,style:{padding:"10px"}},s.createElement("div",{style:{marginBottom:"30px"}},s.createElement(o.Input,{className:"direct-debit-table__filter-input",placeholder:i().translate("explorer.witnesses.filter_by_name"),onChange:this._onFilter,style:{width:"200px",marginRight:"30px"},addonAfter:s.createElement(o.Icon,{type:"search"})}),s.createElement(o.Button,{onClick:this.showModal({type:"create",payload:null}),style:{marginRight:"30px"}},i().translate("showcases.direct_debit.create_new_mandate")),!!this.state.errorMessage&&s.createElement("span",{className:"red"},this.state.errorMessage)),s.createElement(o.Table,{columns:p,dataSource:h,pagination:!1,className:"direct-debit-table"}))),e?s.createElement(O,{isModalVisible:e,hideModal:this.hideModal,operation:n}):null,t?s.createElement(L,{isModalVisible:t,hideModal:this.hideClaimModal,operation:r}):null))}}const K=U=(0,H.V)(U)},43854:(e,t,a)=>{a.r(t),a.d(t,{default:()=>H});var s=a(96540),n=a(46128),o=a(10658),r=a.n(o),i=a(72090),l=a(87040),c=a(65924),d=a(80849),m=a.n(d),h=a(50548),p=a(32485),u=a.n(p),_=a(1951),g=a(55840),b=a(18483),f=a(24609),w=a(15483),y=a(89247),E=a(21561),A=a(9476),v=a(74248),C=a(95093),S=a.n(C),k=a(49074),x=(a(62716),a(2999)),N=a(46863),M=a(48287).Buffer;const T=(e,t)=>{let a=null;switch(e){case"sha256":a=i.hash.sha256(t);break;case"ripemd160":a=i.hash.ripemd160(t);break;case"sha1":throw new Error("sha1 is not considered a secure hashing algorithm, plaase use sha256");default:throw new Error("Wrong cipher name provided when creating htlc op")}return a},I=k.A.createActions(class{create({from_account_id:e,to_account_id:t,asset_id:a,amount:s,lock_time:n,preimage_cipher:o,preimage:r=null,preimage_hash:i=null,preimage_size:l=null,fee_asset:c=null}){c||(c="1.3.0"),"string"!=typeof c&&(c=c.get("id"));const d=x.A.new_transaction();let m=(e=>{let t=null;switch(e){case"sha256":t=2;break;case"ripemd160":t=0;break;case"sha1":throw new Error("sha1 is not considered a secure hashing algorithm, plaase use sha256");default:throw new Error("Wrong cipher name provided when creating htlc op")}return t})(o);if(r&&!i&&(i=T(o,r)),!l){if(!r)throw Error("Preimage must be given if size is empty");l=r.length}return d.add_type_operation("htlc_create",{from:e,to:t,fee:{amount:0,asset_id:c},amount:{amount:s,asset_id:a},preimage_hash:[m,i],preimage_size:l,claim_period_seconds:n}),e=>N.A.process_transaction(d,null,!0).then((()=>{e(!0)})).catch((t=>{console.log("[HtlcActions.js:69] ----- htlc create error -----\x3e",t),e(!1)}))}redeem({htlc_id:e,user_id:t,preimage:a}){let s=x.A.new_transaction();return s.add_type_operation("htlc_redeem",{preimage:new M(a).toString("hex"),fee:{amount:0,asset_id:"1.3.0"},htlc_id:e,redeemer:t}),e=>N.A.process_transaction(s,null,!0).then((()=>{e(!0)})).catch((t=>{console.log("[HtlcActions.js:98] ----- htlc redeem error -----\x3e",t),e(!1)}))}extend({htlc_id:e,user_id:t,seconds_to_add:a}){let s=x.A.new_transaction();return s.add_type_operation("htlc_extend",{fee:{amount:0,asset_id:"1.3.0"},htlc_id:e,update_issuer:t,seconds_to_add:a}),e=>N.A.process_transaction(s,null,!0).then((()=>{e(!0)})).catch((t=>{console.log("[HtlcActions.js:127] ----- htlc extend error -----\x3e",t),e(!1)}))}calculateHash(e,t){const a=T(t,e),s=a.length;return{hash:new M(a).toString("hex"),size:s}}});var B=a(12569),D=a(5556),O=a.n(D),F=a(37556),R=a(84181);const P=()=>new f.Vd({amount:0,asset_id:"1.3.0"});class V extends s.Component{static propTypes={preimage_hash:O().string,preimage_size:O().number,preimage:O().string,preimage_cipher:O().string};constructor(e){super(e),this.state=this.getInitialState(),this.hasRandomHash=!1}getInitialState(){return{stage:1,preimage_hash_calculated:null,ciphers:["sha256","ripemd160"]}}componentDidMount(){this.props.preimage_hash||this.hasRandomHash||this.generateRandom({target:{}})}componentDidUpdate(e,t){e.preimage_hash===this.props.preimage_hash||this.props.preimage_hash||(this.hasRandomHash=!1),this.props.preimage_hash||this.hasRandomHash||this.generateRandom({target:{}})}onClick(e){let t=!1;this.state.stage!==e.target.value&&1==e.target.value&&(t=!0),this.setState({stage:e.target.value},(()=>t?this.generateRandom():null))}onSizeChanged(e){this.props.onAction({preimage_size:e.target.value?parseInt(e.target.value):null})}onHashChanged(e){this.props.onAction({preimage_hash:e.target.value})}onInputChanged(e){let{preimage:t,preimage_cipher:a}=this.props;if(a||(a="sha256"),e.target?(t=e.target.value,this.hashingInProgress=!1):a=e,2==this.state.stage)this.props.onAction({preimage_cipher:a});else{const{hash:e}=I.calculateHash(t,a);"create"!==this.props.type?(this.props.onAction({preimage:t,preimage_cipher:a,preimage_size:t.length}),this.setState({preimage_hash_calculated:e})):this.props.onAction({preimage:t,preimage_cipher:a,preimage_hash:e,preimage_size:t.length})}}generateRandom(e={target:{}}){this.hasRandomHash=!0,e.target.value=i.key.get_random_key().toWif().substr(10,30),this.onInputChanged(e)}render(){let e=s.createElement(s.Fragment,null,r().translate(this.props.label),"create"==this.props.type&&s.createElement(n.Radio.Group,{value:this.state.stage,onChange:this.onClick.bind(this),style:{marginBottom:"7px",marginLeft:"24px"}},s.createElement(n.Radio,{value:1},s.createElement(m(),{content:"showcases.htlc.first_stage"})),s.createElement(n.Radio,{value:2},s.createElement(m(),{content:"showcases.htlc.second_stage"})),s.createElement(n.Radio,{value:3},s.createElement(m(),{content:"showcases.htlc.custom"})))),t="create"!==this.props.type&&null!==this.state.preimage_hash_calculated?this.state.preimage_hash_calculated==this.props.preimage_hash:null;return s.createElement(n.Form.Item,{label:e},s.createElement("span",null,r().translate("showcases.htlc.preimage_has_been_created")),s.createElement(n.Input.Group,{className:"content-block transfer-input preimage-row"},s.createElement(n.Tooltip,{title:r().translate("create"!==this.props.type?"showcases.htlc.tooltip.enter_preimage":"showcases.htlc.tooltip.preimage_random"),mouseEnterDelay:.5},s.createElement(n.Input,{style:{width:"60%",color:null==t?void 0:t?"green":"red"},name:"preimage",id:"preimage",type:"text",onChange:this.onInputChanged.bind(this),value:2==this.state.stage?"":this.props.preimage,placeholder:r().translate(this.props.hash?"showcases.htlc.enter_secret_preimage":"showcases.htlc.preimage"),disabled:"create"===this.props.type&&(1==this.state.stage||2==this.state.stage)})),s.createElement(n.Select,{optionLabelProp:"value",style:{width:"19.5%"},onChange:this.onInputChanged.bind(this),value:this.props.preimage_cipher},this.state.ciphers.map((e=>s.createElement(n.Select.Option,{key:e,value:e},e)))),s.createElement(n.Tooltip,{title:r().translate("showcases.htlc.tooltip.new_random"),mouseEnterDelay:.5},s.createElement(n.Button,{type:"primary",icon:"deployment-unit",style:{verticalAlign:"top"},onClick:this.generateRandom.bind(this)})),s.createElement("div",{style:{float:"right"}},s.createElement(E.A,{dataPlace:"top",text:"preimage: "+this.props.preimage+" hash type: "+this.props.preimage_cipher}))),s.createElement(n.Input.Group,{className:"content-block transfer-input preimage-row"},s.createElement(n.Tooltip,{title:r().translate("showcases.htlc.tooltip.preimage_hash"),mouseEnterDelay:.5},s.createElement(n.Input,{style:{width:"78%"},name:"hash",id:"hash",type:"text",onChange:this.onHashChanged.bind(this),value:this.props.preimage_hash||"",placeholder:r().translate("showcases.htlc.hash"),disabled:1==this.state.stage})),s.createElement(n.Tooltip,{title:r().translate("showcases.htlc.tooltip.preimage_size"),mouseEnterDelay:.5},s.createElement(n.Input,{style:{width:"53px",marginRight:"0.2rem"},name:"size",id:"size",type:"text",onChange:this.onSizeChanged.bind(this),value:this.props.preimage_size||"",placeholder:r().translate("showcases.htlc.size"),disabled:1==this.state.stage})),s.createElement("div",{style:{float:"right"}},s.createElement(E.A,{dataPlace:"top",text:"hash: "+this.props.preimage_hash+" preimage size: "+this.props.preimage_size}))))}}class j extends s.Component{static propTypes={isModalVisible:O().bool.isRequired,hideModal:O().func.isRequired,fromAccount:B.A.ChainObject.isRequired,operation:O().object};constructor(e){super(e),this.state=this.getInitialState(e),this.onTrxIncluded=this.onTrxIncluded.bind(this),this._checkBalance=this._checkBalance.bind(this)}getInitialState(){const e=S()().add("seconds",120);return{from_name:"",to_name:"",from_account:null,to_account:null,amount:"",asset_id:null,asset:null,error:null,feeAmount:P(),maxAmount:!1,num_of_periods:"",period_start_time:e,htlcId:"",balanceError:!1,preimage:null,preimage_cipher:null,preimage_hash:null,preimage_size:null,claim_period:86400,period:"one_day",expirationDate:S()().add("seconds",180).add(1,"day")}}onSubmit=e=>{e.preventDefault();let{from_account:t,to_account:a,amount:s,asset:n,asset_id:o,preimage:r,preimage_size:i,preimage_hash:c,preimage_cipher:d,claim_period:m,feeAmount:h}=this.state;const{operation:{type:p}}=this.props;"create"===p?I.create({from_account_id:t.get("id"),to_account_id:a.get("id"),asset_id:o,amount:l.A.convert_typed_to_satoshi(s,n),lock_time:m,preimage:r,preimage_size:i,preimage_hash:c,preimage_cipher:d,fee_asset:h.asset_id}).then((e=>{this.props.hideModal()})).catch((e=>{console.error(e)})):"redeem"===p?I.redeem({htlc_id:this.props.operation.payload.id,user_id:a.get("id"),preimage:r}).then((e=>{this.props.hideModal()})).catch((e=>{console.error(e)})):"extend"===p&&I.extend({htlc_id:this.props.operation.payload.id,user_id:t.get("id"),seconds_to_add:m}).then((e=>{this.props.hideModal()})).catch((e=>{console.error(e)})),this.props.hideModal()};shouldComponentUpdate(e,t,a){return!(e.fromAccount&&!(0,F.K)(e.fromAccount))}_syncOperation(e){if(e&&e.payload&&"create"!==e.type){const t=e.payload.transfer.to,a=e.payload.transfer.from,s={amount:e.payload.transfer.amount,asset_id:e.payload.transfer.asset_id},n=new Date(e.payload.conditions.time_lock.expiration),o=i.ChainStore.getAccount(t),r=i.ChainStore.getAccount(a);if(o&&r&&o.get&&r.get){const t=i.ChainStore.getAsset(s.asset_id,!1);this.setState({to_account:o,to_name:o.get("name"),from_account:r,from_name:r.get("name"),asset:t,amount:l.A.convert_satoshi_to_typed(s.amount,t),asset_id:s.asset_id,period_start_time:n,htlcId:e.payload.id,preimage_hash:e.payload.conditions.hash_lock.preimage_hash[1],preimage_size:e.payload.conditions.hash_lock.preimage_hash[0],expirationDate:S()(new Date(l.A.makeISODateString(e.payload.conditions.time_lock.expiration))),period:null})}else this.setState({htlcId:e.payload.id,preimage_hash:e.payload.conditions.hash_lock.preimage_hash[1],preimage_size:e.payload.conditions.hash_lock.preimage_hash[0],expirationDate:S()(new Date(l.A.makeISODateString(e.payload.conditions.time_lock.expiration))),period:null})}else this.setState({htlcId:null,preimage_hash:null,preimage_size:null})}componentDidMount(){this._syncOperation(this.props.operation)}componentDidUpdate(e,t){const{operation:a}=this.props;this.props.fromAccount===e.fromAccount&&null!=this.state.from_account||this.setState({from_account:this.props.fromAccount,from_name:this.props.fromAccount.get("name")}),e.operation!==this.props.operation&&this._syncOperation(a)}_checkBalance(){const{feeAmount:e,amount:t,from_account:a,asset:s}=this.state;if(!s||!a)return;const n=a.getIn(["balances",s.get("id")]),o=a.getIn(["balances",e.asset_id]);if(!s||!a)return;if(!n)return this.setState({balanceError:!0});let r=i.ChainStore.getObject(n),l=o?i.ChainStore.getObject(o):null;if(l&&0!==l.get("balance")||this.setState({feeAmount:P()}),!r||!e)return;if(!t)return this.setState({balanceError:!1});const c=(0,w.rT)(t,s,e,r);null!==c&&this.setState({balanceError:!c})}_setTotal(e,t){const{feeAmount:a}=this.state;let s=i.ChainStore.getObject(t),n=i.ChainStore.getObject(e),o=new f.Vd({amount:s.get("balance"),asset_id:n.get("id"),precision:n.get("precision")});s&&(a.asset_id===o.asset_id&&o.minus(a),this.setState({maxAmount:!0,amount:o.getAmount({real:!0})},this._checkBalance))}_getAvailableAssets(e=this.state){const{from_account:t,from_error:a}=e;let s=[];if(!t||!t.get("balances")||a)return{asset_types:s};let n=e.from_account.get("balances").toJS();s=Object.keys(n).sort(l.A.sortID);for(let e in n){let t=i.ChainStore.getObject(n[e]);t&&0===t.get("balance")&&s.splice(s.indexOf(e),1)}return{asset_types:s}}onToAccountChanged=e=>{this.setState({to_account:e,error:null})};onAmountChanged=({amount:e,asset:t})=>{t&&("object"!=typeof t&&(t=i.ChainStore.getAsset(t)),this.setState({amount:e,asset:t,asset_id:t.get("id"),error:null,maxAmount:!1},this._checkBalance))};toChanged=e=>{this.setState({to_name:e,error:null})};onFeeChanged(e){e&&this.setState({feeAmount:e,error:null},this._checkBalance)}onTrxIncluded(e){(e.included&&e.broadcasted_transaction||e.closed)&&(b.A.unlisten(this.onTrxIncluded),b.A.reset())}onDatepickerRef(e){e&&e.picker.input&&(e.picker.input.readOnly=!1)}onExpirationDateChanged=e=>{if(e){const{period_start_time:t}=this.state,a=e.valueOf(),s=t.valueOf(),n=Math.floor((a-s)/1e3);this.setState({claim_period:n,period:null,expirationDate:e})}else this.setState({claim_period:0,period:null,expirationDate:null})};onPreimageChanged({preimage:e,preimage_cipher:t,preimage_hash:a,preimage_size:s}){let n={};void 0!==e&&(n.preimage=e),void 0!==t&&(n.preimage_cipher=t),void 0!==a&&(n.preimage_hash=a),void 0!==s&&(n.preimage_size=s),this.setState(n)}setPeriod=e=>{let t=S()().add(e,"day"),a="one_day";const s=60*e*60*24;switch(e){case 1:a="one_day";break;case 2:a="two_days";break;case 7:a="one_week"}this.setState({claim_period:s,period:a,expirationDate:t})};render(){let{from_account:e,to_account:t,asset:a,asset_id:o,feeAmount:l,amount:d,from_name:p,to_name:b,balanceError:f,preimage:w,preimage_cipher:E,claim_period:A,preimage_hash:v,preimage_size:C,period_start_time:S,expirationDate:k}=this.state,x=g.A.isMyAccount(e)||p===this.props.passwordAccount,N=!(!e||x);const{operation:M}=this.props,T=M&&"extend"===M.type,I=M&&"redeem"===M.type;let{asset_types:B}=this._getAvailableAssets(),D=null;if(e&&e.get("balances")&&!N){let t=e.get("balances").toJS(),n=this.state.balanceError?"has-error":"";if(1===B.length&&(a=i.ChainStore.getAsset(B[0])),B.length>0){let e=a?a.get("id"):B[0];D=s.createElement("span",null,s.createElement(m(),{component:"span",content:"transfer.available"}),":"," ",s.createElement("span",{className:n,style:{borderBottom:"#A09F9F 1px dotted",cursor:"pointer"},onClick:this._setTotal.bind(this,e,t[e],l.getAmount({real:!0}),l.asset_id)},s.createElement(y.A,{balance:t[e]})))}else D=s.createElement("span",null,s.createElement("span",{className:n},s.createElement(m(),{content:"transfer.errors.noFunds"})))}const O=parseFloat(String.prototype.replace.call(d,/,/g,"")),F=O&&!(0,c.A)(O),P=!e||!t||!F||!a||f||e.get("id")==t.get("id")||!(E&&w||v)||!A;let j=M&&"create"===M.type?r().translate("showcases.htlc.create_htlc"):T?r().translate("showcases.htlc.extend_htlc"):r().translate("showcases.htlc.redeem_htlc"),z=M&&"create"===M.type?r().translate("showcases.direct_debit.create"):r().translate("showcases.direct_debit.update");const L=s.createElement("div",{className:"form-input-header--label"},r().translate("showcases.htlc.expiration_date"),s.createElement("div",{className:"form-input-header--right"},s.createElement("span",{className:u()("period-row",{"is-active":"one_day"===this.state.period}),onClick:()=>this.setPeriod(1)},r().translate("showcases.htlc.expiration_period.one_day")),s.createElement("span",{className:u()("period-row",{"is-active":"two_days"===this.state.period}),onClick:()=>this.setPeriod(2)},r().translate("showcases.htlc.expiration_period.two_days")),s.createElement("span",{className:u()("period-row",{"is-active":"one_week"===this.state.period}),onClick:()=>this.setPeriod(7)},r().translate("showcases.htlc.expiration_period.one_week"))));return s.createElement(n.Modal,{title:j,visible:this.props.isModalVisible,overlay:!0,onCancel:this.props.hideModal,footer:[s.createElement(n.Button,{key:"send",disabled:P,onClick:P?null:this.onSubmit.bind(this)},z),s.createElement(n.Button,{key:"Cancel",onClick:this.props.hideModal},s.createElement(m(),{component:"span",content:"transfer.cancel"}))]},s.createElement("div",{className:"grid-block vertical no-overflow"},s.createElement(n.Form,{className:"full-width",layout:"vertical"},s.createElement(_.A,{label:"showcases.htlc.sender",accountName:p,account:e,size:60,typeahead:!0,hideImage:!0,disabled:!0}),s.createElement(_.A,{label:"showcases.htlc.recipient",accountName:b,account:t,onChange:this.toChanged.bind(this),onAccountChanged:this.onToAccountChanged,size:60,typeahead:!0,hideImage:!0,disabled:T||I}),I?null:s.createElement(h.A,{label:"showcases.htlc.amount",amount:d,onChange:this.onAmountChanged.bind(this),asset:B.length>0&&a?a.get("id"):o||B[0],assets:B,display_balance:T||I?void 0:D,allowNaN:!0,disabled:T||I,selectDisabled:T||I}),T?s.createElement(n.Form.Item,{label:r().translate("showcases.htlc.preimage")},s.createElement(n.Input,{type:"text",value:v||"",placeholder:r().translate("showcases.htlc.hash"),readOnly:!0,disabled:!0})):s.createElement(V,{ref:e=>this.preimage=e,label:"showcases.htlc.preimage",onAction:this.onPreimageChanged.bind(this),preimage_hash:v,preimage_size:C,preimage:w,preimage_cipher:E,type:M&&M.type?M.type:"create"}),I?null:s.createElement("div",null,s.createElement(n.Form.Item,{label:L,validateStatus:"",className:"form-input-header"},s.createElement(n.DatePicker,{showToday:!0,showTime:!0,placeholder:"",onChange:this.onExpirationDateChanged,className:"date-picker-width100",style:{width:"100%"},ref:e=>this.onDatepickerRef(e),disabledDate:e=>e&&e<S,value:k})),s.createElement("div",{className:"content-block transfer-input"},s.createElement("div",{className:"no-margin no-padding"},s.createElement(R.A,{account:e,transaction:{type:"htlc_create",options:["price_per_kbyte"],data:{type:"memo",content:null}},onChange:this.onFeeChanged.bind(this)})))))))}}const z=(0,A.N)(j,{listenTo:()=>[v.A],getProps:e=>({fee_asset_symbol:v.A.getState().settings.get("fee_asset")})});var L=a(24873);class W extends s.Component{constructor(e){super(e),this.state={isModalVisible:!1,filterString:"",operationData:void 0,htlc_list:[],tableIsLoading:!1},this.hasLoadedOnce=null}shouldComponentUpdate(e,t){return this.props.currentAccount!==e.currentAccount||JSON.stringify(this.state.htlc_list)!==JSON.stringify(t.htlc_list)||this.state.isModalVisible!==t.isModalVisible||this.state.tableIsLoading!==t.tableIsLoading||this.state.filterString!==t.filterString}async _update(){let e=this.props.currentAccount;e.get("id"),this.hasLoadedOnce=e.get("id"),this.setState({tableIsLoading:!0});const t=this.props.currentAccount.get("htlcs_from").toJS()||[],a=this.props.currentAccount.get("htlcs_to").toJS()||[];this.setState({htlc_list:t.concat(a).map((e=>i.ChainStore.getObject(e))).map((e=>e.toJS?e.toJS():void 0)),tableIsLoading:!1})}componentDidMount(){this._update()}componentDidUpdate(e){this._update()}showModal=e=>async()=>{e.payload&&(await(0,i.FetchChainObjects)(i.ChainStore.getAccount,[e.payload.transfer.to],void 0,{}),await(0,i.FetchChainObjects)(i.ChainStore.getAccount,[e.payload.transfer.from],void 0,{}),await(0,i.FetchChainObjects)(i.ChainStore.getAsset,[e.payload.transfer.asset_id])),this.setState({isModalVisible:!0,operationData:e})};hideModal=()=>{this.setState({isModalVisible:!1,operation:null})};_onFilter=e=>{e.preventDefault(),this.setState({filterString:e.target.value.toLowerCase()})};render(){const{isModalVisible:e,htlc_list:t,operationData:a,filterString:o}=this.state;let c=this.props.currentAccount,d=null;t.length&&(d=t.map((e=>{const t=e.transfer.to,a=e.transfer.from,o={amount:e.transfer.amount,asset_id:e.transfer.asset_id},d=e.conditions.time_lock.expiration,m=i.ChainStore.getAsset(o.asset_id,!1),h=i.ChainStore.getAccountName(t)||t,p=i.ChainStore.getAccountName(a)||a;return{key:e.id,id:e.id,type:t==c.get("id")?"payee":"payer",from:p,to:h,amount:s.createElement("span",null,m?l.A.get_asset_amount(o.amount,m)+" ":null,s.createElement(L.A,{asset:o.asset_id})),hash:s.createElement(n.Tooltip,{title:r().translate("htlc.preimage_hash_explanation")},s.createElement("span",null,"("+e.conditions.hash_lock.preimage_size+","+e.conditions.hash_lock.preimage_hash[0]+"): "+e.conditions.hash_lock.preimage_hash[1])),expires:d,rawData:{...e}}})),d.length&&d.filter((e=>e.to&&-1!==e.to.indexOf(o))));const m=[{title:"#",dataIndex:"id",key:"id",sorter:(e,t)=>e.id>t.id?1:e.id<t.id?-1:0},{title:r().translate("showcases.htlc.from"),dataIndex:"from",key:"from",sorter:(e,t)=>e.from>t.from?1:e.from<t.from?-1:0},{title:r().translate("showcases.htlc.to"),dataIndex:"to",key:"to",sorter:(e,t)=>e.to>t.to?1:e.to<t.to?-1:0},{title:r().translate("showcases.htlc.amount"),dataIndex:"amount",key:"amount",sorter:(e,t)=>e.rawData.op[1].amount.amount-t.rawData.op[1].amount.amount},{title:r().translate("showcases.htlc.hash"),dataIndex:"hash",key:"hash"},{title:r().translate("showcases.htlc.expires"),dataIndex:"expires",key:"expires",sorter:(e,t)=>e.expires>t.expires?1:e.expires<t.expires?-1:0,render:(e,t)=>r().localize(new Date(l.A.makeISODateString(e)),{type:"date",format:"full"})},{title:r().translate("showcases.htlc.actions"),dataIndex:"action",key:"action",render:(e,t)=>t.type?"payer"===t.type?s.createElement("span",null,s.createElement(n.Button,{style:{marginRight:"10px"},onClick:this.showModal({type:"extend",payload:t.rawData})},r().translate("showcases.htlc.extend"))):s.createElement("span",{onClick:this.showModal({type:"redeem",payload:t.rawData})},s.createElement(n.Button,null,r().translate("showcases.htlc.redeem"))):null}];return s.createElement("div",{className:"direct-debit-view"},s.createElement(n.Card,{className:"direct-debit-table-card"},s.createElement(n.Row,null,s.createElement(n.Col,{span:24,style:{padding:"10px"}},s.createElement("div",{style:{marginBottom:"30px"}},s.createElement(n.Input,{className:"direct-debit-table__filter-input",placeholder:r().translate("explorer.witnesses.filter_by_name"),onChange:this._onFilter,style:{width:"200px",marginRight:"30px"},addonAfter:s.createElement(n.Icon,{type:"search"})}),s.createElement(n.Button,{onClick:this.showModal({type:"create",payload:null}),style:{marginRight:"30px"}},r().translate("showcases.htlc.create_htlc")),!!this.state.errorMessage&&s.createElement("span",{className:"red"},this.state.errorMessage)),s.createElement(n.Table,{columns:m,dataSource:d,pagination:!1,className:"direct-debit-table",loading:this.state.tableIsLoading}))),e?s.createElement(z,{isModalVisible:e,hideModal:this.hideModal,operation:a,fromAccount:this.props.currentAccount}):null))}}const H=W=(0,F.V)(W)},49585:(e,t,a)=>{a.d(t,{A:()=>w});var s=a(96540),n=a(80849),o=a.n(n),r=a(96366),i=a(62611),l=a(9404),c=a.n(l),d=a(10658),m=a.n(d),h=a(60819),p=a(87040),u=a(5556),_=a.n(u),g=a(6356);class b extends s.Component{static propTypes={value:_().string,onChange:_().func,scroll_length:_().number};shouldComponentUpdate(e){return!p.A.are_equal_shallow(e.assets,this.props.assets)||e.value!==this.props.value||e.scroll_length!==this.props.scroll_length}render(){return this.props.assets.length?s.createElement(i.A,{entries:this.props.assets.map((e=>e&&e.get("symbol"))).filter((e=>!!e)),values:this.props.assets.reduce(((e,t)=>(t&&t.get("symbol")&&(e[t.get("symbol")]=t),e)),{}),singleEntry:this.props.assets[0]?s.createElement(r.A,{asset:this.props.assets[0].get("id"),amount:0,hide_amount:!0}):null,value:this.props.value,onChange:this.props.onChange,scroll_length:this.props.scroll_length}):null}}b=(0,h.A)(b,{asList:!0});class f extends g.x{static propTypes={label:_().string,assets:_().array,amount:_().any,placeholder:_().string,onChange:_().func,tabIndex:_().number,error:_().string,scroll_length:_().number};static defaultProps={disabled:!1,tabIndex:0};componentDidMount(){this.onAssetChange(this.props.asset)}formatAmount(e){return e||(e=""),"number"==typeof e&&(e=e.toString()),e.trim().replace(/,/g,"")}_onChange(e){this.props.onChange&&this.props.onChange({amount:this.getNumericEventValue(e),asset:this.props.asset})}onAssetChange(e){this.props.onChange&&this.props.onChange({amount:this.props.amount,asset:e})}render(){let e=this.props.error?m().translate(this.props.error):this.formatAmount(this.props.amount);return s.createElement("div",{className:"amount-selector",style:this.props.style},s.createElement("label",{className:"right-label"},this.props.display_balance),s.createElement(o(),{className:"left-label",component:"label",content:this.props.label}),s.createElement("div",{className:"inline-label input-wrapper"},s.createElement("input",{disabled:this.props.disabled,type:"text",value:e||"",placeholder:this.props.placeholder,onChange:this._onChange.bind(this),tabIndex:this.props.tabIndex,onPaste:this.props.onPaste||this.onPaste.bind(this),onKeyPress:this.onKeyPress.bind(this)}),s.createElement("div",{className:"form-label select floating-dropdown"},this.props.isPrice?s.createElement("div",{className:"dropdown-wrapper inactive"},s.createElement("div",null,this.props.asset.get("symbol"),"/",this.props.base)):s.createElement(b,{ref:this.props.refCallback,value:this.props.asset.get("symbol"),assets:c().List(this.props.assets),onChange:this.onAssetChange.bind(this),scroll_length:this.props.scroll_length}))))}}const w=f=(0,h.A)(f)},37556:(e,t,a)=>{a.d(t,{K:()=>d,V:()=>m});var s=a(96540),n=a(12569),o=a(83599),r=a(72342),i=a(9476),l=a(55840),c=a(40702);const d=function(e){return!!e&&!!e.get("id")},m=function(e){let t=class extends s.Component{static propTypes={currentAccount:n.A.ChainAccount};static defaultProps={autosubscribe:!0};constructor(e){super(e)}render(){return d(this.props.currentAccount)?s.createElement(e,this.props):s.createElement(c.A,null)}};return t=(0,r.A)(t),t=(0,o.Ay)(t,100,{leading:!1}),(0,i.N)(t,{listenTo:()=>[l.A],getProps(){let e=l.A.getState().currentAccount||l.A.getState().passwordAccount||"please-login";return{currentAccount:new Map([["name",e]])}}})}}}]);