frequi_origin/src/components/ftbot/BotBalance.vue

86 lines
2.7 KiB
Vue
Raw Normal View History

2020-05-14 05:15:18 +00:00
<template>
2020-05-22 18:04:27 +00:00
<div>
<div class="mb-2">
2022-10-30 13:26:23 +00:00
<label class="me-auto h3">Balance</label>
2022-12-24 09:53:01 +00:00
<div class="float-end d-flex flex-row">
<b-button
size="sm"
title="Hide small balances"
@click="hideSmallBalances = !hideSmallBalances"
>
<HideIcon v-if="hideSmallBalances" :size="16" />
<ShowIcon v-else :size="16" />
</b-button>
<b-button class="float-end" size="sm" @click="botStore.activeBot.getBalance"
>&#x21bb;</b-button
>
</div>
</div>
2022-01-24 18:47:33 +00:00
<BalanceChart v-if="balanceCurrencies" :currencies="balanceCurrencies" />
2020-05-22 18:04:27 +00:00
<div>
<p v-if="botStore.activeBot.balance.note">
<strong>{{ botStore.activeBot.balance.note }}</strong>
2020-05-14 05:22:27 +00:00
</p>
<b-table class="table-sm" :items="balanceCurrencies" :fields="tableFields">
2022-12-17 14:03:04 +00:00
<template #custom-foot>
2020-05-14 05:16:07 +00:00
<td><strong>Total</strong></td>
<td>
<span
class="font-italic"
:title="`Increase over initial capital of ${formatCurrency(
botStore.activeBot.balance.starting_capital,
)} ${botStore.activeBot.balance.stake}`"
>{{ formatPercent(botStore.activeBot.balance.starting_capital_ratio) }}</span
>
</td>
2020-05-14 05:15:18 +00:00
<!-- this is a computed prop that adds up all the expenses in the visible rows -->
2020-05-14 05:16:07 +00:00
<td>
<strong>{{ formatCurrency(botStore.activeBot.balance.total) }}</strong>
2020-05-14 05:16:07 +00:00
</td>
2020-05-14 05:15:18 +00:00
</template>
</b-table>
</div>
</div>
</template>
2023-03-18 16:14:14 +00:00
<script setup lang="ts">
import HideIcon from 'vue-material-design-icons/EyeOff.vue';
import ShowIcon from 'vue-material-design-icons/Eye.vue';
2021-12-19 19:06:25 +00:00
import BalanceChart from '@/components/charts/BalanceChart.vue';
2023-03-18 16:47:23 +00:00
import { formatPercent, formatPrice } from '@/shared/formatters';
2023-03-18 16:14:14 +00:00
import { computed, ref } from 'vue';
import { useBotStore } from '@/stores/ftbotwrapper';
2020-08-09 13:07:09 +00:00
2023-03-18 16:14:14 +00:00
const botStore = useBotStore();
const hideSmallBalances = ref(true);
2020-08-09 13:07:09 +00:00
2023-03-18 16:14:14 +00:00
const smallBalance = computed((): number => {
return Number((0.1 ** botStore.activeBot.stakeCurrencyDecimals).toFixed(8));
});
2023-03-18 16:14:14 +00:00
const balanceCurrencies = computed(() => {
if (!hideSmallBalances.value) {
return botStore.activeBot.balance.currencies;
}
2023-03-18 16:14:14 +00:00
return botStore.activeBot.balance.currencies?.filter((v) => v.est_stake >= smallBalance.value);
});
2023-03-18 16:14:14 +00:00
const formatCurrency = (value) => {
2023-03-18 16:47:23 +00:00
return value ? formatPrice(value, 5) : '';
2023-03-18 16:14:14 +00:00
};
2023-03-18 16:14:14 +00:00
const tableFields = computed(() => {
return [
{ key: 'currency', label: 'Currency' },
{ key: 'free', label: 'Available', formatter: formatCurrency },
{
key: 'est_stake',
label: `in ${botStore.activeBot.balance.stake}`,
formatter: formatCurrency,
},
];
2022-04-15 18:02:27 +00:00
});
2020-05-14 05:15:18 +00:00
</script>