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

Add multi-callee support to the frontend #498

Merged
merged 19 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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: 2 additions & 0 deletions core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export declare interface AuctionInitialInfo {
isFinished: boolean;
isRestarting: boolean;
marketUnitPrice?: BigNumber;
suggestedMarketId?: string;
marketData?: Record<string, any>;
aomafarag marked this conversation as resolved.
Show resolved Hide resolved
marketUnitPriceToUnitPriceRatio?: BigNumber;
transactionGrossProfit?: BigNumber;
transactionAddress?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
type="error"
/>
<Alert v-if="auctionTransaction.isFinished" message="This auction is finished" type="error" />
<CollateralAuctionSwapTransactionTable :auction-transaction="auctionTransaction" class="mt-4" />
<CollateralAuctionSwapTransactionTable
:auction-transaction="auctionTransaction"
:market-id.sync="marketId"
class="mt-4"
/>
<TextBlock class="TextBlock mt-4 mb-8">
Please note, the transaction fee is a suggested value based on the current gas prices on the market; the
Transaction Net Profit is also approximate, since it is extrapolated from the exchange rates and may change
Expand Down Expand Up @@ -84,7 +88,13 @@
:is-collateral-authed="isWalletCollateralAuthorizationCheckPassed"
:fees="fees"
:transaction-gross-profit="auctionTransaction.transactionGrossProfit"
@execute="$emit('execute', { id: auctionTransaction.id, alternativeDestinationAddress: $event })"
@execute="
$emit('execute', {
id: auctionTransaction.id,
marketId: marketSuggestionOrSelection,
alternativeDestinationAddress: $event,
})
"
/>
</div>
</template>
Expand Down Expand Up @@ -151,6 +161,7 @@ export default Vue.extend({
},
data() {
return {
marketId: '',
isWalletConnectedCheck: false,
isWalletDAIAuthorizationCheckPassed: false,
isWalletCollateralAuthorizationCheckPassed: false,
Expand All @@ -177,6 +188,9 @@ export default Vue.extend({
}
return fees;
},
marketSuggestionOrSelection(): string | undefined {
return this.marketId || this.auctionTransaction.suggestedMarketId;
},
},
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,7 @@
<span class="uppercase">{{ auctionTransaction.collateralSymbol }}</span>
</div>
</div>
<div class="flex w-full justify-between">
<div>Price On Uniswap</div>
<div class="RightInfo">
<template v-if="auctionTransaction.isActive && auctionTransaction.marketUnitPrice">
<FormatCurrency :value="auctionTransaction.marketUnitPrice" currency="DAI" /> per
<span class="uppercase">{{ auctionTransaction.collateralSymbol }}</span>
</template>
<span v-else class="opacity-50">Unknown</span>
</div>
</div>
<MarketPriceSelection :auction-transaction="auctionTransaction" :market-id.sync="marketId" />
Copy link
Contributor

Choose a reason for hiding this comment

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

As you raised in the issue and I answered: the values underneath this row is dependent on the selected marketId. They all now taken from the marketData[marketId] object: so that switching marketId displays new values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly. But the calculation of the market difference, profitability, etc. happens in the core. So, shouldn't that be implemented there by using the marketId that is sent to the store?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, nvm. For some reason, I've just noticed the comment you made last week 😅.

<div class="flex w-full justify-between">
<div>Market Difference</div>
<div class="RightInfo">
Expand Down Expand Up @@ -98,19 +89,21 @@
<script lang="ts">
import Vue from 'vue';
import PriceDropAnimation from '~/components/auction/collateral/PriceDropAnimation.vue';
import FormatCurrency from '~/components/common/formatters/FormatCurrency.vue';
import MarketPriceSelection from '~/components/auction/collateral/MarketPriceSelection.vue';
import TimeTillProfitable from '~/components/auction/collateral/TimeTillProfitable.vue';
import TimeTill from '~/components/common/formatters/TimeTill.vue';
import FormatCurrency from '~/components/common/formatters/FormatCurrency.vue';
import FormatMarketValue from '~/components/common/formatters/FormatMarketValue.vue';
import TextBlock from '~/components/common/other/TextBlock.vue';
import { AuctionTransaction } from '~/../core/src/types';

export default Vue.extend({
components: {
PriceDropAnimation,
FormatCurrency,
MarketPriceSelection,
TextBlock,
TimeTill,
FormatCurrency,
FormatMarketValue,
TimeTillProfitable,
},
Expand All @@ -119,6 +112,10 @@ export default Vue.extend({
type: Object as Vue.PropType<AuctionTransaction>,
required: true,
},
marketId: {
type: String,
default: '',
},
},
});
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { storiesOf } from '@storybook/vue';
import MarketPriceSelection from './MarketPriceSelection';
import { generateFakeAuctionTransaction } from '~/helpers/generateFakeAuction.ts';

const fakeAuctionTransaction = generateFakeAuctionTransaction();

const common = {
components: {
MarketPriceSelection,
},
data: () => ({
auctionTransaction: fakeAuctionTransaction,
marketId: '',
}),
template: `<MarketPriceSelection :auction-transaction="auctionTransaction" :market-id.sync="marketId" />`,
};

storiesOf('Auction/Collateral/MarketPriceSelection', module).add('Default', () => ({ ...common }));
99 changes: 99 additions & 0 deletions frontend/components/auction/collateral/MarketPriceSelection.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<template>
<div>
<div class="flex justify-between">
<button class="Title" type="button" @click="isExpanded = !isExpanded">
<Icon v-if="!isExpanded" type="caret-right" class="Icon" />
<Icon v-else type="caret-down" class="Icon" />
Market Unit Price
<span class="text-gray-300">({{ suggestionOrSelection }})</span>
</button>
<div v-show="!isExpanded">
<FormatCurrency :value="marketUnitPrice" currency="DAI" /> per
<span class="uppercase">{{ auctionTransaction.collateralSymbol }}</span>
</div>
</div>
<CollapseTransition>
<div v-show="isExpanded" class="Content overflow-x-auto">
<table class="table-auto">
<tbody>
<tr v-for="(value, key) in auctionTransaction.marketData" :key="key">
<td class="pr-2 whitespace-nowrap">{{ key }}</td>
<td class="pr-2 whitespace-nowrap">
<span v-for="currency in value.route" :key="currency">{{ currency }} &#8594; </span>
DAI
</td>
<td class="w-full text-right whitespace-nowrap">
<div v-if="value.unitPrice && !value.unitPrice.isNaN()">
<button type="button" @click="$emit('update:marketId', key)">
<span v-if="marketId === key" class="opacity-50">Selected</span>
<span v-else class="text-green-500">Select</span>
</button>
<span class="pl-1">
<FormatCurrency :value="value.unitPrice" currency="DAI" /> per
<span class="uppercase">{{ auctionTransaction.collateralSymbol }}</span>
</span>
</div>
<div v-else class="opacity-50">Unknown</div>
</td>
</tr>
</tbody>
</table>
</div>
</CollapseTransition>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import BigNumber from 'bignumber.js';
import { Icon } from 'ant-design-vue';
import CollapseTransition from '@ivanv/vue-collapse-transition';
import { AuctionTransaction } from 'auctions-core/src/types';
import FormatCurrency from '~/components/common/formatters/FormatCurrency.vue';

export default Vue.extend({
components: {
Icon,
FormatCurrency,
CollapseTransition,
},
props: {
auctionTransaction: {
type: Object as Vue.PropType<AuctionTransaction>,
required: true,
},
marketId: {
type: String,
default: '',
},
},
data() {
return {
isExpanded: false,
};
},
computed: {
suggestionOrSelection(): string | undefined {
return this.marketId || this.auctionTransaction.suggestedMarketId;
},
marketUnitPrice(): BigNumber | undefined {
if (this.auctionTransaction.marketData && this.suggestionOrSelection) {
return this.auctionTransaction.marketData[this.suggestionOrSelection].unitPrice;
}
return undefined;
},
},
});
</script>

<style scoped>
.Title {
@apply text-left text-green-500;
}
.Icon {
@apply inline;
}
.Content {
@apply pl-4;
}
</style>
4 changes: 3 additions & 1 deletion frontend/containers/AuctionsContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@

<script lang="ts">
import Vue from 'vue';
import BigNumber from 'bignumber.js';
import { mapGetters, mapActions } from 'vuex';
import CollateralAuctionFlow from '~/components/auction/collateral/CollateralAuctionFlow';
import { Auction } from 'auctions-core/src/types';
import CollateralAuctionFlow from '~/components/auction/collateral/CollateralAuctionFlow.vue';

export default Vue.extend({
components: {
Expand Down
21 changes: 21 additions & 0 deletions frontend/helpers/generateFakeAuction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ export const generateFakeAuction = function () {
const marketUnitPrice = approximateUnitPrice.multipliedBy(
new BigNumber(1).minus(marketUnitPriceToUnitPriceRatio || 0)
);
const suggestedMarketId = 'Uniswap v3';
const marketData = {
'Uniswap v3': {
unitPrice: marketUnitPrice.multipliedBy(
new BigNumber(faker.datatype.float({ min: 1.1, max: 1.5, precision: 0.001 }))
),
route: [collateralObject.symbol, 'USDC'],
},
'Uniswap v2': {
unitPrice: new BigNumber(NaN),
route: [collateralObject.symbol],
},
'1inch': {
unitPrice: marketUnitPrice.multipliedBy(
new BigNumber(faker.datatype.float({ min: 1.1, max: 1.5, precision: 0.001 }))
),
route: [collateralObject.symbol],
},
};
const transactionGrossProfit = marketUnitPrice
.multipliedBy(collateralAmount)
.minus(approximateUnitPrice.multipliedBy(collateralAmount));
Expand All @@ -40,6 +59,8 @@ export const generateFakeAuction = function () {
approximateUnitPrice,
unitPrice: approximateUnitPrice,
marketUnitPrice,
marketData,
suggestedMarketId,
isActive,
transactionGrossProfit,
isFinished,
Expand Down
7 changes: 6 additions & 1 deletion frontend/store/auctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,13 @@ export const actions = {
},
async bidWithCallee(
{ getters, commit, rootGetters }: ActionContext<State, State>,
{ id, alternativeDestinationAddress }: { id: string; alternativeDestinationAddress: string | undefined }
{
id,
marketId,
alternativeDestinationAddress,
}: { id: string; marketId: string; alternativeDestinationAddress: string | undefined }
) {
console.log(marketId); // to be removed after core implementation
const auction = getters.getAuctionById(id);
if (!auction) {
message.error(`Bidding error: can not find auction with id "${id}"`);
Expand Down