Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added TFTPrice component. #381

Merged
merged 2 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/dashboard/src/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
>Threefold Chain</v-toolbar-title
>

<v-spacer></v-spacer>
<v-spacer>
<TftSwapPrice v-if="!loadingAPI" />
</v-spacer>
<div class="d-flex">
<FundsCard v-if="$store.state.credentials.initialized && $store.state.credentials.balance" />
<div class="d-flex" style="align-items: center">
Expand Down Expand Up @@ -194,6 +196,7 @@ import { Component, Vue } from "vue-property-decorator";
import config from "@/portal/config";

import FundsCard from "./portal/components/FundsCard.vue";
import TftSwapPrice from "./portal/components/TftSwapPrice.vue";
import WelcomeWindow from "./portal/components/WelcomeWindow.vue";
import { connect } from "./portal/lib/connect";
import { accountInterface } from "./portal/store/state";
Expand Down Expand Up @@ -222,7 +225,7 @@ interface SidenavItem {

@Component({
name: "Dashboard",
components: { WelcomeWindow, FundsCard },
components: { WelcomeWindow, FundsCard, TftSwapPrice },
})
export default class Dashboard extends Vue {
collapseOnScroll = true;
Expand Down
64 changes: 64 additions & 0 deletions packages/dashboard/src/portal/components/TftSwapPrice.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<template>
<v-container>
<div class="d-flex ml-5">
<div class="d-flex" style="align-items: center">
<p>{{ prices[0].amount }} {{ prices[0].currency }}</p>
<v-tooltip>
<template v-slot:activator="{ on, attrs }">
<v-btn @click="priceSwap" icon v-bind="attrs" v-on="on" class="d-flex align-center">
<v-icon>mdi-swap-horizontal</v-icon>
</v-btn>
</template>
<span>ThreeFold Price Swapping</span>
</v-tooltip>
<p>{{ prices[1].amount }} {{ prices[1].currency }}</p>
</div>
</div>
</v-container>
</template>
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";

type SwapPrice = {
currency: string;
amount: number;
};

@Component({
name: "TftSwapPrice",
})
export default class FundsCard extends Vue {
Mahmoud-Emad marked this conversation as resolved.
Show resolved Hide resolved
$api: any;
swaped = false;
prices: SwapPrice[] = [
{ currency: "TFT", amount: 1 },
{ currency: "USD", amount: 0 },
];

async mounted() {
this.prices[1].amount = await this.getTFTPrice();
}

async priceSwap() {
// Changing the values from TFT to USD and vice versa on click.
this.swaped = !this.swaped;
if (this.swaped) {
this.prices = [
{ currency: "USD", amount: 1 },
{ currency: "TFT", amount: Math.floor((1 / (await this.getTFTPrice())) * 1000) / 1000 },
];
} else {
this.prices = [
{ currency: "TFT", amount: 1 },
{ currency: "USD", amount: await this.getTFTPrice() },
];
}
}

async getTFTPrice() {
// Getting the TFT price from the substrate.
const res = await this.$api.query.tftPriceModule.tftPrice();
return res.toPrimitive() / 1000;
}
}
</script>