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

Mark off-boarded collaterals on the dashboard #595

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 9 additions & 2 deletions frontend/components/dashboard/CollateralTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<CurrencyIcon :currency-symbol="record.symbol" />
</div>
<div slot="ilk" slot-scope="ilk" class="Element">
{{ ilk }}
{{ ilk }} <span v-if="isCollateralOffboarded(ilk)" class="opacity-50">&nbsp;(off-boarded)</span>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we might just use a separate column for that with off-boarded/active label

</div>
<div slot="symbol" slot-scope="symbol" class="Element">{{ symbol }}</div>
<div slot="token" slot-scope="tokenAddress, record" class="Element" :class="{ Loading: isLoading(record) }">
Expand Down Expand Up @@ -103,10 +103,10 @@
</template>

<script lang="ts">
import type { CollateralRow } from 'auctions-core/src/types';
import Vue from 'vue';
import BigNumber from 'bignumber.js';
import { Table, Popover } from 'ant-design-vue';
import type { CollateralRow } from 'auctions-core/src/types';
import CurrencyIcon from '~/components/common/other/CurrencyIcon.vue';
import FormatCurrency from '~/components/common/formatters/FormatCurrency.vue';
import FormatAddress from '~/components/common/formatters/FormatAddress.vue';
Expand All @@ -126,6 +126,10 @@ export default Vue.extend({
type: Array as Vue.PropType<CollateralRow[]>,
default: () => [],
},
offBoardedCollaterals: {
type: Array as Vue.PropType<string[]>,
default: () => [],
},
},
computed: {
collateralAmount() {
Expand Down Expand Up @@ -191,6 +195,9 @@ export default Vue.extend({
isValidBigNumber(bigNumber: BigNumber) {
return BigNumber.isBigNumber(bigNumber);
},
isCollateralOffboarded(collateralType: string) {
return this.offBoardedCollaterals.includes(collateralType);
},
},
});
</script>
Expand Down
10 changes: 9 additions & 1 deletion frontend/components/dashboard/DashboardAuctionsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
</TextBlock>
</div>
<div class="Block max-w-screen-xl">
<CollateralTable :collaterals="collaterals" class="overflow-x-auto" />
<CollateralTable
:collaterals="collaterals"
:off-boarded-collaterals="offBoardedCollaterals"
class="overflow-x-auto"
/>
</div>
<div class="Block space-y-4 md:space-y-8 max-w-screen-sm">
<TextBlock v-if="isExplanationsShown" title="Exchange Callee Contracts">
Expand Down Expand Up @@ -67,6 +71,10 @@ export default Vue.extend({
type: Array as Vue.PropType<CollateralRow[]>,
default: () => [],
},
offBoardedCollaterals: {
type: Array as Vue.PropType<string[]>,
default: () => [],
},
callees: {
type: Object as Vue.PropType<CalleeAddresses>,
default: () => ({}),
Expand Down
21 changes: 21 additions & 0 deletions frontend/containers/DashboardContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div class="DashboardContainer">
<DashboardAuctionsView
:collaterals="collaterals"
:off-boarded-collaterals="offBoardedCollaterals"
:callees="callees"
:base-fee-per-gas="baseFeePerGas"
:gas-parameters="gasParameters"
Expand All @@ -14,13 +15,19 @@
<script lang="ts">
import Vue from 'vue';
import { mapGetters } from 'vuex';
import type { CollateralRow } from 'auctions-core/src/types';
import { getCalleesByNetworkType } from 'auctions-core/src/constants/CALLEES';
import DashboardAuctionsView from '~/components/dashboard/DashboardAuctionsView.vue';

export default Vue.extend({
components: {
DashboardAuctionsView,
},
data() {
return {
offBoardedCollaterals: [],
};
},
computed: {
...mapGetters('collaterals', {
collaterals: 'collaterals',
Expand Down Expand Up @@ -56,6 +63,20 @@ export default Vue.extend({
this.$store.dispatch('collaterals/setup');
}
},
collaterals: {
handler(newCollaterals: CollateralRow[]) {
if (newCollaterals) {
newCollaterals.forEach(async collateral => {
if (await this.$store.dispatch('collaterals/isCollateralOffboarded', collateral.ilk)) {
if (!this.offBoardedCollaterals.includes(collateral.ilk)) {
this.offBoardedCollaterals.push(collateral.ilk);
}
}
});
}
},
immediate: true,
},
},
});
</script>
Expand Down
18 changes: 18 additions & 0 deletions frontend/store/collaterals.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Vue from 'vue';
import { ActionContext } from 'vuex';
import { ethers } from 'ethers';
import type { CollateralRow, CollateralStatus } from 'auctions-core/src/types';
import COLLATERALS, {
getAllCollateralTypes,
Expand All @@ -10,6 +11,7 @@ import { fetchCalcParametersByCollateralType } from 'auctions-core/src/params';
import { getTokenAddressByNetworkAndSymbol } from 'auctions-core/src/tokens';
import { isCollateralTypeSupported } from 'auctions-core/src/addresses';
import { fetchAutoRouteInformation } from 'auctions-core/src/calleeFunctions/helpers/uniswapAutoRouter';
import { getContractValue } from 'auctions-core/src/contracts';

interface State {
collaterals: CollateralRow[];
Expand Down Expand Up @@ -162,6 +164,22 @@ export const actions = {
});
}
},
async isCollateralOffboarded(
{ rootGetters }: ActionContext<State, State>,
collateralType: string
): Promise<boolean> {
const network = rootGetters['network/getMakerNetwork'];
if (!network) {
return false;
}
const typeHex = ethers.utils.formatBytes32String(collateralType);
const maxCollateralDebt = await getContractValue(network, 'MCD_VAT', 'ilks', {
parameters: [typeHex],
variableName: 'line',
decimalUnits: 'RAD',
});
return maxCollateralDebt.isZero();
},
Comment on lines +167 to +182
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Please move this function to the appropriate place in the core
  • Then, please just call isCollateralOffboarded inside existing fetchCollateralStatus action to add the values to the type
  • Then, you no longer need to pass any other new props to the dashboard, and can just use existing status.isOffboarded to display the appropriate label

Do you see any problems with this suggestion or why did you have to introduce all those new props and extra types like offBoardedCollaterals array?

async setup({ commit, dispatch }: ActionContext<State, State>) {
commit('reset');

Expand Down