-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathQuickTrade.200b11fb64c5f4d715c7.js
More file actions
1 lines (1 loc) · 27.6 KB
/
QuickTrade.200b11fb64c5f4d715c7.js
File metadata and controls
1 lines (1 loc) · 27.6 KB
1
"use strict";(this.webpackChunkBitShares2_light=this.webpackChunkBitShares2_light||[]).push([[614],{28269(e,t,s){s.r(t),s.d(t,{default:()=>H});var n=s(96540),i=s(188),r=s(64741),a=s(37556),o=s(9476),l=s(72181),c=s(58586),u=s(46128),h=s(80849),d=s.n(h),m=s(5556),p=s.n(m),g=s(50548),A=s(10658),v=s.n(A),_=s(49568);function f(){return f=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(e[n]=s[n])}return e},f.apply(this,arguments)}class S extends n.Component{static propTypes={chains:p().array,placeholder:p().string,style:p().object,selectStyle:p().object};static defaultProps={chains:["BitShares Blockchain"],placeholder:null,style:{},selectStyle:{}};render(){let{chains:e,selectStyle:t,style:s,placeholder:i,value:r,onDropdownVisibleChange:a,...o}=this.props;const l=e.filter(_.T5.isMap).length<=1&&!a;r||(r=e[0]);const c=n.createElement(u.Select,f({onDropdownVisibleChange:a,showArrow:!l&&void 0,style:t,placeholder:n.createElement(d(),{content:i||"utility.asset_select_placeholder"}),value:r},o,{optionFilterProp:"children",filterOption:(e,t)=>t.key.toLowerCase().indexOf(e.toLowerCase())>=0,disabled:l,notFoundContent:v().translate("global.not_found")}),e.filter(_.T5.isMap).map(e=>n.createElement(u.Select.Option,{key:e,value:e},e)));return n.createElement("div",{className:"chain-select",style:s},c)}}const b=S;class I extends n.Component{static propTypes={label:p().string,assetInput:p().string,asset:p().string,assets:p().array,amount:p().string,disabled:p().bool,onAssetInputChange:p().func,onAmountChange:p().func,onImageError:p().func,onSearch:p().func,imgName:p().string,placeholderAmount:p().string,placeholder:p().string};static defaultProps={disabled:!1,imgName:"unknown",placeholderAmount:"0.0",placeholder:""};constructor(e){super(e),this.state={imageError:!1}}componentDidUpdate(e,t){this.props.imgName&&this.props.imgName!==e.imgName&&"unknown"!==this.props.imgName&&this.setState({imageError:!1})}onImageError(){this.setState({imageError:!0})}render(){let{label:e,assetInput:t,asset:s,assets:i,amount:r,onAssetInputChange:a,onSearch:o,onAmountChange:l,imgName:c,placeholder:h,placeholderAmount:m,tooltipText:p}=this.props;this.state.imageError&&(c="unknown");const A=n.createElement(d(),{className:"left-label",component:"label",content:e,style:{fontSize:"1.2rem",margin:"0",padding:"0"}}),v=n.createElement(b,null),_=n.createElement("img",{style:{width:"3.5rem",height:"3.5rem",marginTop:"0.5rem"},onError:this.onImageError.bind(this),src:`asset-symbols/${c.toLowerCase()}.png`}),f=n.createElement(g.A,{onChange:l,amount:r,asset:s,assets:i,placeholder:m,onSearch:o});return n.createElement("div",{className:"amount-selector-2",style:{minWidth:"3.5rem",width:"100%"}},A,n.createElement(u.Row,{style:{minWidth:"18rem"}},n.createElement(u.Col,{style:{minWidth:"3.5rem"},span:5},_),n.createElement(u.Col,{span:19},n.createElement(u.Tooltip,{placement:"top",title:p},v),f)))}}const y=I;var k=s(36234);class C extends n.Component{static propTypes={sellAssetInput:p().string,sellAsset:p().string,sellAssets:p().array,sellAmount:p().string,sellImgName:p().string,receiveAssetInput:p().string,receiveAsset:p().string,receiveAssets:p().array,receiveAmount:p().string,receiveImgName:p().string,onSellAssetInputChange:p().func.isRequired,onSellAmountChange:p().func.isRequired,onReceiveAssetInputChange:p().func.isRequired,onReceiveAmountChange:p().func.isRequired,onSwap:p().func.isRequired,isSwappable:p().bool};render(){const e=window.innerWidth<850,{sellAssetInput:t,sellAsset:s,sellAssets:i,sellAmount:r,sellImgName:a,receiveAssetInput:o,receiveAsset:l,receiveAssets:c,receiveAmount:h,receiveImgName:d,onSellAssetInputChange:m,onSellAmountChange:p,onReceiveAssetInputChange:g,onReceiveAmountChange:A,onReceiveAssetSearch:v,onSwap:_,isSwappable:f}=this.props,S=n.createElement(y,{label:"exchange.sell",assetInput:t,asset:s,assets:i,amount:r,onAssetInputChange:m,onAmountChange:p,imgName:a,placeholder:"exchange.quick_trade_details.placeholder_sell"}),b=n.createElement(y,{label:"exchange.receive",assetInput:o,asset:l,assets:c,amount:h,onAssetInputChange:g,onSearch:v,onAmountChange:A,imgName:d,placeholder:"exchange.quick_trade_details.placeholder_receive"}),I={align:"center",display:"flex",justifyContent:"center"};f||(I.opacity=.1);const C=n.createElement("div",{style:I},n.createElement(k.A,{name:"swap",size:"2x",style:e?null:{marginTop:"3rem"},onClick:_}));return n.createElement("div",null,e?n.createElement("div",null,n.createElement(u.Row,null,S),n.createElement(u.Row,null,C),n.createElement(u.Row,null,b)):n.createElement(u.Row,null,n.createElement(u.Col,{span:10},S),n.createElement(u.Col,{span:4},C),n.createElement(u.Col,{span:10},b)))}}const E=C;var w=s(36247),T=s(87040),P=s(72090),x=s(15483);function R(e,t,s){const n=[];let i;t.sort((e,t)=>t.getPrice()-e.getPrice());for(let r=0;r<t.length;r++)if(n.length){if(n.forEach(({order:e})=>{i="receive"===s?e.total_for_sale.getAmount():e.total_to_receive.getAmount()}),i>=e)break;n.push({order:t[r],amount:t[r].amountToReceive().amount,total_amount:t[r].total_to_receive.amount,price:t[r].getPrice()})}else n.push({order:t[r],amount:t[r].amountToReceive().amount,total_amount:t[r].total_to_receive.amount,price:t[r].getPrice()});return n}function F(e){let t=[];if(!e||!e.get("balances"))return t;let s=e.get("balances").toJS();t=Object.keys(s).sort(T.A.sortID);for(let e in s){let n=P.ChainStore.getObject(s[e]);n&&0===n.get("balance")&&t.splice(t.indexOf(e),1)}return t}var D=s(44352),q=s(44483),M=s(63024),O=s(24609),N=s(32853),L=s(91001);class V extends n.Component{constructor(e){super(e);const t=F(e.currentAccount);this.state={mounted:!1,sub:"",sellAssetInput:"",sellAsset:null,sellAssets:t,sellAmount:"",sellImgName:"unknown",receiveAssetInput:"",receiveAsset:null,receiveAssets:t,receiveAmount:"",receiveImgName:"unknown",activeInput:"",activeAmountInput:"",lookupQuote:"",orders:[],orderView:"amount",fees:null,prices:null,isSubscribedToMarket:!0},this.onSellAssetInputChange=this.onSellAssetInputChange.bind(this),this.onReceiveAssetInputChange=this.onReceiveAssetInputChange.bind(this),this.onSellAmountChange=this.onSellAmountChange.bind(this),this.onReceiveAmountChange=this.onReceiveAmountChange.bind(this),this.onSellImageError=this.onSellImageError.bind(this),this.onReceiveImageError=this.onReceiveImageError.bind(this),this.onReceiveAssetSearch=this.onReceiveAssetSearch.bind(this),this.onSwap=this.onSwap.bind(this),this.handleSubscriptionToggleChange=this.handleSubscriptionToggleChange.bind(this),this.hendleOrderView=this.hendleOrderView.bind(this),this.handleSell=this.handleSell.bind(this),this._subToMarket=this._subToMarket.bind(this),this._checkAndUpdateMarketList=this._checkAndUpdateMarketList.bind(this),this.getAssetList=(0,r.A)(D.A.getAssetList.defer,150)}static getDerivedStateFromProps(e,t){let s={};return e.assetToSell&&(s={sellAssetInput:e.assetToSell.get("id"),sellAsset:e.assetToSell,sellImgName:e.assetToSell.get("symbol")}),e.assetToReceive&&(s={...s,receiveAssetInput:e.assetToReceive.get("id"),receiveAsset:e.assetToReceive,receiveImgName:e.assetToReceive.get("symbol")}),s}_routeTo(e,t){let s=e,n=t;e||(s=""),t||(n="");let i="/instant-trade/"+s+"_"+n;this.props.location.pathname!==i&&this.props.history.push(i)}_areEqualAssets(e,t){return this._isLoadedAsset(e)&&this._isLoadedAsset(t)&&e.get("id")===t.get("id")}_isLoadedAsset(e){return!!e&&!!e.toJS}_areAssetsGiven(){return this._isLoadedAsset(this.props.assetToSell)&&this._isLoadedAsset(this.props.assetToReceive)}_haveAssetsChanged(e){return this._isLoadedAsset(this.props.assetToSell)!==this._isLoadedAsset(e.assetToSell)||this._isLoadedAsset(this.props.assetToReceive)!==this._isLoadedAsset(e.assetToReceive)||!this._areEqualAssets(this.props.assetToSell,e.assetToSell)||!this._areEqualAssets(this.props.assetToReceive,e.assetToReceive)}_hasMarketChanged(e){return JSON.stringify(e.marketData)!==JSON.stringify(this.props.marketData)}componentDidUpdate(e){if(this._haveAssetsChanged(e)?this._assetsHaveChanged():this._hasMarketChanged(e)&&this._getOrders(),this.props.searchAssets!==e.searchAssets){this.setState({activeSearch:!0});let e=this.props.searchAssets.toArray().filter(e=>-1!==e.symbol.indexOf(this.state.lookupQuote));this._checkAndUpdateMarketList(e)}if(this.props.currentAccount!==e.currentAccount){const e=F(this.props.currentAccount);this.setState({sellAssets:e,receiveAssets:e})}}componentDidMount(){this.setState({mounted:!0}),this._areAssetsGiven()&&this._assetsHaveChanged()}componentWillUnmount(){const{sub:e}=this.state,{sellAssetId:t,receiveAssetId:s}=this.getAssetsDetails();e&&w.A.unSubscribeMarket(t,s)}async _subToMarket(){const{receiveAsset:e,sellAsset:t,sub:s}=this.state;if(e&&t){const{receiveAssetId:n,sellAssetId:i}=this.getAssetsDetails(),{bucketSize:r,currentGroupOrderLimit:a}=this.props;if(s){let[e,t]=s.split("_");if(e===i&&t===n)return;await w.A.unSubscribeMarket(e,t)}await w.A.subscribeMarket(e,t,3600,0),this.setState({sub:`${i}_${n}`},()=>{this.getAllPrices(),this.getAllFees()})}}async getAllFees(){const{currentAccount:e}=this.props,{sellAsset:t,receiveAsset:s}=this.state;if(t&&s){const n=await async function(e,t,s){return{marketFee:{baseMarketFeePercent:e.getIn(["options","market_fee_percent"])/100+"%",quoteMarketFeePercent:t.getIn(["options","market_fee_percent"])/100+"%",baseMarketFee:e.getIn(["options","market_fee_percent"]),quoteMarketFee:t.getIn(["options","market_fee_percent"])},transactionFee:await async function(e=[],t){let s={},n=[];return e.forEach(e=>{n.push((0,x.hQ)({accountID:t.get("id"),feeID:e.get("id"),type:"limit_order_create"}))}),Promise.all(n).then(t=>(e.forEach((e,n)=>{s[e.get("id")]=t[n]}),s)).catch(e=>(console.error("checkFeeStatusAsync error",e),s))}([e,t],s)}}(s,t,e);this.setState({fees:n})}}getAssetsDetails(){const{sellAsset:e,receiveAsset:t}=this.state;return{sellAssetId:e?e.get("id"):null,receiveAssetId:t?t.get("id"):null,sellAssetPrecision:e?e.get("precision"):null,receiveAssetPrecision:t?t.get("precision"):null,sellAssetSymbol:e?e.get("symbol"):null,receiveAssetSymbol:t?t.get("symbol"):null}}getAllPrices(){const{activeMarketHistory:e,feedPrice:t}=this.props,s=function(e,t){let s;return e.size&&(s=e.take(2).first().getPrice()),{latestPrice:s||null,feedPrice:t?t.toReal():t}}(e,t);this.setState({prices:s})}_getOrders(){if(!this.state.isSubscribedToMarket)return void console.log(this.props.marketData);const{combinedBids:e}=this.props.marketData,{sellAsset:t,receiveAsset:s,sellAmount:n,receiveAmount:i,activeInput:r}=this.state,{sellAssetPrecision:a,receiveAssetPrecision:o}=this.getAssetsDetails();if(e&&e.length&&t&&s)switch(r){case"receiveAsset":if(n){const t=R(n*10**a,e,"sell");this.setState({orders:t,ordersUpdated:new Date},()=>this.updateReceiveAmount())}break;case"sellAsset":if(i){const t=R(i*10**o,e,"receive");this.setState({orders:t,ordersUpdated:new Date},()=>this.updateSellAmount())}break;case"sell":if(n){const t=R(n*10**a,e,"sell");this.setState({orders:t,ordersUpdated:new Date},()=>this.updateReceiveAmount())}else this.setState({orders:[],receiveAmount:""});break;case"receive":if(i){const t=R(i*10**o,e,"receive");this.setState({orders:t,ordersUpdated:new Date},()=>this.updateSellAmount())}else this.setState({orders:[],sellAmount:""})}}_assetsHaveChanged(){this._subToMarket()}async _setSellAsset(e,t="sellAsset",s=!0){let n=null;n="string"==typeof e?await(0,P.FetchChain)("getAsset",e):e,this.setState({activeInput:t},()=>{this._routeTo(n.get("symbol"),this.props.assetToReceive?this.props.assetToReceive.get("symbol"):"")})}async _setReceiveAsset(e,t="receiveAsset",s=!0){let n=null;n="string"==typeof e?await(0,P.FetchChain)("getAsset",e):e,this.setState({activeInput:t},()=>{this._routeTo(this.props.assetToSell?this.props.assetToSell.get("symbol"):"",n.get("symbol"))})}async _swapAssets(e,t=!0){this.setState({sellAmount:"sellAsset"===e?"":this.state.receiveAmount,receiveAmount:"receiveAsset"===e?"":this.state.sellAmount,activeInput:e},()=>{this._routeTo(this.state.receiveAsset.get("symbol"),this.state.sellAsset.get("symbol"))})}async onSellAssetInputChange(e){const{receiveAssetId:t}=this.getAssetsDetails();e===t?this._swapAssets("sellAsset"):this._setSellAsset(e)}async onReceiveAssetInputChange(e){const{sellAssetId:t}=this.getAssetsDetails();e===t?this._swapAssets("receiveAsset"):this._setReceiveAsset(e)}onReceiveAssetSearch(e){this.state.mounted&&(P.ChainValidation.is_valid_symbol_error(e,!0)?this.setState({receiveAsset:null,receiveAssetInput:e,activeSearch:!1}):(this.state.receiveAssetInput!==e&&this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{(0,q.YY)(e,!0,this.getAssetList,this.setState)},100)))}_checkAndUpdateMarketList(e){let t=e.map(e=>e.id);clearInterval(this.intervalId);const{receiveAssetInput:s}=this.state;let n="";if(P.ChainStore.getAsset(s)){const e=P.ChainStore.getAsset(s).get("id");t.includes(e)&&(n=P.ChainStore.getAsset(s).get("id"))}if(1===t.length){n=t[0];const{currentAccount:e}=this.props;t=F(e),t.push(n)}if(0===t.length){const{currentAccount:e}=this.props;t=F(e)}this.intervalId=setInterval(()=>{clearInterval(this.intervalId),this.setState({receiveAssets:t,activeSearch:!1},()=>{this._subToMarket()})},100)}onSellAmountChange(e){this.state.mounted&&(e.asset!==this.state.sellAssetInput&&this.onSellAssetInputChange(e.asset),this.setState({sellAmount:e.amount,activeInput:"sell",activeAmountInput:"sell"},()=>{this._getOrders()}))}onReceiveAmountChange(e){this.state.mounted&&(e.asset!==this.state.receiveAssetInput&&this.onReceiveAssetInputChange(e.asset),this.setState({receiveAmount:e.amount,activeInput:"receive",activeAmountInput:"receive"},()=>{this._getOrders()}))}onSellImageError(){this.setState({sellImgName:"unknown"})}onReceiveImageError(){this.setState({receiveImgName:"unknown"})}onSwap(){this.isSwappable()&&this._swapAssets("neither")}handleSubscriptionToggleChange(){this.setState(e=>({isSubscribedToMarket:!e.isSubscribedToMarket}))}hendleOrderView(){this.setState(e=>({orderView:"amount"===e.orderView?"total":"amount"}))}handleSell(){const{currentAccount:e}=this.props,{sellAmount:t,receiveAmount:s}=this.state,{sellAssetId:n,receiveAssetId:i,sellAssetPrecision:r,receiveAssetPrecision:a}=this.getAssetsDetails(),o=new O.Vd({asset_id:n,precision:r,amount:t*10**r}),l=new O.Vd({asset_id:i,precision:a,amount:s*10**a}),c=new Date(Date.now()+31536e6),h=new O.uw({for_sale:o,expiration:c,to_receive:l,seller:e.get("id"),fee:{asset_id:"1.3.0",amount:0},fill_or_kill:!0});return w.A.createLimitOrder2(h).then(e=>{e.error&&"wallet locked"!==e.error.message&&u.Notification.error({message:v().translate("notifications.exchange_unknown_error_place_order",{amount:s,symbol:i})})}).catch(e=>{console.error("order failed:",e)})}updateSellAmount(){const{orders:e,receiveAmount:t}=this.state,{sellAssetPrecision:s,receiveAssetPrecision:n}=this.getAssetsDetails();if(1===e.length){const n=(t/e[0].order.getPrice()).toFixed(s);return void this.setState({sellAmount:n})}if(e.length>1){const i=e.slice(-1)[0],r=e.slice(e.length-2,e.length-1)[0],a=(t*10**n-r.order.total_for_sale.getAmount())/i.order.getPrice()*10**s/10**n,o=((r.order.total_to_receive.getAmount()+a)/10**s).toFixed(s);return void this.setState({sellAmount:o})}}updateReceiveAmount(){const{orders:e,sellAmount:t}=this.state,{sellAssetPrecision:s,receiveAssetPrecision:n}=this.getAssetsDetails();if(1===e.length){const s=(e[0].order.getPrice()*t).toFixed(n);return void this.setState({receiveAmount:s})}if(e.length>1){const i=e.slice(-1)[0],r=e.slice(e.length-2,e.length-1)[0],a=(t*10**s-r.order.total_to_receive.getAmount())*i.order.getPrice()*10**n/10**s,o=((r.order.total_for_sale.getAmount()+a)/10**n).toFixed(n);return void this.setState({receiveAmount:o})}}isSwappable(){return this._areAssetsGiven()}_getTransactionFee(e){const{fees:t,prices:s}=this.state,{sellAssetId:n}=this.getAssetsDetails();return t&&t.transactionFee[n]?e&&e!==n?t.transactionFee[n].fee.amount/10**t.transactionFee[n].fee.precision*s.latestPrice:t.transactionFee[n].fee.amount/10**t.transactionFee[n].fee.precision:0}_getMarketFee(e){const{fees:t,prices:s,receiveAmount:n}=this.state,{receiveAssetId:i}=this.getAssetsDetails();return t?e&&e!==i?t.marketFee.baseMarketFee*n/s.latestPrice/1e4:t.marketFee.baseMarketFee*n/1e4:0}_getFeePercent(e,t){return+t?(+t+ +e)/t-1:0}getDetails(){const{sub:e}=this.state;if(!e)return;const{sellAmount:t,receiveAmount:s}=this.state,{sellAssetId:i,receiveAssetId:r,sellAssetPrecision:a,receiveAssetPrecision:o,receiveAssetSymbol:l}=this.getAssetsDetails(),c=this.getPriceSection(),h=n.createElement(n.Fragment,null,v().translate("exchange.quick_trade_details.effective")," ",n.createElement(N.A,{base_asset:i,quote_asset:r,base_amount:t*10**a,quote_amount:s*10**o,noPopOver:!0,force_direction:l,noInvertTip:!0})),d=this.getFeeSection(),m=this.getOrdersSection(),p=v().translate("exchange.quick_trade_details.effective")+" "+(100*this.getTotalPercentFee()).toFixed(2),g=this.state.orders.length,A=g<2?v().translate("exchange.quick_trade_details.order"):v().translate("exchange.quick_trade_details.orders");return n.createElement(u.Collapse,{className:"asset-collapse",style:{marginTop:"1rem"}},n.createElement(u.Collapse.Panel,{header:v().translate("exchange.price"),extra:h},c),n.createElement(u.Collapse.Panel,{header:v().translate("exchange.fee"),extra:`${p}%`},d),n.createElement(u.Collapse.Panel,{header:v().translate("exchange.orders"),extra:g?`${g} ${A}`:"no orders"},m))}showDetails(){const{sellAsset:e,receiveAsset:t,sellAmount:s,receiveAmount:n}=this.state;return e&&t&&+s&&+n}showFeedPrice(){const{sellAsset:e,receiveAsset:t}=this.state,{sellAssetId:s,receiveAssetId:n}=this.getAssetsDetails(),i=t.getIn(["bitasset","options","short_backing_asset"]),r=e.getIn(["bitasset","options","short_backing_asset"]);return i===s||r===n}getPriceSection(){const{prices:e,sellAmount:t,receiveAmount:s}=this.state,{sellAssetId:i,receiveAssetId:r,sellAssetPrecision:a,receiveAssetPrecision:o,receiveAssetSymbol:l}=this.getAssetsDetails();return n.createElement(u.Row,null,n.createElement(u.Col,{span:12},n.createElement("div",null,v().translate("exchange.quick_trade_details.your_price")),this.showFeedPrice()&&n.createElement("div",null,v().translate("exchange.quick_trade_details.feed_price")),n.createElement("div",null,v().translate("exchange.quick_trade_details.last_price"))),n.createElement(u.Col,{span:12,style:{textAlign:"right"}},n.createElement("div",null,n.createElement(N.A,{base_asset:i,quote_asset:r,base_amount:t*10**a,quote_amount:s*10**o,noPopOver:!0,force_direction:l,noInvertTip:!0})),this.showFeedPrice()&&n.createElement("div",null,n.createElement(N.A,{base_asset:i,quote_asset:r,base_amount:1*10**a,quote_amount:e.feedPrice*10**o,noPopOver:!0,force_direction:l,noInvertTip:!0})),n.createElement("div",null,n.createElement(N.A,{base_asset:i,quote_asset:r,base_amount:1*10**a,quote_amount:e.latestPrice*10**o,noPopOver:!0,force_direction:l,noInvertTip:!0}))))}getFeeSection(){const{sellAmount:e,receiveAmount:t}=this.state,{sellAssetPrecision:s,receiveAssetPrecision:i,sellAssetSymbol:r,receiveAssetSymbol:a}=this.getAssetsDetails(),o=this._getTransactionFee().toFixed(s),l=(100*this._getFeePercent(this._getTransactionFee(),e)).toFixed(2),c=this._getMarketFee().toFixed(i),h=(100*this._getFeePercent(this._getMarketFee(),t)).toFixed(2);let[d,m]=this.getLiquidityPenalty();d=d||0===d?(100*d).toFixed(2)+"%":"-",m=m||0===m?(100*m).toFixed(2)+"%":"-";const p=this.showFeedPrice()?`${d} / ${m}`:d;return n.createElement(u.Row,null,n.createElement(u.Col,{span:12},n.createElement("div",null,v().translate("exchange.quick_trade_details.liquidity_penalty")),n.createElement("div",null,v().translate("exchange.quick_trade_details.market_fee"),` ${h}%`),n.createElement("div",null,v().translate("exchange.quick_trade_details.transaction_fee"),` ${l}%`)),n.createElement(u.Col,{span:12,style:{textAlign:"right"}},n.createElement("div",null,p),n.createElement("div",null,c," ",n.createElement(L.A,{name:a,noTip:!0})),n.createElement("div",null,o," ",n.createElement(L.A,{name:r,noTip:!0}))))}getOrdersSection(){const{orders:e,orderView:t}=this.state,{sellAssetId:s,receiveAssetId:i,sellAssetPrecision:r,sellAssetSymbol:a,receiveAssetSymbol:o}=this.getAssetsDetails(),l=e.map(e=>({key:e.order.id,id:e.order.id,seller:n.createElement(M.A,{account:e.order.seller}),amount:n.createElement("div",{onClick:this.hendleOrderView},"amount"===t?e.amount/10**r:e.total_amount/10**r),price:e.price})),c=n.createElement("span",null,"amount"===t?v().translate("exchange.quick_trade_details.amount"):v().translate("exchange.quick_trade_details.total")," (",n.createElement(L.A,{name:a,noTip:!0}),")"),h=n.createElement("span",null,v().translate("exchange.quick_trade_details.price")," (",n.createElement(N.A,{base_asset:s,quote_asset:i,noPopOver:!0,force_direction:o,noInvertTip:!0,hide_value:!0}),")"),m=[{title:v().translate("exchange.quick_trade_details.id"),dataIndex:"id",key:"id",width:"20%"},{title:v().translate("exchange.quick_trade_details.seller"),dataIndex:"seller",key:"seller",width:"20%"},{title:c,dataIndex:"amount",key:"amount",width:"30%"},{title:h,dataIndex:"price",key:"price"}];return n.createElement("div",null,n.createElement(u.Switch,{style:{marginLeft:"0px"},onChange:this.handleSubscriptionToggleChange,checked:this.state.isSubscribedToMarket}),this.state.ordersUpdated&&n.createElement("div",{style:{float:"right"}},v().localize(this.state.ordersUpdated)),n.createElement(d(),{onClick:this.handleSubscriptionToggleChange,content:"exchange.quick_trade_details.subscribe_to_market",style:{marginLeft:"10px",cursor:"pointer"}}),n.createElement(u.Table,{columns:m,dataSource:l,style:{width:"100%",marginTop:"10px"},pagination:l.length>5&&{pageSize:5}}))}getLiquidityPenalty(){const{prices:e,sellAmount:t,receiveAmount:s}=this.state,n=s/t,i=e.latestPrice,r=e.feedPrice;let a,o;return n&&i&&(a=Math.max(1-n/i,1-i/n)),n&&r&&(o=Math.max(1-n/r,1-r/n)),[a,o]}getTotalPercentFee(){const{sellAmount:e,receiveAmount:t}=this.state;return this._getFeePercent(this._getTransactionFee(),e)+this._getFeePercent(this._getMarketFee(),t)+this.getLiquidityPenalty()[0]}hasBalance(){const{sellAmount:e}=this.state,{currentAccount:t}=this.props,s=t.get("balances").toJS(),{sellAssetId:n,sellAssetPrecision:i}=this.getAssetsDetails();if(!s[n])return!1;const r=P.ChainStore.getObject(s[n]).get("balance");return e*10**i+this._getTransactionFee()*10**i<+r}render(){const{sellAssetInput:e,sellAssets:t,sellAmount:s,sellImgName:i,receiveAssetInput:r,receiveAssets:a,receiveAmount:o,receiveImgName:l,sub:c}=this.state,{sellAssetId:h,receiveAssetId:d}=this.getAssetsDetails(),m=this.showDetails()?this.getDetails():null;return n.createElement(u.Card,{className:"quick-trade",style:{align:"center",display:"flex",justifyContent:"center",minWidth:"300px",marginTop:"1rem"}},n.createElement(E,{sellAssetInput:e,sellAsset:h,sellAssets:t,sellAmount:s,sellImgName:i,onSellAssetInputChange:this.onSellAssetInputChange,onSellAmountChange:this.onSellAmountChange,receiveAssetInput:r,receiveAsset:d,receiveAssets:a,receiveAmount:o,receiveImgName:l,onReceiveAssetInputChange:this.onReceiveAssetInputChange,onReceiveAmountChange:this.onReceiveAmountChange,onReceiveAssetSearch:this.onReceiveAssetSearch,onSwap:this.onSwap,isSwappable:this.isSwappable()}),m,n.createElement("div",{style:{marginTop:"1rem",textAlign:"center"}},n.createElement(u.Tooltip,{title:this.hasBalance()?null:v().translate("exchange.no_balance")},n.createElement(u.Button,{key:"sell",type:"primary",disabled:!this.showDetails()||!c||!this.hasBalance(),onClick:this.handleSell},v().translate("exchange.sell")))))}}V=(0,o.N)(V,{listenTo:()=>[l.A,c.A],getProps:()=>({searchAssets:l.A.getState().assets,assetsLoading:l.A.getState().assetsLoading,marketData:c.A.getState().marketData,activeMarketHistory:c.A.getState().activeMarketHistory,bucketSize:c.A.getState().bucketSize,currentGroupOrderLimit:c.A.getState().currentGroupOrderLimit,feedPrice:c.A.getState().feedPrice,marketLimitOrders:c.A.getState().marketLimitOrders})});const U=V=(0,a.V)(V);var B=s(12569),j=s(72342);function W(){return W=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(e[n]=s[n])}return e},W.apply(this,arguments)}class $ extends n.Component{static propTypes={assetToSell:B.A.ChainAsset,assetToReceive:B.A.ChainAsset};static defaultProps={assetToSell:"CNY",assetToReceive:"BTS"};render(){return this.props.assetToReceive.get&&this.props.assetToSell.get?n.createElement(U,this.props):null}}const z=(0,j.A)($,{show_loader:!0});class G extends n.Component{render(){let e=this.props.match.params.marketID?this.props.match.params.marketID.toUpperCase().split("_"):["",""];return 2==e.length&&e[0]&&e[0]===e[1]?n.createElement(i.A,{subtitle:"market_not_found_subtitle"}):n.createElement(z,W({},this.props,{assetToSell:e[0]||"",assetToReceive:2==e.length?e[1]:""}))}}const H=G},37556(e,t,s){s.d(t,{K:()=>u,V:()=>h});var n=s(96540),i=s(12569),r=s(83599),a=s(72342),o=s(9476),l=s(55840),c=s(40702);const u=function(e){return!!e&&!!e.get("id")},h=function(e){let t=class extends n.Component{static propTypes={currentAccount:i.A.ChainAccount};static defaultProps={autosubscribe:!0};constructor(e){super(e)}render(){return u(this.props.currentAccount)?n.createElement(e,this.props):n.createElement(c.A,null)}};return t=(0,a.A)(t),t=(0,r.Ay)(t,100,{leading:!1}),(0,o.N)(t,{listenTo:()=>[l.A],getProps(){let e=l.A.getState().currentAccount||l.A.getState().passwordAccount||"please-login";return{currentAccount:new Map([["name",e]])}}})}},44483(e,t,s){s.d(t,{DB:()=>a,YY:()=>r,nM:()=>l});var n=s(41321),i=s(72090);function r(e,t=!1,s,n){if(!e&&""!==e)return;let i=e.toUpperCase();i.startsWith("BIT")&&i.length>=6&&(i=e.substr(3,i.length-1)),s(i,10,t),n({lookupQuote:i})}function a({searchAssets:e,marketPickerAsset:t,baseAsset:s,quoteAsset:i},{inputValue:r,lookupQuote:a},c,u){c({activeSearch:!0});let h=0,d=[],m=s.get("symbol"),p=i.get("symbol");e.size&&r&&r.length>2&&e.filter(e=>{try{if(e.options.description){let t=JSON.parse(e.options.description);if("visible"in t&&!t.visible)return!1}}catch(e){}return-1!==e.symbol.indexOf(a)}).forEach(e=>{if(h>100)return;h++;let n=l(e.issuer),i=s.get("symbol"),r=e.symbol+"_"+i,a=p==t;(a&&e.symbol!=m||!a&&e.symbol!=p)&&d.push([r,{quote:e.symbol,base:i,issuerId:e.issuer,issuer:n}])});const g=function(e,t){return t.startsWith("BIT")&&t.length>=6&&(t=t.substr(3,t.length-1)),e.sort(([,e],[,s])=>{const i=o(e),r=o(s);if(i.asset!==r.asset){if(i.asset===t)return-1;if(r.asset===t)return 1;if(i.asset>r.asset)return-1;if(i.asset<r.asset)return 1}if(i.isCommittee^r.isCommittee){if(i.isCommittee)return-1;if(r.isCommittee)return 1}const a=(0,n.DC)(e.quote),l=(0,n.DC)(s.quote);return a&&!l?-1:l&&!a||i.gateway>r.gateway?1:i.gateway<r.gateway?-1:0})}(d,r);u(g)}function o(e){const t={},s=e.quote;if(-1!==s.indexOf(".")){const[e,n]=s.split(".");t.gateway=e,t.asset=n}else t.asset=s;return"1.2.0"===e.issuerId&&(t.isCommittee=!0),t}function l(e){let t=i.ChainStore.getObject(e,!1,!1);return t?t.get("name"):void 0}},64741(e,t,s){s.d(t,{A:()=>c});var n=s(23149),i=s(41917);const r=function(){return i.A.Date.now()};var a=s(50751),o=Math.max,l=Math.min;const c=function(e,t,s){var i,c,u,h,d,m,p=0,g=!1,A=!1,v=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function _(t){var s=i,n=c;return i=c=void 0,p=t,h=e.apply(n,s)}function f(e){var s=e-m;return void 0===m||s>=t||s<0||A&&e-p>=u}function S(){var e=r();if(f(e))return b(e);d=setTimeout(S,function(e){var s=t-(e-m);return A?l(s,u-(e-p)):s}(e))}function b(e){return d=void 0,v&&i?_(e):(i=c=void 0,h)}function I(){var e=r(),s=f(e);if(i=arguments,c=this,m=e,s){if(void 0===d)return function(e){return p=e,d=setTimeout(S,t),g?_(e):h}(m);if(A)return clearTimeout(d),d=setTimeout(S,t),_(m)}return void 0===d&&(d=setTimeout(S,t)),h}return t=(0,a.A)(t)||0,(0,n.A)(s)&&(g=!!s.leading,u=(A="maxWait"in s)?o((0,a.A)(s.maxWait)||0,t):u,v="trailing"in s?!!s.trailing:v),I.cancel=function(){void 0!==d&&clearTimeout(d),p=0,i=m=c=d=void 0},I.flush=function(){return void 0===d?h:b(r())},I}}}]);