added rates to currencies

This commit is contained in:
FIRST_NAME LAST_NAME 2025-01-22 21:50:35 +03:00
parent 27b37d8b58
commit e41509fc2a

View File

@ -14,6 +14,7 @@
let currenciesFilter = "-1"; let currenciesFilter = "-1";
let showCurrenciesLoading = false; let showCurrenciesLoading = false;
let currencies = []; let currencies = [];
let rates = {};
async function getCurrencies() { async function getCurrencies() {
showCurrenciesLoading = true; showCurrenciesLoading = true;
const res = await makePost( const res = await makePost(
@ -21,11 +22,9 @@
{ {
page: currenciesCurrentPage, page: currenciesCurrentPage,
status: status:
Number(currenciesFilter) > -1 Number(currenciesFilter) > -1 ? Number(currenciesFilter) : undefined,
? Number(currenciesFilter)
: undefined,
}, },
makeAuthHeaderForAxios(getAuthInfo()?.a), makeAuthHeaderForAxios(getAuthInfo()?.a)
); );
// console.log(res); // console.log(res);
if (res.error) { if (res.error) {
@ -38,7 +37,7 @@
? Number(currenciesFilter) ? Number(currenciesFilter)
: undefined, : undefined,
}, },
"- ERROR", "- ERROR"
); );
showCurrenciesLoading = false; showCurrenciesLoading = false;
return; return;
@ -46,6 +45,7 @@
currencies = res.data.data ?? []; currencies = res.data.data ?? [];
currenciesMaxPage = Number(res.data.pages); currenciesMaxPage = Number(res.data.pages);
showCurrenciesLoading = false; showCurrenciesLoading = false;
rates = res.data["rates"];
} }
if (browser) { if (browser) {
@ -73,14 +73,17 @@
} }
showChangeCurrencyLoading = true; showChangeCurrencyLoading = true;
const res = await makePost("admin/updateCurrency", { const res = await makePost(
"admin/updateCurrency",
{
bank: newBankValue.length >= 1 ? newBankValue : undefined, bank: newBankValue.length >= 1 ? newBankValue : undefined,
volume: newVolumeValue.length > 1 ? newVolumeValue : undefined, volume: newVolumeValue.length > 1 ? newVolumeValue : undefined,
code: selectedCurrency['code'] code: selectedCurrency["code"],
}, makeAuthHeaderForAxios(getAuthInfo()?.a)); },
makeAuthHeaderForAxios(getAuthInfo()?.a)
);
if(res.error) if (res.error) {
{
sayError("Не удалось обновить валюту"); sayError("Не удалось обновить валюту");
showChangeCurrencyLoading = false; showChangeCurrencyLoading = false;
return; return;
@ -99,9 +102,7 @@
<div class="bg-accent rounded-[4px] w-[10px] h-full"></div> <div class="bg-accent rounded-[4px] w-[10px] h-full"></div>
<h1 class="text-2xl font-semibold">Валюты</h1> <h1 class="text-2xl font-semibold">Валюты</h1>
</div> </div>
<div <div class="flex w-full flex-col bg-base-300 p-4 rounded-box overflow-x-auto">
class="flex w-full flex-col bg-base-300 p-4 rounded-box overflow-x-auto"
>
<div class="flex justify-center items-center p-4"> <div class="flex justify-center items-center p-4">
<Pagination <Pagination
pageChangedCallback={(n) => { pageChangedCallback={(n) => {
@ -114,10 +115,7 @@
/> />
</div> </div>
<div class="flex justify-center items-center p-2"> <div class="flex justify-center items-center p-2">
<select <select bind:value={currenciesFilter} class="select select-bordered">
bind:value={currenciesFilter}
class="select select-bordered"
>
<option value="-1">Все</option> <option value="-1">Все</option>
<option value="0">Активные</option> <option value="0">Активные</option>
<option value="1">Неактивные</option> <option value="1">Неактивные</option>
@ -135,6 +133,7 @@
<th>Статус</th> <th>Статус</th>
<th>Minor Units</th> <th>Minor Units</th>
<th>Приоритетный банк (Bybit)</th> <th>Приоритетный банк (Bybit)</th>
<th>Курс</th>
<th>Объем</th> <th>Объем</th>
<th>ID</th> <th>ID</th>
<th></th> <th></th>
@ -147,15 +146,12 @@
<td>{cur["num"]}</td> <td>{cur["num"]}</td>
<td>{cur["country"]}</td> <td>{cur["country"]}</td>
<td <td
class={cur["is_active"] === "t" class={cur["is_active"] === "t" ? "text-success" : "text-error"}
? "text-success" >{cur["is_active"] === "t" ? "Активна" : "Неактивна"}</td
: "text-error"}
>{cur["is_active"] === "t"
? "Активна"
: "Неактивна"}</td
> >
<td>{cur["minor_unit"]}</td> <td>{cur["minor_unit"]}</td>
<td>{cur["priority_bank_bybit"]}</td> <td>{cur["priority_bank_bybit"]}</td>
<td>{rates[cur["code"]] ?? ""}</td>
<td>{cur["volume"]}</td> <td>{cur["volume"]}</td>
<td>{cur["id"]}</td> <td>{cur["id"]}</td>
<td> <td>
@ -194,9 +190,12 @@
class="input input-bordered" class="input input-bordered"
/> />
<button on:click={()=>{ <button
on:click={() => {
changeCurrency(); changeCurrency();
}} class="btn btn-outline btn-success mt-4"> }}
class="btn btn-outline btn-success mt-4"
>
Сохранить Сохранить
</button> </button>
<button <button