From 8604b1602b12ee5d813ef1d00b3deb44ca7279c0 Mon Sep 17 00:00:00 2001 From: Felix Egbert <47861849+fegbert@users.noreply.github.com> Date: Wed, 30 Mar 2022 12:09:24 +0200 Subject: [PATCH] feat: Bid with DAI flow (#160) --- core/src/abis/MCD_DOG.json | 481 ++++++++++++++++++ core/src/auctions.ts | 5 +- core/src/contracts.ts | 4 + core/src/fetch.ts | 23 +- core/src/types.ts | 1 + frontend/components/Auction.vue | 11 +- frontend/components/MainFlow.vue | 30 +- .../transaction/BidBlock.stories.js | 12 +- frontend/components/transaction/BidBlock.vue | 6 +- .../transaction/BidTransaction.stories.js | 48 +- .../components/transaction/BidTransaction.vue | 67 +-- .../BidTransactionTable.stories.js | 26 +- .../transaction/BidTransactionTable.vue | 69 +-- .../transaction/DepositBlock.stories.js | 26 +- .../components/transaction/DepositBlock.vue | 34 +- frontend/components/utils/BidInput.stories.js | 8 +- frontend/components/utils/BidInput.vue | 60 ++- .../wallet/WalletDepositWithdrawBlock.vue | 8 +- frontend/containers/AuctionsContainer.vue | 26 +- frontend/containers/AuctionsFakeData.vue | 39 +- frontend/helpers/generateFakeAuction.js | 1 + 21 files changed, 699 insertions(+), 286 deletions(-) create mode 100644 core/src/abis/MCD_DOG.json diff --git a/core/src/abis/MCD_DOG.json b/core/src/abis/MCD_DOG.json new file mode 100644 index 000000000..dfe714555 --- /dev/null +++ b/core/src/abis/MCD_DOG.json @@ -0,0 +1,481 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "vat_", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "ilk", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "urn", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "ink", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "art", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "due", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "clip", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "id", + "type": "uint256" + } + ], + "name": "Bark", + "type": "event" + }, + { + "anonymous": false, + "inputs": [], + "name": "Cage", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "usr", + "type": "address" + } + ], + "name": "Deny", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "ilk", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "rad", + "type": "uint256" + } + ], + "name": "Digs", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "what", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "data", + "type": "uint256" + } + ], + "name": "File", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "ilk", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "what", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "data", + "type": "uint256" + } + ], + "name": "File", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "ilk", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "what", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "address", + "name": "clip", + "type": "address" + } + ], + "name": "File", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "usr", + "type": "address" + } + ], + "name": "Rely", + "type": "event" + }, + { + "inputs": [], + "name": "Dirt", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "Hole", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "ilk", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "urn", + "type": "address" + }, + { + "internalType": "address", + "name": "kpr", + "type": "address" + } + ], + "name": "bark", + "outputs": [ + { + "internalType": "uint256", + "name": "id", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "cage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "ilk", + "type": "bytes32" + } + ], + "name": "chop", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "usr", + "type": "address" + } + ], + "name": "deny", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "ilk", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "rad", + "type": "uint256" + } + ], + "name": "digs", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "ilk", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "what", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "data", + "type": "uint256" + } + ], + "name": "file", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "what", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "data", + "type": "uint256" + } + ], + "name": "file", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "what", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "data", + "type": "address" + } + ], + "name": "file", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "ilk", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "what", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "clip", + "type": "address" + } + ], + "name": "file", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "name": "ilks", + "outputs": [ + { + "internalType": "address", + "name": "clip", + "type": "address" + }, + { + "internalType": "uint256", + "name": "chop", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "hole", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "dirt", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "live", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "usr", + "type": "address" + } + ], + "name": "rely", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "vat", + "outputs": [ + { + "internalType": "contract VatLike", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "vow", + "outputs": [ + { + "internalType": "contract VowLike", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "wards", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/core/src/auctions.ts b/core/src/auctions.ts index 0007840d8..f20f381a8 100644 --- a/core/src/auctions.ts +++ b/core/src/auctions.ts @@ -1,6 +1,6 @@ import type { Auction, AuctionInitialInfo, AuctionTransaction, Notifier, TakeEvent } from './types'; import BigNumber from './bignumber'; -import fetchAuctionsByCollateralType, { fetchAuctionStatus } from './fetch'; +import fetchAuctionsByCollateralType, { fetchAuctionStatus, fetchMinimumBidDai } from './fetch'; import { getCalleeData, getMarketPrice } from './calleeFunctions'; import { fetchCalcParametersByCollateralType } from './params'; import executeTransaction from './execute'; @@ -27,15 +27,18 @@ const enrichAuctionWithActualNumbers = async function ( if (!auction.isActive || auction.isFinished) { return { ...auction, + minimumBidDai: new BigNumber(0), unitPrice: new BigNumber(0), approximateUnitPrice: new BigNumber(0), totalPrice: new BigNumber(0), }; } const auctionStatus = await fetchAuctionStatus(network, auction.collateralType, auction.index); + const minimumBidDai = await fetchMinimumBidDai(network, auction.collateralType); return { ...auction, ...auctionStatus, + minimumBidDai, approximateUnitPrice: auctionStatus.unitPrice, }; }; diff --git a/core/src/contracts.ts b/core/src/contracts.ts index 95cabd6db..756cfa13e 100644 --- a/core/src/contracts.ts +++ b/core/src/contracts.ts @@ -7,6 +7,7 @@ import MCD_VAT from './abis/MCD_VAT.json'; import MCD_JOIN_DAI from './abis/MCD_JOIN_DAI.json'; import MCD_CLIP_CALC from './abis/MCD_CLIP_CALC.json'; import MCD_CLIP from './abis/MCD_CLIP.json'; +import MCD_DOG from './abis/MCD_DOG.json'; import WSTETH from './abis/WSTETH.json'; import getSigner from './signer'; @@ -31,6 +32,9 @@ const getContractInterfaceByName = async function (contractName: string): Promis if (contractName === 'MCD_VAT') { return MCD_VAT; } + if (contractName === 'MCD_DOG') { + return MCD_DOG; + } if (contractName === 'WSTETH') { return WSTETH; } diff --git a/core/src/fetch.ts b/core/src/fetch.ts index 49d0aec29..59e593826 100644 --- a/core/src/fetch.ts +++ b/core/src/fetch.ts @@ -1,4 +1,5 @@ import type { AuctionInitialInfo, AuctionStatus } from './types'; +import { ethers } from 'ethers'; import memoizee from 'memoizee'; import BigNumber from './bignumber'; import getContract, { getClipperNameByCollateralType } from './contracts'; @@ -6,7 +7,7 @@ import { RAD, RAY, WAD } from './constants/UNITS'; import { getCollateralConfigByType } from './constants/COLLATERALS'; import convertNumberTo32Bytes from './helpers/convertNumberTo32Bytes'; -const AUCTION_DURATION_CACHE_EXPIRY_MS = 24 * 60 * 60 * 1000; +const CACHE_EXPIRY_MS = 24 * 60 * 60 * 1000; const _fetchMaximumAuctionDurationInSeconds = async function ( network: string, @@ -18,7 +19,21 @@ const _fetchMaximumAuctionDurationInSeconds = async function ( }; const fetchMaximumAuctionDurationInSeconds = memoizee(_fetchMaximumAuctionDurationInSeconds, { - maxAge: AUCTION_DURATION_CACHE_EXPIRY_MS, + maxAge: CACHE_EXPIRY_MS, + promise: true, + length: 2, +}); + +const _fetchMinimumBidDai = async function (network: string, collateralType: string): Promise { + const dogContract = await getContract(network, 'MCD_DOG'); + const encodedCollateralType = ethers.utils.formatBytes32String(collateralType); + const collateralParameters = await dogContract.ilks(encodedCollateralType); + const minimumBidDai = new BigNumber(collateralParameters.dirt._hex).div(RAD); + return minimumBidDai; +}; + +export const fetchMinimumBidDai = memoizee(_fetchMinimumBidDai, { + maxAge: CACHE_EXPIRY_MS, promise: true, length: 2, }); @@ -26,10 +41,10 @@ const fetchMaximumAuctionDurationInSeconds = memoizee(_fetchMaximumAuctionDurati export const fetchAuctionStatus = async function ( network: string, collateralType: string, - auctionId: number + auctionIndex: number ): Promise { const contract = await getContract(network, getClipperNameByCollateralType(collateralType)); - const statusData = await contract.getStatus(convertNumberTo32Bytes(auctionId)); + const statusData = await contract.getStatus(convertNumberTo32Bytes(auctionIndex)); const unitPrice = new BigNumber(statusData.price._hex).div(RAY); const collateralAmount = new BigNumber(statusData.lot._hex).div(WAD); const debtDAI = new BigNumber(statusData.tab._hex).div(RAD); diff --git a/core/src/types.ts b/core/src/types.ts index 770f84264..7e6fa28a8 100644 --- a/core/src/types.ts +++ b/core/src/types.ts @@ -37,6 +37,7 @@ export declare interface Auction extends AuctionInitialInfo { secondsTillNextPriceDrop?: number; priceDropRatio?: BigNumber; transactionGrossProfitDate?: Date; + minimumBidDai: BigNumber; } export declare interface TransactionFees { diff --git a/frontend/components/Auction.vue b/frontend/components/Auction.vue index 0a02d07f1..4bc222218 100644 --- a/frontend/components/Auction.vue +++ b/frontend/components/Auction.vue @@ -202,13 +202,10 @@
- -
- This feature is currently only supported for stub data. -
+
@@ -71,7 +68,6 @@ import BigNumber from 'bignumber.js'; import AuthorisationBlock from './AuthorisationBlock.vue'; import BidTransactionTable from './BidTransactionTable.vue'; import WalletBlock from './WalletBlock.vue'; -import AccessDaiBlock from './AccessDaiBlock.vue'; import DepositBlock from './DepositBlock.vue'; import BidBlock from './BidBlock.vue'; import TextBlock from '~/components/common/TextBlock.vue'; @@ -82,7 +78,6 @@ export default Vue.extend({ BidTransactionTable, AuthorisationBlock, WalletBlock, - AccessDaiBlock, DepositBlock, BidBlock, Alert, @@ -96,11 +91,7 @@ export default Vue.extend({ type: Boolean, default: false, }, - isGrantingAccess: { - type: Boolean, - default: false, - }, - isDepositing: { + isDepositingOrWithdrawing: { type: Boolean, default: false, }, @@ -116,10 +107,6 @@ export default Vue.extend({ type: Boolean, default: false, }, - isDaiAccessGranted: { - type: Boolean, - default: false, - }, authorisedCollaterals: { type: Array as Vue.PropType, default: () => [], @@ -140,17 +127,10 @@ export default Vue.extend({ type: Boolean, default: true, }, - transactionAmountDai: { - type: Object as Vue.PropType, - default: null, - }, - minimumBidDai: { - type: Object as Vue.PropType, - default: null, - }, }, data() { return { + inputBidAmount: undefined as BigNumber | undefined, amountToReceive: undefined as BigNumber | undefined, }; }, @@ -162,12 +142,11 @@ export default Vue.extend({ return this.authorisedCollaterals.includes(this.auctionTransaction.collateralType); }, isEnoughDeposited(): boolean { - return this.walletVatDai.isGreaterThanOrEqualTo(this.transactionAmountDai); + return this.walletVatDai?.isGreaterThanOrEqualTo(this.transactionBidAmount); }, - }, - methods: { - setAmountToReceive(amount: BigNumber | undefined) { - this.amountToReceive = amount; + transactionBidAmount(): BigNumber { + const output = this.inputBidAmount || this.auctionTransaction?.totalPrice || new BigNumber(NaN); + return output; }, }, }); diff --git a/frontend/components/transaction/BidTransactionTable.stories.js b/frontend/components/transaction/BidTransactionTable.stories.js index 3df351faf..fb263fb4a 100644 --- a/frontend/components/transaction/BidTransactionTable.stories.js +++ b/frontend/components/transaction/BidTransactionTable.stories.js @@ -15,7 +15,6 @@ const common = { isFinished: false, isActive: true, }, - minimumDepositDAI: new BigNumber(faker.finance.amount(0, 50)), }; }, }; @@ -23,8 +22,7 @@ const common = { storiesOf('Transaction/BidTransactionTable', module) .add('Default', () => ({ ...common, - template: - '', + template: '', })) .add('Finished', () => ({ ...common, @@ -35,11 +33,9 @@ storiesOf('Transaction/BidTransactionTable', module) isFinished: true, totalPrice: null, }, - minimumDepositDAI: new BigNumber(faker.finance.amount(0, 50)), }; }, - template: - '', + template: '', })) .add('Inactive', () => ({ ...common, @@ -51,11 +47,9 @@ storiesOf('Transaction/BidTransactionTable', module) isFinished: false, totalPrice: null, }, - minimumDepositDAI: new BigNumber(faker.finance.amount(0, 50)), }; }, - template: - '', + template: '', })) .add('Total < Minimum x 2', () => ({ ...common, @@ -66,12 +60,11 @@ storiesOf('Transaction/BidTransactionTable', module) isActive: true, isFinished: false, totalPrice: new BigNumber(faker.finance.amount(60, 99)), + minimumBidDai: new BigNumber(faker.finance.amount(50, 60)), }, - minimumDepositDAI: new BigNumber(faker.finance.amount(50, 60)), }; }, - template: - '', + template: '', })) .add('Decreasing Price', () => ({ ...common, @@ -82,7 +75,6 @@ storiesOf('Transaction/BidTransactionTable', module) isActive: true, isFinished: false, }, - minimumDepositDAI: new BigNumber(faker.finance.amount(0, 50)), }; }, created() { @@ -90,8 +82,7 @@ storiesOf('Transaction/BidTransactionTable', module) this.auctionTransaction.totalPrice = this.auctionTransaction.totalPrice.multipliedBy(0.99); }, 5000); }, - template: - '', + template: '', })) .add('Decreasing Into Disabled Input', () => ({ ...common, @@ -102,8 +93,8 @@ storiesOf('Transaction/BidTransactionTable', module) isActive: true, isFinished: false, totalPrice: new BigNumber(faker.finance.amount(50, 51)), + minimumBidDai: new BigNumber(faker.finance.amount(25, 25)), }, - minimumDepositDAI: new BigNumber(faker.finance.amount(25, 25)), }; }, created() { @@ -111,6 +102,5 @@ storiesOf('Transaction/BidTransactionTable', module) this.auctionTransaction.totalPrice = this.auctionTransaction.totalPrice.multipliedBy(0.99); }, 5000); }, - template: - '', + template: '', })); diff --git a/frontend/components/transaction/BidTransactionTable.vue b/frontend/components/transaction/BidTransactionTable.vue index c29e40b5c..4e9928434 100644 --- a/frontend/components/transaction/BidTransactionTable.vue +++ b/frontend/components/transaction/BidTransactionTable.vue @@ -50,17 +50,14 @@
-
-
The amount to bid
-
+
@@ -126,6 +126,7 @@ diff --git a/frontend/components/utils/BidInput.stories.js b/frontend/components/utils/BidInput.stories.js index 75cca12fe..6db634a9d 100644 --- a/frontend/components/utils/BidInput.stories.js +++ b/frontend/components/utils/BidInput.stories.js @@ -8,8 +8,8 @@ const common = { data() { return { totalPrice: new BigNumber(faker.finance.amount()), - minimumDepositDAI: new BigNumber(faker.finance.amount(0, 20)), - amountToBid: undefined, + minimumBidDai: new BigNumber(faker.finance.amount(0, 20)), + transactionBidAmount: undefined, }; }, }; @@ -19,13 +19,13 @@ storiesOf('Utils/BidInput', module) ...common, template: `
- +
`, })) .add('Disabled', () => ({ ...common, template: `
- +
`, })); diff --git a/frontend/components/utils/BidInput.vue b/frontend/components/utils/BidInput.vue index bdf989e13..050234736 100644 --- a/frontend/components/utils/BidInput.vue +++ b/frontend/components/utils/BidInput.vue @@ -3,14 +3,14 @@ -
+
DAI @@ -31,11 +31,11 @@ export default Vue.extend({ type: Object as Vue.PropType, default: null, }, - minimumDepositDai: { + minimumBidDai: { type: Object as Vue.PropType, required: true, }, - amountToBid: { + transactionBidAmount: { type: Object as Vue.PropType | undefined, default: undefined, }, @@ -46,34 +46,32 @@ export default Vue.extend({ }, data() { return { - amountToBidInput: '' as string, + transactionBidAmountInput: '' as string, }; }, computed: { isInputEmpty(): boolean { - return this.amountToBidInput.trim() === ''; + return this.transactionBidAmountInput.trim() === ''; }, - amountToBidInputParsed(): BigNumber | undefined { + transactionBidAmountInputParsed(): BigNumber | undefined { if (this.isInputEmpty) { return undefined; } - const amountToBid = new BigNumber(this.amountToBidInput); - return amountToBid; + const transactionBidAmount = new BigNumber(this.transactionBidAmountInput); + return transactionBidAmount; }, error(): string | undefined { - const maximumBid = this.totalPrice?.minus(this.minimumDepositDai); + const maximumBid = this.totalPrice?.minus(this.minimumBidDai); if ( - this.amountToBidInputParsed?.isGreaterThan(maximumBid) || - this.amountToBidInputParsed?.isLessThan(this.minimumDepositDai) + this.transactionBidAmountInputParsed?.isGreaterThan(maximumBid) || + this.transactionBidAmountInputParsed?.isLessThan(this.minimumBidDai) ) { - return `The value can only be between ${this.minimumDepositDai.toFixed(2)} and ${maximumBid.toFixed( - 2 - )}`; + return `The value can only be between ${this.minimumBidDai.toFixed(2)} and ${maximumBid.toFixed(2)}`; } return undefined; }, isTooSmallToPartiallyTake(): boolean { - return this.totalPrice?.isLessThan(this.minimumDepositDai.multipliedBy(2)); + return this.totalPrice?.isLessThan(this.minimumBidDai.multipliedBy(2)); }, isDisabled(): boolean { return this.disabled || this.isTooSmallToPartiallyTake; @@ -86,44 +84,44 @@ export default Vue.extend({ }, }, watch: { - amountToBidInput(_newAmountToBidInput: string, oldAmountToBidInput: string) { + transactionBidAmountInput(_newtransactionBidAmountInput: string, oldtransactionBidAmountInput: string) { if (this.error) { - this.$emit('update:amountToBid', new BigNumber(NaN)); + this.$emit('update:transactionBidAmount', new BigNumber(NaN)); return; } - if (!this.amountToBidInputParsed) { + if (!this.transactionBidAmountInputParsed) { return; } - if (this.amountToBidInputParsed?.isNaN()) { - this.amountToBidInput = oldAmountToBidInput || ''; + if (this.transactionBidAmountInputParsed?.isNaN()) { + this.transactionBidAmountInput = oldtransactionBidAmountInput || ''; return; } - this.$emit('update:amountToBid', this.amountToBidInputParsed); + this.$emit('update:transactionBidAmount', this.transactionBidAmountInputParsed); }, - amountToBid(newAmountToBid: BigNumber | undefined) { - if (!newAmountToBid) { - this.amountToBidInput = ''; + transactionBidAmount(newtransactionBidAmount: BigNumber | undefined) { + if (!newtransactionBidAmount) { + this.transactionBidAmountInput = ''; return; } - if (newAmountToBid.isEqualTo(this.minimumDepositDai) && !newAmountToBid.isZero()) { - this.amountToBidInput = newAmountToBid.toFixed(); + if (newtransactionBidAmount.isEqualTo(this.minimumDepositDai) && !newtransactionBidAmount.isZero()) { + this.transactionBidAmountInput = newtransactionBidAmount.toFixed(); } }, isTooSmallToPartiallyTake(newVal) { if (newVal) { - this.$emit('update:amountToBid', undefined); + this.$emit('update:transactionBidAmount', undefined); } }, }, methods: { hideTotalPrice(): void { - if (!this.amountToBid) { - this.$emit('update:amountToBid', new BigNumber(NaN)); + if (!this.transactionBidAmount) { + this.$emit('update:transactionBidAmount', new BigNumber(NaN)); } }, showTotalPriceIfEmpty(): void { if (this.isInputEmpty) { - this.$emit('update:amountToBid', undefined); + this.$emit('update:transactionBidAmount', undefined); } }, }, diff --git a/frontend/components/wallet/WalletDepositWithdrawBlock.vue b/frontend/components/wallet/WalletDepositWithdrawBlock.vue index 902754981..da271ad31 100644 --- a/frontend/components/wallet/WalletDepositWithdrawBlock.vue +++ b/frontend/components/wallet/WalletDepositWithdrawBlock.vue @@ -30,17 +30,17 @@ diff --git a/frontend/containers/AuctionsContainer.vue b/frontend/containers/AuctionsContainer.vue index 4932ad0ac..ac0319314 100644 --- a/frontend/containers/AuctionsContainer.vue +++ b/frontend/containers/AuctionsContainer.vue @@ -9,17 +9,22 @@ :is-explanations-shown.sync="isExplanationsShown" :wallet-address="walletAddress" :is-wallet-loading="isWalletLoading" + :is-depositing-or-withdrawing="isDepositingOrWithdrawing" :is-authorizing="isAuthorizing" :is-wallet-authorised="isWalletAuthorised" :authorised-collaterals="authorisedCollaterals" :is-executing="isAuctionBidding" :take-event-storage="takeEvents" - @connect="openWalletModal" + :wallet-dai="walletDai" + :wallet-vat-dai="walletVatDai" + @manageVat="openWalletModal" + @connect="openSelectWalletModal" @disconnect="disconnect" @authorizeWallet="authorizeWallet" @authorizeCollateral="authorizeCollateral" @restart="restartAuction" @execute="bidWithCallee" + @bidWithDai="bidWithDai" @fetchTakeEventsFromAuction="fetchTakeEventsByAuctionId" />
@@ -46,6 +51,8 @@ export default Vue.extend({ ...mapGetters('wallet', { isWalletLoading: 'isLoading', walletAddress: 'getAddress', + walletBalances: 'walletBalances', + isDepositingOrWithdrawing: 'isDepositingOrWithdrawing', }), ...mapGetters('authorizations', { isAuthorizing: 'isAuthorizationLoading', @@ -85,6 +92,12 @@ export default Vue.extend({ hasAcceptedTerms(): boolean { return this.$store.getters['cookies/hasAcceptedTerms']; }, + walletDai(): BigNumber { + return this.walletBalances?.walletDAI; + }, + walletVatDai(): BigNumber { + return this.walletBalances?.walletVatDAI; + }, }, watch: { fetchedSelectedAuctionId: { @@ -93,6 +106,7 @@ export default Vue.extend({ if (!fetchedSelectedAuctionId) { return; } + this.fetchWalletBalances(); this.fetchWalletAuthorizationStatus(); this.fetchCollateralAuthorizationStatus(this.selectedAuction.collateralType); }, @@ -101,6 +115,8 @@ export default Vue.extend({ if (!newWalletAddress) { return; } + + this.fetchWalletBalances(); this.fetchWalletAuthorizationStatus(); if (this.selectedAuction) { this.fetchCollateralAuthorizationStatus(this.selectedAuction.collateralType); @@ -114,14 +130,18 @@ export default Vue.extend({ 'fetchWalletAuthorizationStatus', 'fetchCollateralAuthorizationStatus', ]), - ...mapActions('auctions', ['bidWithCallee', 'restart', 'fetchTakeEventsByAuctionId']), - openWalletModal(): void { + ...mapActions('auctions', ['bidWithCallee', 'bidWithDai', 'restart', 'fetchTakeEventsByAuctionId']), + ...mapActions('wallet', ['fetchWalletBalances']), + openSelectWalletModal(): void { if (!this.hasAcceptedTerms) { this.$store.commit('modals/setTermsModal', true); return; } this.$store.commit('modals/setSelectWalletModal', true); }, + openWalletModal(): void { + this.$store.commit('modals/setWalletModal', true); + }, disconnect(): void { this.$store.dispatch('wallet/disconnect'); }, diff --git a/frontend/containers/AuctionsFakeData.vue b/frontend/containers/AuctionsFakeData.vue index 211dbc6df..309926519 100644 --- a/frontend/containers/AuctionsFakeData.vue +++ b/frontend/containers/AuctionsFakeData.vue @@ -3,29 +3,26 @@ :auctions="auctions" :selected-auction-id.sync="selectedAuctionId" :is-connecting="isConnecting" - :is-granting-access="isGrantingAccess" - :is-depositing-dai="isDepositingDai" + :is-depositing-or-withdrawing="isDepositingOrWithdrawing" :is-authorizing="isAuthorizing" :is-wallet-authorised="isWalletAuthorised" - :is-dai-access-granted="isDaiAccessGranted" :authorised-collaterals="authorisedCollaterals" :is-executing="isExecuting" :wallet-address="walletAddress" :wallet-dai="walletDai" :wallet-vat-dai="walletVatDai" :transaction-address="selectedAuction && selectedAuction.transactionAddress" - :transaction-amount-dai="transactionAmountDai" - :minimum-bid-dai="minimumBidDai" + :transaction-bid-amount="transactionAmountDai" :is-explanations-shown.sync="isExplanationsShown" @inputBidAmount="setTransactionAmountDai" @connect="connect" @disconnect="disconnect" - @grantDaiAccess="grantDaiAccess" - @deposit="deposit" + @manageVat="deposit" @authorizeWallet="authorizeWallet" @authorizeCollateral="authorizeCollateral" @restart="restart" @execute="execute" + @bidWithDai="execute" /> @@ -46,18 +43,14 @@ export default Vue.extend({ auctions: [] as AuctionTransaction[], selectedAuctionId: '', isConnecting: false, - isGrantingAccess: false, - isDepositingDai: false, + isDepositingOrWithdrawing: false, isAuthorizing: false, isExecuting: false, isWalletAuthorised: false, - isDaiAccessGranted: false, - isDeposited: false, authorisedCollaterals: [] as string[], walletAddress: null as string | null, walletDai: new BigNumber(faker.finance.amount()), walletVatDai: new BigNumber(faker.finance.amount()), - minimumBidDai: new BigNumber(faker.finance.amount(0, 100)), transactionAmountDai: undefined as BigNumber | undefined, }; }, @@ -124,21 +117,6 @@ export default Vue.extend({ this.isConnecting = false; }, 1000); }, - grantDaiAccess() { - this.isGrantingAccess = true; - setTimeout(() => { - this.isDaiAccessGranted = true; - this.isGrantingAccess = false; - }, 1000); - }, - deposit(amount: BigNumber) { - this.isDepositingDai = true; - setTimeout(() => { - this.walletDai = this.walletDai.minus(amount); - this.walletVatDai = this.walletVatDai.plus(amount); - this.isDepositingDai = false; - }, 1000); - }, authorizeWallet() { this.isAuthorizing = true; setTimeout(() => { @@ -174,6 +152,13 @@ export default Vue.extend({ setTransactionAmountDai(amount: BigNumber | undefined) { this.transactionAmountDai = amount; }, + deposit(): void { + this.isDepositingOrWithdrawing = true; + setTimeout(() => { + this.walletVatDai = this.transactionAmountDai!; + this.isDepositingOrWithdrawing = false; + }, 1000); + }, }, }); diff --git a/frontend/helpers/generateFakeAuction.js b/frontend/helpers/generateFakeAuction.js index 7b11d6ff5..fdcd56c3b 100644 --- a/frontend/helpers/generateFakeAuction.js +++ b/frontend/helpers/generateFakeAuction.js @@ -45,6 +45,7 @@ export const generateFakeAuction = function () { transactionAddress: undefined, secondsBetweenPriceDrops, secondsTillNextPriceDrop, + minimumBidDai: new BigNumber(faker.finance.amount()), priceDropRatio: new BigNumber(faker.datatype.number({ min: 0.5, max: 1, precision: 0.0001 })), transactionGrossProfitDate: faker.date.future(), };