-
Notifications
You must be signed in to change notification settings - Fork 13
/
927.9afc34a13712744457df.js
1 lines (1 loc) · 19.2 KB
/
927.9afc34a13712744457df.js
1
"use strict";(this.webpackChunkBitShares2_light=this.webpackChunkBitShares2_light||[]).push([[927],{35277:(t,e,a)=>{a.d(e,{A:()=>P});var s=a(96540),l=a(5556),o=a.n(l),i=a(54392),n=a.n(i),r=a(12569),c=a(39744),p=a(72342),h=a(87040),d=a(2999),b=a(46863),_=a(10658),u=a.n(_),g=a(9404),m=a.n(g),C=a(46128),A=a(64143),k=a(80849),O=a.n(k),w=a(96366),j=a(50548),E=a(32853),v=a(81428);function S({accountObj:t,backingAssetObj:e,collateralBalanceObj:a,debtBalanceObj:l,quoteAssetObj:o,newPosition:i,errors:n,collateral:r,collateral_ratio:c,debtAmount:p,backingPrecision:d,maintenanceRatio:b,remainingBackingBalance:_,remainingDebtBalance:g,target_collateral_ratio:m,unlockedInputType:k,disableHelp:S,isRatioLocked:y,isOriginalBelowMCR:R,isPredictionMarket:P,isValid:I,useTargetCollateral:B,onPayDebt:x,onMaximizeCollatereal:F,onBorrowChange:f,onLockChangeDebt:L,onCollateralChange:q,onLockChangeCollateral:M,onRatioChange:T,onLockChangeCR:N,onSetUseTCR:U,onTCRatioChange:D}){let z=h.A.get_asset_precision(o.get("precision"));const J=i?s.createElement(E.A,{noPopOver:!0,noTip:!0,quote_amount:b*p*z,quote_asset:o.get("id"),base_asset:e.get("id"),base_amount:r*d}):null,H=s.createElement("div",{style:{textAlign:"center"}},s.createElement(O(),{component:"h3",content:"borrow.no_valid",asset_symbol:o.get("symbol")})),W=s.createElement("span",null,s.createElement("span",null,0!=r?s.createElement("span",null,s.createElement(O(),{component:"a",onClick:x.bind(this),content:"borrow.pay_max_debt"})," "):null,s.createElement(O(),{component:"span",content:"transfer.available"}),":"," ",s.createElement("span",null,l.id?s.createElement(w.A,{amount:g,asset:o.get("id")}):s.createElement(w.A,{amount:0,asset:o.get("id")})))),V=s.createElement("span",null,s.createElement("span",null,s.createElement("span",null,s.createElement(O(),{component:"a",onClick:F.bind(this),content:"borrow.use_max"})," "),s.createElement(O(),{component:"span",content:"transfer.available"}),":"," ",s.createElement("span",null,a.id?s.createElement(w.A,{amount:_,asset:e.get("id")}):s.createElement(w.A,{amount:0,asset:e.get("id")}))));return I?s.createElement("div",{style:{textAlign:"left"}},S?null:s.createElement("div",{style:{paddingBottom:"1rem"}},s.createElement(v.A,{path:"components/"+(P?"BorrowModalPrediction":"BorrowModal"),debt:o.get("symbol"),collateral:e.get("symbol"),borrower:t.get("name"),mr:b})),!P&&R?s.createElement(O(),{component:"h6",className:"has-warning",content:"borrow.errors.below_info"}):null,P?null:s.createElement("div",{style:{paddingTop:"1rem",paddingBottom:"1rem"}},s.createElement("div",{className:"borrow-price-feeds"},s.createElement("span",{className:"borrow-price-label"},s.createElement(O(),{content:"transaction.feed_price"}),": "),s.createElement(E.A,{noPopOver:!0,quote_amount:A.A.extractRawFeedPrice(o).getIn(["base","amount"]),quote_asset:A.A.extractRawFeedPrice(o).getIn(["base","asset_id"]),base_asset:A.A.extractRawFeedPrice(o).getIn(["quote","asset_id"]),base_amount:A.A.extractRawFeedPrice(o).getIn(["quote","amount"])})),s.createElement("b",null),s.createElement("div",{className:"borrow-price-final "+(n.below_maintenance?"has-error":n.close_maintenance?"has-warning":"")},s.createElement("span",{className:"borrow-price-label"},s.createElement(O(),{content:"exchange.your_price"}),": "),J)),s.createElement(C.Form,{className:"full-width",layout:"vertical"},s.createElement(j.A,{label:"transaction.borrow_amount",amount:p.toString(),onChange:f.bind(this),asset:o.get("id"),assets:[o.get("id")],display_balance:W,placeholder:"0.0",tabIndex:1,lockStatus:"debt"!=k&&!y,onLockChange:L.bind(this)}),s.createElement(j.A,{label:"transaction.collateral",amount:r.toString(),onChange:q.bind(this),asset:e.get("id"),assets:[e.get("id")],display_balance:V,placeholder:"0.0",tabIndex:2,lockStatus:"collateral"!=k&&!y,onLockChange:M.bind(this),validateStatus:n.collateral_balance?"error":"",help:n.collateral_balance?n.collateral_balance:null}),P?null:s.createElement(s.Fragment,null,s.createElement(C.Row,{gutter:16},s.createElement(C.Col,{span:12},s.createElement(C.Form.Item,{label:u().translate("borrow.coll_ratio"),validateStatus:n.close_maintenance?"warning":n.below_maintenance?"error":null,help:n.close_maintenance?n.close_maintenance:n.below_maintenance?n.below_maintenance:null},s.createElement(C.Input,{value:0==c?"":c,tabIndex:3,onChange:T.bind(this),className:"input-group-unbordered-before",addonBefore:s.createElement(C.Icon,{className:y?"green":"grey",type:y?"lock":"unlock",onClick:N.bind(this),style:{fontSize:"20px"}})}))),s.createElement(C.Col,{span:12},s.createElement(C.Form.Item,{validateStatus:n.tcr_below_maintenance?"error":"",help:n.tcr_below_maintenance?n.tcr_below_maintenance:null},s.createElement(C.Input.Group,{compact:!0,style:{marginBottom:8}},s.createElement(C.Checkbox,{onClick:U.bind(this),checked:B,tabIndex:4},s.createElement(O(),{content:"borrow.enable_target_collateral_ratio"})),s.createElement(C.Tooltip,{title:u().translate("tooltip.target_collateral_ratio")},s.createElement(C.Icon,{type:"question-circle"}))),B?s.createElement(C.Input,{value:isNaN(m)?"0":m,tabIndex:5,onChange:D.bind(this)}):null))),s.createElement(C.Form.Item,{label:"Ratio Slider"},s.createElement(C.Slider,{step:.01,min:0,max:100*b,value:c,onChange:T.bind(this)}))))):H}var y=a(83599);class R extends s.Component{static propTypes={quoteAssetObj:r.A.ChainAsset.isRequired,backingAssetObj:r.A.ChainAsset.isRequired,debtBalanceObj:r.A.ChainObject,collateralBalanceObj:r.A.ChainObject,call_orders:r.A.ChainObjectsList,hasCallOrders:o().bool};constructor(t){super(t),this.state=this._initialState(t),this._onSubmit=this._onSubmit.bind(this)}_initialState(t){let e=t?this._getCurrentPosition(t):{};if(e.collateral){let a=h.A.get_asset_amount(e.debt,t.quoteAssetObj),s=h.A.get_asset_amount(e.collateral,t.backingAssetObj),l=isNaN(e.target_collateral_ratio)?0:e.target_collateral_ratio/1e3;return{debtAmount:a?a.toString():null,collateral:s?s.toString():null,collateral_ratio:this._getCollateralRatio(a,s),target_collateral_ratio:l,errors:this._getInitialErrors(),useTargetCollateral:l>0,original_position:{debt:a,collateral:s,target_collateral_ratio:l},unlockedInputType:"collateral",isRatioLocked:!0}}return{debtAmount:0,collateral:0,collateral_ratio:this._getInitialCollateralRatio(t),target_collateral_ratio:this._getMaintenanceRatio(),errors:this._getInitialErrors(),useTargetCollateral:!1,original_position:{debt:0,collateral:0},unlockedInputType:"debt",isRatioLocked:!0}}componentDidUpdate(){c.A.rebuild()}componentDidMount(){let t=this._initialState(this.props);this.setState(t),this._setUpdatedPosition(t)}shouldComponentUpdate(t,e){return!(this.props.visible===t.visible&&h.A.are_equal_shallow(e,this.state)&&m().is(t.quoteAssetObj,this.props.quoteAssetObj)&&!t.backingAssetObj.get("symbol")!==this.props.backingAssetObj.get("symbol")&&m().is(t.accountObj,this.props.accountObj)&&m().is(t.call_orders,this.props.call_orders)&&this.state.unlockedInputType===e.unlockedInputType)}UNSAFE_componentWillReceiveProps(t){const{debtAmount:e,collateral:a,collateral_ratio:s}=this.state;if(t.accountObj!==this.props.accountObj||t.hasCallOrders!==this.props.hasCallOrders||t.quoteAssetObj.get("id")!==this.props.quoteAssetObj.get("id")){let l=this._initialState(t),o=!1;(e||a||s)&&(l.debtAmount=e,l.collateral=a,l.collateral_ratio=s,o=!0),this.setState(l),o&&this._validateFields(l)}}_getInitialErrors(){return{collateral_balance:null,ratio_too_high:null}}_getMaintenanceRatio(){return this.props.quoteAssetObj.getIn(["bitasset","current_feed","maintenance_collateral_ratio"])/1e3}confirmClicked(t){t.preventDefault(),n().publish(this.props.modalId,"close")}_onBorrowChange(t){let e=this._getFeedPrice(),a=t.amount.replace(/,/g,""),s={debtAmount:a,collateral:this.state.isRatioLocked?(this.state.collateral_ratio*(a/e).toFixed(this.props.backingAssetObj.get("precision"))).toFixed(this.props.backingAssetObj.get("precision")):this.state.collateral,collateral_ratio:this.state.isRatioLocked?this.state.collateral_ratio:this.state.collateral/(a/e)};this.setState(s),this._validateFields(s),this._setUpdatedPosition(s)}_onCollateralChange(t){let{isRatioLocked:e,collateral_ratio:a}=this.state,s=t.amount.replace(/,/g,""),l=this._getFeedPrice();const o=e?a:s/(this.state.debtAmount/l),i=e?(s*l/o).toFixed(this.props.backingAssetObj.get("precision")):this.state.debtAmount;let n=this._isPredictionMarket(this.props)?{debtAmount:s,collateral:s,collateral_ratio:1}:{debtAmount:i,collateral:s,collateral_ratio:o};this.setState(n),this._validateFields(n),this._setUpdatedPosition(n)}_onTargetRatioChange(t){let e=t.target.value;new RegExp(/[[:digit:]]/).test(e)||(e=e.replace(/[^0-9.]/g,""));let a={target_collateral_ratio:e};this.setState(a),this._validateFields(a),this._setUpdatedPosition(a)}_onRatioChange(t){let e,a,s=this._getFeedPrice(),l=0;t.target?(new RegExp(/[[:digit:]]/).test(t.target.value)||(t.target.value=t.target.value.replace(/[^0-9.]/g,"")),l=t.target.value):l=t,"debt"==this.state.unlockedInputType?(e=(this.state.collateral*s/parseFloat(l)).toFixed(this.props.backingAssetObj.get("precision")),a=this.state.collateral):(e=this.state.debtAmount,a=(this.state.debtAmount/s*parseFloat(l)).toFixed(this.props.backingAssetObj.get("precision")));let o={debtAmount:e,collateral:a,collateral_ratio:l};this.setState(o),this._validateFields(o),this._setUpdatedPosition(o)}_maximizeCollateral(){let t=this.props?this._getCurrentPosition(this.props):{},e=0;t.collateral&&(e=h.A.convert_satoshi_to_typed(t.collateral,this.props.backingAssetObj));let a=h.A.convert_satoshi_to_typed(this.props.collateralBalanceObj.get("balance"),this.props.backingAssetObj),s=Math.max(Math.floor(a+e-10),0);this._onCollateralChange(new Object({amount:s.toString()}))}_maximizeDebt(){let t=this.props?this._getCurrentPosition(this.props):{},e=0;t.collateral&&(e=h.A.get_asset_amount(t.collateral,this.props.backingAssetObj));let a=this.props.collateralBalanceObj.get("balance")/h.A.get_asset_precision(this.props.backingAssetObj)+e-10;const s={debtAmount:a/this.state.collateral_ratio*this._getFeedPrice(),collateral:a,collateral_ratio:this.state.collateral_ratio};this.setState(s),this._validateFields(s),this._setUpdatedPosition(s)}_payDebt(){let t=this.props?this._getCurrentPosition(this.props):{debt:0};if(t.debt<=0)return;const e=h.A.get_asset_amount(Math.max(t.debt-this.props.debtBalanceObj.get("balance"),0),this.props.quoteAssetObj);this._onBorrowChange({amount:e.toString()})}_setUpdatedPosition(t){this.setState({newPosition:parseFloat(t.debtAmount)/parseFloat(t.collateral)})}_validateFields(t){let e=this._getInitialErrors(),{original_position:a}=this.state,s=this.props.collateralBalanceObj?this.props.collateralBalanceObj.toJS():{balance:0},l=this._getMaintenanceRatio(),o=this._getCollateralRatio(a.debt,a.collateral),i=a.collateral>0&&o<l;parseFloat(t.collateral)-a.collateral>h.A.get_asset_amount(s.balance,this.props.backingAssetObj.toJS())&&(e.collateral_balance=u().translate("borrow.errors.collateral")),t.target_collateral_ratio&&t.target_collateral_ratio<l&&(e.tcr_below_maintenance=u().translate("borrow.errors.below_mcr_tcr",{mr:l})),i&&t.debtAmount>a.debt?e.below_maintenance=u().translate("borrow.errors.increased_debt_on_margin_call"):i&&parseFloat(t.collateral_ratio)<=parseFloat(o)?e.below_maintenance=u().translate("borrow.errors.below_ratio_mcr_update",{ocr:o.toFixed(4)}):!i&&parseFloat(t.collateral_ratio)<(this._isPredictionMarket(this.props)?1:l)?e.below_maintenance=u().translate("borrow.errors.below",{mr:l}):parseFloat(t.collateral_ratio)<(this._isPredictionMarket(this.props)?1:l+.5)&&(e.close_maintenance=u().translate("borrow.errors.close",{mr:l})),this.setState({errors:e})}_onSubmit(t){t.preventDefault(),this.props.hideModal();let e=h.A.get_asset_precision(this.props.quoteAssetObj.get("precision")),a=h.A.get_asset_precision(this.props.backingAssetObj.get("precision")),s=this._getCurrentPosition(this.props),l=!1;void 0!==this.state.target_collateral_ratio&&this.state.target_collateral_ratio>0&&this.state.useTargetCollateral&&(l={target_collateral_ratio:parseInt(1e3*this.state.target_collateral_ratio,10)});let o=parseInt(this.state.collateral*a-s.collateral,10),i=parseInt(this.state.debtAmount*e-s.debt,10);0==o&&0==i&&(o=1);var r=d.A.new_transaction();l?r.add_type_operation("call_order_update",{fee:{amount:0,asset_id:0},funding_account:this.props.accountObj.get("id"),delta_collateral:{amount:o,asset_id:this.props.backingAssetObj.get("id")},delta_debt:{amount:i,asset_id:this.props.quoteAssetObj.get("id")},extensions:l}):r.add_type_operation("call_order_update",{fee:{amount:0,asset_id:0},funding_account:this.props.accountObj.get("id"),delta_collateral:{amount:o,asset_id:this.props.backingAssetObj.get("id")},delta_debt:{amount:i,asset_id:this.props.quoteAssetObj.get("id")}}),b.A.process_transaction(r,null,!0).catch((t=>{})),n().publish(this.props.modalId,"close")}_getCurrentPosition(t){let e={collateral:null,debt:null};return t&&t.hasCallOrders&&t.call_orders&&(e=t.call_orders.filter((t=>!!t)).find((e=>e.getIn(["call_price","quote","asset_id"])===t.quoteAssetObj.get("id"))),e=e?e.toJS():{collateral:null,debt:null}),e}_getFeedPrice(){return this.props?this._isPredictionMarket(this.props)?1:1/h.A.get_asset_price(A.A.extractRawFeedPrice(this.props.quoteAssetObj).getIn(["quote","amount"]),this.props.backingAssetObj,A.A.extractRawFeedPrice(this.props.quoteAssetObj).getIn(["base","amount"]),this.props.quoteAssetObj):1}_getInitialCollateralRatio(t){return this._isPredictionMarket(t)?1:2*this._getMaintenanceRatio()}_getCollateralRatio(t,e){return e/(t/this._getFeedPrice())}_isPredictionMarket(t){return t.quoteAssetObj.getIn(["bitasset","is_prediction_market"])}_setUseTargetCollateral(){this.setState({useTargetCollateral:!this.state.useTargetCollateral})}_onLockChange(t){this.setState({isRatioLocked:!1,unlockedInputType:t})}_onLockCR(){this.setState({isRatioLocked:!this.state.isRatioLocked})}render(){let{quoteAssetObj:t,backingAssetObj:e,debtBalanceObj:a,collateralBalanceObj:l}=this.props,{debtAmount:o,collateral:i,collateral_ratio:n,target_collateral_ratio:r,errors:c,original_position:p,useTargetCollateral:d}=this.state;n&&!isNaN(n)&&n>0&&n<1e3||(n=0),-1!=n.toString().indexOf(".")&&n.toString().split(".")[1].length>2&&(n=n.toString().split(".")[0]+"."+n.toString().split(".")[1].substr(0,2)),-1!=r.toString().indexOf(".")&&r.toString().split(".")[1].length>2&&(r=r.toString().split(".")[0]+"."+r.toString().split(".")[1].substr(0,2)),a=a?a.toJS():{balance:0,id:null},l=l?l.toJS():{balance:0,id:null};let b=h.A.get_asset_precision(this.props.backingAssetObj.get("precision")),_=h.A.get_asset_precision(this.props.quoteAssetObj.get("precision")),g=this._getCurrentPosition(this.props),m=parseInt(this.state.collateral*b-g.collateral,10),A=parseInt(this.state.debtAmount*_-g.debt,10),k=l.balance-m,O=a.balance+A,w=this._getFeedPrice(),j=this._getMaintenanceRatio(),E=this._isPredictionMarket(this.props),v=p.collateral>0&&this._getCollateralRatio(p.debt,p.collateral)<j;const y=[];return!E&&isNaN(w)?y.push(s.createElement(C.Button,{tabIndex:6,onClick:this.props.hideModal},u().translate("accountObj.perm.cancel"))):(y.push(s.createElement(C.Button,{tabIndex:6,key:"submit",type:"primary",onClick:this._onSubmit},u().translate("borrow.adjust"))),y.push(s.createElement(C.Button,{tabIndex:7,key:"cancel",onClick:()=>{this.setState(this._initialState(this.props))}},u().translate("wallet.reset")))),s.createElement(C.Modal,{title:u().translate("borrow.title",{asset_symbol:t.get("symbol")}),visible:this.props.visible,onCancel:this.props.hideModal,footer:y},s.createElement(S,{accountObj:this.props.accountObj,backingAssetObj:e,collateralBalanceObj:l,debtBalanceObj:a,quoteAssetObj:t,newPosition:this.state.newPosition||null,errors:c,collateral:i,collateral_ratio:n,debtAmount:o,backingPrecision:b,maintenanceRatio:j,remainingBackingBalance:k,remainingDebtBalance:O,target_collateral_ratio:r,unlockedInputType:this.state.unlockedInputType,disableHelp:this.props.disableHelp,isRatioLocked:this.state.isRatioLocked,isOriginalBelowMCR:v,isPredictionMarket:E,isValid:E||!E&&!isNaN(w),useTargetCollateral:d,onBorrowChange:this._onBorrowChange.bind(this),onCollateralChange:this._onCollateralChange.bind(this),onMaximizeCollatereal:this._maximizeCollateral.bind(this),onRatioChange:this._onRatioChange.bind(this),onLockChangeCR:this._onLockCR.bind(this),onLockChangeCollateral:this._onLockChange.bind(this,"debt"),onLockChangeDebt:this._onLockChange.bind(this,"collateral"),onPayDebt:this._payDebt.bind(this),onTCRatioChange:this._onTargetRatioChange.bind(this),onSetUseTCR:this._setUseTargetCollateral.bind(this)}))}}R=(0,p.A)(R),R=(0,y.Ay)(R,50,{leading:!1});class P extends s.Component{constructor(){super(),this.state={smallScreen:!1,open:!1}}show(){this.props.showModal()}UNSAFE_componentWillMount(){this.setState({smallScreen:window.innerHeight<=800})}render(){let t,e,{quoteAssetObj:a,backingAssetObj:l,accountObj:o}=this.props,i=o.get("balances").toJS();if(i)for(var n in i)n===l&&(t=i[n]),n===a&&(e=i[n]);return this.props.visible?s.createElement(R,{visible:this.props.visible,hideModal:this.props.hideModal,showModal:this.props.showModal,quoteAssetObj:a,call_orders:o.get("call_orders",(0,g.List)()).toList(),hasCallOrders:o.get("call_orders")&&o.get("call_orders").size>0,modalId:this.props.modalId,debtBalanceObj:e,collateralBalanceObj:t,backingAssetObj:l,disableHelp:this.state.smallScreen,accountObj:o}):null}}},62611:(t,e,a)=>{a.d(e,{A:()=>r});var s=a(96540),l=a(87040),o=a(5556),i=a.n(o);class n extends s.Component{static propTypes={scroll_length:i().number};static defaultProps={scroll_length:9};constructor(t){t.scroll_length,super(t),this.state={active:!1},this.listener=!1,this.onBodyClick=this.onBodyClick.bind(this)}componentDidMount(){this._setListener()}shouldComponentUpdate(t,e){return!l.A.are_equal_shallow(t.entries,this.props.entries)||!l.A.are_equal_shallow(e,this.state)||t.value!==this.props.value}_setListener(t=this.props){t.entries.length>1&&!this.listener&&(this.listener=!0,document.body.addEventListener("click",this.onBodyClick,{capture:!1,passive:!0}))}_removeListener(){document.body.removeEventListener("click",this.onBodyClick),this.listener=!1}UNSAFE_componentWillReceiveProps(t){1===t.entries.length?this._removeListener():t.entries.length>1&&this._setListener(t)}componentWillUnmount(){this._removeListener()}onBodyClick(t){let e=t.target,a=!1;do{if(e.classList&&e.classList.contains("dropdown")&&e.id===this.props.id){a=!0;break}}while(e=e.parentNode);a?t.stopPropagation():this.setState({active:!1})}onChange(t,e){e.preventDefault(),e.stopPropagation(),this.props.onChange(t),this.setState({active:!1})}_toggleDropdown(){this.setState({active:!this.state.active})}render(){const{entries:t,value:e}=this.props;let{active:a}=this.state;if(0===t.length)return null;if(1==t.length)return s.createElement("div",{className:"dropdown-wrapper inactive"+(this.props.upperCase?" upper-case":"")},s.createElement("div",null,this.props.singleEntry?this.props.singleEntry:t[0]));{let l=t.map((t=>s.createElement("li",{className:this.props.upperCase?"upper-case":"",key:t,onClick:this.onChange.bind(this,this.props.values[t])},s.createElement("span",null,t))));return s.createElement("div",{onClick:this._toggleDropdown.bind(this),className:"dropdown-wrapper"+(a?" active":"")+(this.props.upperCase?" upper-case":"")},s.createElement("div",{style:{paddingRight:15}},e||s.createElement("span",{className:"hidden"},"A")),s.createElement("ul",{className:"dropdown",style:{overflow:t.length>this.props.scroll_length?"auto":"hidden"}},l))}}}const r=n}}]);