text: (this["webpackJsonpmy-app"]=this["webpackJsonpmy-app"]||[]).push([[0],{13:function(e,t,n){},15:function(e,t,n){},16:function(e,t,n){"use strict";n.r(t);var r=n(0),a=n.n(r),c=n(7),l=n.n(c),u=(n(13),n(2)),o=n.n(u),i=n(4),s=n(3),m=n(5),d=n(1),f=(n(15),{addon:new(0,window.Addon)}),p=function(e){return f.addon.api.getPositions({groups:e.groupsFilter,institutions:e.institutionsFilter,investments:e.investmentsFilter})},E=function(e){return f.addon.api.getInstitutions({groups:e.groupsFilter,institutions:e.institutionsFilter,investments:e.investmentsFilter})},y=function(){return f.addon.request({method:"GET",endpoint:"preferences/addons/passiv/passiv-lite"}).then((function(e){return t=e.data,JSON.parse(atob(t));var t}))},b=function(e){return function(e,t,n){var r=new URL(e);return t&&(r.search=new URLSearchParams(t).toString()),fetch(r.toString(),n).then((function(e){return e.json()}))}("https://getpassiv.com/api/v1/embeddedTrades",void 0,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(e)})},h={margin:8},v={display:"flex",flexDirection:"row",justifyContent:"space-around"},O=function(e,t){var n="cad"===t?".TO":"";return"".concat(e.symbol).concat(n)},j=function(e,t){return e.reduce((function(e,n){var r;return e+n.quantity*((null===(r=t.find((function(e){return e.symbol===O(n.security,n.security.currency)})))||void 0===r?void 0:r.price)||0)}),0)},g=function(e,t){var n;return(null===(n=e.find((function(e){return O(e.security,e.security.currency)===t.symbol})))||void 0===n?void 0:n.quantity)||0},S=function(e,t,n){var r=g(t,e),a=n.find((function(t){return t.symbol===e.symbol}));return Math.round(100*(100*e.percentOfPortfolio-Math.round(function(e,t){return Math.round(e*t*100)/100}(r,(null===a||void 0===a?void 0:a.price)||0)/j(t,n)*100*100)/100))/100},w=function(e){var t=g(e.positions,e.component),n=e.actions.find((function(t){return t.symbol===e.component.symbol})),r=0,c=0,l=0,u=0;return n&&(r=n.units,"SELL"===n.action&&(r*=-1),l=Math.round(t*n.price*100)/100,c=Math.round((t+r)*n.price*100)/100,u=j(e.positions,e.actions)),a.a.createElement("tr",null,a.a.createElement("td",null,e.component.symbol),a.a.createElement("td",null,(null===n||void 0===n?void 0:n.price)||"-"),a.a.createElement("td",null,"".concat(Math.round(l/u*100*100)/100,"%")),a.a.createElement("td",null,"".concat(100*e.component.percentOfPortfolio,"%")),a.a.createElement("td",null,t),a.a.createElement("td",null,l),a.a.createElement("td",null,(null===n||void 0===n?void 0:n.action)||""),a.a.createElement("td",null,r||""),a.a.createElement("td",null,t+r),a.a.createElement("td",null,n?c:"-"),a.a.createElement("td",null,"".concat(S(e.component,e.positions,e.actions),"%")))},k=function(){var e=Object(r.useState)(!1),t=Object(d.a)(e,2),n=t[0],c=t[1],l=Object(r.useState)(!1),u=Object(d.a)(l,2),j=u[0],g=u[1],k=Object(r.useState)(!1),F=Object(d.a)(k,2),x=F[0],M=F[1],P=Object(r.useState)(),C=Object(d.a)(P,2),B=C[0],T=C[1],q=Object(r.useState)(),A=Object(d.a)(q,2),L=A[0],N=A[1],J=Object(r.useState)(),Q=Object(d.a)(J,2),D=Q[0],I=Q[1],R=Object(r.useState)([]),U=Object(d.a)(R,2),V=U[0],W=U[1],G=Object(r.useState)([]),$=Object(d.a)(G,2),_=$[0],z=$[1],H=Object(r.useState)([]),K=Object(d.a)(H,2),X=K[0],Y=K[1],Z=Object.keys(_.flatMap((function(e){return e.investments})).map((function(e){return e.currency})).reduce((function(e,t){return Object(m.a)({},e,Object(s.a)({},t,1))}),{})),ee=B?Z.map((function(e){return function(e,t){return{currency:e,amount:_.flatMap((function(t){return t.investments.filter((function(t){return t.currency===e}))})).filter((function(e){return!t.groupsFilter||t.groupsFilter.split(",").some((function(t){return e.groups.includes(t)}))})).reduce((function(e,t){return e+t.cash}),0)}}(e,B)})):[];Object(r.useEffect)((function(){n||(c(!0),f.addon.on("init",(function(e){T(e)})),f.addon.on("update",(function(e){T((function(t){return Object(m.a)({},t,{},e)}))})))}),[n]),Object(r.useEffect)((function(){(function(){var e=Object(i.a)(o.a.mark((function e(){var t,n,r;return o.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!B){e.next=13;break}return e.next=3,p(B);case 3:return t=e.sent,W(t),e.next=7,y();case 7:return n=e.sent,N(n),e.next=11,E(B);case 11:r=e.sent,z(r);case 13:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}})()()}),[B]);var te=function(){var e=Object(i.a)(o.a.mark((function e(t){var n;return o.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return M(!0),e.next=3,b({buy_only:j,positions:V.map((function(e){return{symbol:O(e.security,e.security.currency),units:e.quantity}})),targets:t.components.map((function(e){return{symbol:e.symbol,percent:100*e.percentOfPortfolio}})),balances:ee});case 3:n=e.sent,Y(n),I(t),M(!1);case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}();return a.a.createElement("div",{className:"App"},a.a.createElement("h1",null,"Cash Balance"),a.a.createElement("table",null,a.a.createElement("tr",null,a.a.createElement("th",null,"Currency"),a.a.createElement("th",null,"Balance")),ee.map((function(e){return a.a.createElement("tr",null,a.a.createElement("td",null,e.currency),a.a.createElement("td",null,e.amount))}))),a.a.createElement("div",{style:v},a.a.createElement("div",null,a.a.createElement("h1",null,"Positions:"),a.a.createElement("table",null,a.a.createElement("tr",null,a.a.createElement("th",null,"Symbol"),a.a.createElement("th",null,"Quantity")),V.map((function(e){return a.a.createElement("tr",null,a.a.createElement("td",null,O(e.security,e.security.currency)),a.a.createElement("td",null,e.quantity))})))),a.a.createElement("div",null,a.a.createElement("h1",null,"Select a Passiv portfolio configuration to calculate:"),a.a.createElement("div",null,L&&a.a.createElement(a.a.Fragment,null,a.a.createElement("span",null,"Buy only"),a.a.createElement("input",{type:"checkbox",checked:j,onClick:function(){return g(!j)}}),L.portfolios.map((function(e){return a.a.createElement("button",{disabled:x,onClick:function(){return te(e)},style:h},e.portfolioName)})))),x&&a.a.createElement("h2",null,"Loading..."),D&&V&&a.a.createElement(a.a.Fragment,null,a.a.createElement("h1",null,D.portfolioName),a.a.createElement("table",null,a.a.createElement("tr",null,a.a.createElement("th",null,"Symbol"),a.a.createElement("th",null,"Price"),a.a.createElement("th",null,"Actual"),a.a.createElement("th",null,"Target"),a.a.createElement("th",null,"Current Quantity"),a.a.createElement("th",null,"Current Value"),a.a.createElement("th",null,"Action"),a.a.createElement("th",null,"Buy/Sell"),a.a.createElement("th",null,"Final Quantity"),a.a.createElement("th",null,"Final Value"),a.a.createElement("th",null,"Delta")),D.components.sort((function(e,t){return S(e,V,X)-S(t,V,X)})).map((function(e){return a.a.createElement(w,{component:e,positions:V,actions:X})})))))))};Boolean("localhost"===window.location.hostname||"[::1]"===window.location.hostname||window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));l.a.render(a.a.createElement(a.a.StrictMode,null,a.a.createElement(k,null)),document.getElementById("root")),"serviceWorker"in navigator&&navigator.serviceWorker.ready.then((function(e){e.unregister()})).catch((function(e){console.error(e.message)}))},8:function(e,t,n){e.exports=n(16)}},[[8,1,2]]]);
  //# sourceMappingURL=main.24b56c5f.chunk.js.map