|
@@ -13,6 +13,7 @@
|
|
|
let showModal = false;
|
|
let showModal = false;
|
|
|
let searchStockResult = [];
|
|
let searchStockResult = [];
|
|
|
let orderBy = 'total';
|
|
let orderBy = 'total';
|
|
|
|
|
+ let currency = 'USD';
|
|
|
let hasChanges = false;
|
|
let hasChanges = false;
|
|
|
|
|
|
|
|
onMount(() => {
|
|
onMount(() => {
|
|
@@ -28,7 +29,7 @@
|
|
|
|
|
|
|
|
async function fetchPortfolio() {
|
|
async function fetchPortfolio() {
|
|
|
try {
|
|
try {
|
|
|
- const response = await fetch(`${import.meta.env.VITE_STOCKS_HOST}/api/portfolios`, {
|
|
|
|
|
|
|
+ const response = await fetch(`${import.meta.env.VITE_STOCKS_HOST}/api/portfolios?currency=${currency}`, {
|
|
|
method: 'GET',
|
|
method: 'GET',
|
|
|
headers: {
|
|
headers: {
|
|
|
Authorization: 'Bearer ' + authToken
|
|
Authorization: 'Bearer ' + authToken
|
|
@@ -173,7 +174,7 @@
|
|
|
function formatCurrency(value) {
|
|
function formatCurrency(value) {
|
|
|
return value.toLocaleString('en-US', {
|
|
return value.toLocaleString('en-US', {
|
|
|
style: 'currency',
|
|
style: 'currency',
|
|
|
- currency: 'USD'
|
|
|
|
|
|
|
+ currency: currency
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -207,6 +208,11 @@
|
|
|
fetchPortfolio();
|
|
fetchPortfolio();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function updateCurrency(event) {
|
|
|
|
|
+ currency = event.target.value;
|
|
|
|
|
+ fetchPortfolio()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function handleInputChange(event) {
|
|
function handleInputChange(event) {
|
|
|
const form = new FormData(event.target.closest('form'));
|
|
const form = new FormData(event.target.closest('form'));
|
|
|
const code = form.get('code');
|
|
const code = form.get('code');
|
|
@@ -235,7 +241,12 @@
|
|
|
Add
|
|
Add
|
|
|
</button>
|
|
</button>
|
|
|
|
|
|
|
|
- <!-- Dropdown for ordering the list -->
|
|
|
|
|
|
|
+ <select class="form-control order-select" on:change={updateCurrency}>
|
|
|
|
|
+ <option value="brl">BRL</option>
|
|
|
|
|
+ <option value="eur">EURO</option>
|
|
|
|
|
+ <option value="usd" selected>USD</option>
|
|
|
|
|
+ </select>
|
|
|
|
|
+
|
|
|
<select class="form-control order-select" on:change={updateOrderBy}>
|
|
<select class="form-control order-select" on:change={updateOrderBy}>
|
|
|
<option value="code">Order by Code</option>
|
|
<option value="code">Order by Code</option>
|
|
|
<option value="name">Order by Name</option>
|
|
<option value="name">Order by Name</option>
|