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

Minor surplus fixes #468

Merged
merged 7 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start": "node .",
"test": "npx hardhat test --network testnetwork --config local.hardhat.config.ts",
"lint": "eslint --ext \".js,.ts\" --ignore-path .gitignore . --max-warnings=0",
"hardhat:silent": "npx hardhat node 1>&/dev/null",
"hardhat:silent": "npx hardhat node &> /dev/null",
"hardhat": "npx hardhat node",
"hardhat:simulations": "npx hardhat --network testnetwork --config local.hardhat.config.ts run ./simulations/index.ts",
"simulate": "npm-run-all --parallel hardhat:silent hardhat:simulations"
Expand Down
5 changes: 4 additions & 1 deletion core/src/surplus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,14 @@ export const enrichSurplusAuction = async (
network: string,
auction: SurplusAuctionActive
): Promise<SurplusAuctionTransaction> => {
const nextMinimumBid = await getNextMinimumBid(network, auction);
let nextMinimumBid = await getNextMinimumBid(network, auction);
const unitPrice = auction.bidAmountMKR.div(auction.receiveAmountDAI);
const marketUnitPrice = await getMarketPriceMkr(network, auction.bidAmountMKR);
const marketUnitPriceToUnitPriceRatio = unitPrice.minus(marketUnitPrice).dividedBy(marketUnitPrice);
const fees = await getSurplusTransactionFees(network);
if (nextMinimumBid.isZero()) {
nextMinimumBid = new BigNumber(1000).plus(fees.combinedBidFeesDai).div(marketUnitPrice);
}
return {
...auction,
...fees,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="flex justify-between">
<div>Auction State</div>
<div>
<time-till :date="auction.auctionEndDate" />
<SurplusAuctionState :state="auction.state" :end-date="auction.earliestEndDate" />
</div>
</div>
<div class="flex justify-between">
Expand Down Expand Up @@ -82,22 +82,22 @@
</template>

<script lang="ts">
import type { SurplusAuction } from 'auctions-core/src/types';
import Vue from 'vue';
import BigNumber from 'bignumber.js';
import BidInput from '../../common/inputs/BidInput.vue';
import TimeTill from '~/components/common/formatters/TimeTill.vue';
import type { SurplusAuctionTransaction } from 'auctions-core/src/types';
import SurplusAuctionState from '~/components/auction/surplus/SurplusAuctionState.vue';
import BidInput from '~/components/common/inputs/BidInput.vue';
import FormatCurrency from '~/components/common/formatters/FormatCurrency.vue';

export default Vue.extend({
components: {
TimeTill,
SurplusAuctionState,
FormatCurrency,
BidInput,
},
props: {
auction: {
type: Object as Vue.PropType<SurplusAuction>,
type: Object as Vue.PropType<SurplusAuctionTransaction>,
required: true,
},
},
Expand Down
22 changes: 22 additions & 0 deletions frontend/components/auction/surplus/SurplusAuctionState.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { storiesOf } from '@storybook/vue';
import faker from 'faker';
import SurplusAuctionState from './SurplusAuctionState';

const common = {
components: { SurplusAuctionState },
data: () => ({
state: faker.helpers.randomize([
'just-started',
'have-bids',
'ready-for-collection',
'requires-restart',
'collected',
]),
endDate: new Date(faker.date.recent()),
}),
};

storiesOf('Auction/Surplus/SurplusAuctionState', module).add('Default', () => ({
...common,
template: '<SurplusAuctionState :state="state" :end-date="endDate" />',
}));
32 changes: 32 additions & 0 deletions frontend/components/auction/surplus/SurplusAuctionState.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<div>
<span v-if="state === 'collected'"> Collected </span>
<span v-else-if="state === 'requires-restart'"> Requires Restart </span>
<span v-else-if="state === 'ready-for-collection'"> Collectable since </span>
<span v-else> Expires in </span>
<TimeTill v-if="state !== 'requires-restart'" :date="endDate" />
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import { SurplusAuctionStates } from 'auctions-core/src/types';
import TimeTill from '~/components/common/formatters/TimeTill.vue';

export default Vue.extend({
name: 'SurplusAuctionState',
components: {
TimeTill,
},
props: {
state: {
type: String as Vue.PropType<SurplusAuctionStates>,
required: true,
},
endDate: {
type: [String, Number, Date],
default: '',
},
},
});
</script>
12 changes: 5 additions & 7 deletions frontend/components/auction/surplus/SurplusAuctionsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@
<span v-else class="opacity-50">Unknown</span>
</div>
<div slot="state" slot-scope="state, record">
<span v-if="state === 'collected'"> Collected </span>
<span v-else-if="state === 'requires-restart'"> Requires Restart </span>
<span v-else-if="state === 'ready-for-collection'"> Collectable since </span>
<span v-else> Expires in </span>
<time-till v-if="state !== 'requires-restart'" :date="record.earliestEndDate" />
<SurplusAuctionState :state="state" :end-date="record.earliestEndDate" />
</div>
<div slot="updatingStatus" class="opacity-50 font-normal">
<div v-if="isLoading" class="flex items-center space-x-2">
Expand Down Expand Up @@ -76,13 +72,14 @@
<script lang="ts">
import Vue, { PropType } from 'vue';
import { Table } from 'ant-design-vue';
import { SurplusAuctionTransaction } from 'auctions-core/src/types';
import { compareAsc } from 'date-fns';
import { SurplusAuctionTransaction } from 'auctions-core/src/types';
import LoadingIcon from '~/assets/icons/loading.svg';
import SurplusAuctionState from '~/components/auction/surplus/SurplusAuctionState.vue';
import Loading from '~/components/common/other/Loading.vue';
import TimeTill from '~/components/common/formatters/TimeTill.vue';
import FormatMarketValue from '~/components/common/formatters/FormatMarketValue.vue';
import FormatCurrency from '~/components/common/formatters/FormatCurrency.vue';
import LoadingIcon from '~/assets/icons/loading.svg';

const compareBy = function (field: string, cmp: Function = (a: number, b: number): number => a - b): Function {
return (aAuction: any, bAuction: any, sortOrder: string) => {
Expand Down Expand Up @@ -145,6 +142,7 @@ const STATES_FILTERS: { text: string; value: string }[] = [
export default Vue.extend({
name: 'SurplusAuctionsTable',
components: {
SurplusAuctionState,
Loading,
Table,
TimeTill,
Expand Down