|
| 1 | +<template> |
| 2 | + <TextBlock> |
| 3 | + <TextBlock v-if="isExplanationsShown" class="mb-2"> |
| 4 | + This is a list of collaterals supported by the Maker Protocol. Each row provides the possibility to |
| 5 | + withdraw collateral from the VAT (if there is any) and to pre-authorize VAT transactions. |
| 6 | + </TextBlock> |
| 7 | + <table class="Table"> |
| 8 | + <tr class="Heading"> |
| 9 | + <th>Collateral</th> |
| 10 | + <th>Token</th> |
| 11 | + <th>Authorization</th> |
| 12 | + <th>Balance</th> |
| 13 | + </tr> |
| 14 | + <tbody> |
| 15 | + <tr v-for="collateralStatus of sortedCollaterals" :key="collateralStatus.type" class="Body"> |
| 16 | + <td> |
| 17 | + <div class="flex items-center gap-2"> |
| 18 | + <CurrencyIcon :currency-symbol="collateralStatus.symbol" /> |
| 19 | + {{ collateralStatus.type }} |
| 20 | + </div> |
| 21 | + </td> |
| 22 | + <td> |
| 23 | + <span v-if="collateralStatus.address === undefined" class="opacity-50">Fetching</span> |
| 24 | + <span v-else-if="collateralStatus.address === null" class="opacity-50">Not found</span> |
| 25 | + <format-address v-else :value="collateralStatus.address" shorten type="address" /> |
| 26 | + </td> |
| 27 | + <td> |
| 28 | + <template v-if="collateralStatus.address"> |
| 29 | + <span v-if="collateralStatus.isAuthorized">Authorized</span> |
| 30 | + <BaseButton |
| 31 | + v-else |
| 32 | + class="w-full" |
| 33 | + :is-loading="collateralStatus.isAuthorizing" |
| 34 | + @click="$emit('authorizeCollateral', collateralStatus.type)" |
| 35 | + > |
| 36 | + Authorize |
| 37 | + </BaseButton> |
| 38 | + </template> |
| 39 | + </td> |
| 40 | + <td> |
| 41 | + <template v-if="collateralStatus.address"> |
| 42 | + <Tooltip :title="generateWithdrawalErrorMessage(collateralStatus)" placement="top"> |
| 43 | + <div> |
| 44 | + <BaseButton |
| 45 | + class="w-full" |
| 46 | + :disabled="!canWithdrawCollateral(collateralStatus)" |
| 47 | + :is-loading="collateralStatus.isDepositingOrWithdrawing" |
| 48 | + @click="$emit('withdrawCollateral', collateralStatus.type)" |
| 49 | + > |
| 50 | + <span class="mr-1">Withdraw</span |
| 51 | + ><format-currency :value="collateralStatus.balance" /> |
| 52 | + </BaseButton> |
| 53 | + </div> |
| 54 | + </Tooltip> |
| 55 | + </template> |
| 56 | + </td> |
| 57 | + </tr> |
| 58 | + </tbody> |
| 59 | + </table> |
| 60 | + </TextBlock> |
| 61 | +</template> |
| 62 | + |
| 63 | +<script lang="ts"> |
| 64 | +import type { CollateralStatus } from 'auction-core/src/types'; |
| 65 | +import Vue from 'vue'; |
| 66 | +import { Tooltip } from 'ant-design-vue'; |
| 67 | +import TextBlock from '~/components/common/TextBlock.vue'; |
| 68 | +import FormatAddress from '~/components/utils/FormatAddress.vue'; |
| 69 | +import FormatCurrency from '~/components/utils/FormatCurrency.vue'; |
| 70 | +import CurrencyIcon from '~/components/common/CurrencyIcon.vue'; |
| 71 | +import BaseButton from '~/components/common/BaseButton.vue'; |
| 72 | +
|
| 73 | +export default Vue.extend({ |
| 74 | + components: { |
| 75 | + Tooltip, |
| 76 | + TextBlock, |
| 77 | + FormatAddress, |
| 78 | + FormatCurrency, |
| 79 | + CurrencyIcon, |
| 80 | + BaseButton, |
| 81 | + }, |
| 82 | + props: { |
| 83 | + collateralStatuses: { |
| 84 | + type: Array as Vue.PropType<CollateralStatus[]>, |
| 85 | + default: () => [], |
| 86 | + }, |
| 87 | + isExplanationsShown: { |
| 88 | + type: Boolean, |
| 89 | + default: true, |
| 90 | + }, |
| 91 | + }, |
| 92 | + computed: { |
| 93 | + sortedCollaterals() { |
| 94 | + const statuses = this.collateralStatuses; |
| 95 | + return statuses.sort((firstCollateral: CollateralStatus, secondCollateral: CollateralStatus) => |
| 96 | + firstCollateral.type.localeCompare(secondCollateral.type) |
| 97 | + ); |
| 98 | + }, |
| 99 | + }, |
| 100 | + methods: { |
| 101 | + canWithdrawCollateral(collateral: CollateralStatus): boolean { |
| 102 | + return collateral.balance?.isGreaterThan(0) && collateral.isAuthorized; |
| 103 | + }, |
| 104 | + generateWithdrawalErrorMessage(collateral: CollateralStatus): string | undefined { |
| 105 | + if (!collateral.balance?.isGreaterThan(0)) { |
| 106 | + return `There is no ${collateral.type} collateral to withdraw`; |
| 107 | + } |
| 108 | + if (!collateral.isAuthorized) { |
| 109 | + return `The ${collateral.type} collateral needs to be authorized first`; |
| 110 | + } |
| 111 | + }, |
| 112 | + }, |
| 113 | +}); |
| 114 | +</script> |
| 115 | + |
| 116 | +<style scoped> |
| 117 | +.Table { |
| 118 | + @apply w-full border-2 border-gray-300 dark:border-gray-600 bg-transparent; |
| 119 | +} |
| 120 | +
|
| 121 | +.Element { |
| 122 | + @apply p-2 h-12 border-r-2 border-b-2 border-gray-300 dark:border-gray-600; |
| 123 | +} |
| 124 | +
|
| 125 | +.Heading > th { |
| 126 | + @apply Element text-gray-700 dark:text-gray-100; |
| 127 | +} |
| 128 | +
|
| 129 | +.Body > td { |
| 130 | + @apply Element text-gray-500 dark:text-gray-300; |
| 131 | +} |
| 132 | +</style> |
0 commit comments