Skip to content

Commit

Permalink
Frontend: Show cart action block even if contributor's data has been …
Browse files Browse the repository at this point in the history
…lost
  • Loading branch information
xuhcc committed Apr 11, 2021
1 parent e57b0d5 commit 5c3f615
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions vue-app/src/components/Cart.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="cart">
<div v-if="isEmptyCart" class="empty-cart">
<div v-if="isCartEmpty" class="empty-cart">
<img src="@/assets/empty.svg">
<h3>No projects selected</h3>
<div>Please select the projects that you want to contribute to</div>
Expand Down Expand Up @@ -36,35 +36,35 @@
</form>
</div>
<div
v-if="canSubmit()"
class="submit-btn-wrapper"
v-if="hasContributorActionBtn()"
class="action-btn-wrapper"
>
<div v-if="errorMessage" class="submit-error">
<div v-if="errorMessage" class="action-error">
{{ errorMessage }}
</div>
<div v-if="hasUnallocatedFunds()" class="submit-suggestion">
<div v-if="hasUnallocatedFunds()" class="action-suggestion">
Unallocated funds will be used as matching funding
</div>
<div v-if="canRegisterWithBrightId()" class="submit-suggestion">
<div v-if="canRegisterWithBrightId()" class="action-suggestion">
<a @click="registerWithBrightId()">Click here to verify your account using BrightID</a>
</div>
<div v-if="canBuyWxdai()" class="submit-suggestion">
<div v-if="canBuyWxdai()" class="action-suggestion">
<a href="https://wrapeth.com/" target="_blank" rel="noopener">
Click here to wrap XDAI
</a>
</div>
<button
v-if="canWithdrawContribution()"
class="btn submit-btn"
class="btn action-btn"
@click="withdrawContribution()"
>
Withdraw {{ formatAmount(contribution) }} {{ tokenSymbol }}
</button>
<button
v-else
class="btn submit-btn"
class="btn action-btn"
:disabled="errorMessage !== null"
@click="submit()"
@click="submitCart()"
>
<template v-if="contribution.isZero()">
Contribute {{ formatAmount(getTotal()) }} {{ tokenSymbol }} to {{ cart.length }} projects
Expand Down Expand Up @@ -124,8 +124,13 @@ export default class Cart extends Vue {
return this.cart.filter((item) => !item.isCleared)
}
get isEmptyCart(): boolean {
return this.$store.state.currentUser && this.filteredCart.length === 0
get isCartEmpty(): boolean {
return (
this.$store.state.currentUser &&
this.$store.state.contribution !== null &&
this.$store.state.contribution.isZero() &&
this.filteredCart.length === 0
)
}
formatAmount(value: BigNumber): string {
Expand Down Expand Up @@ -178,8 +183,14 @@ export default class Cart extends Vue {
this.$store.dispatch(SAVE_CART)
}
canSubmit(): boolean {
return this.$store.state.currentRound && this.cart.length > 0 || this.canWithdrawContribution()
hasContributorActionBtn(): boolean {
// Show cart action button:
// - if there are items in cart
// - if contribution can be withdrawn
// - if contributor data has been lost
return this.$store.state.currentRound && (
this.cart.length > 0 || !this.contribution.isZero()
)
}
private isFormValid(): boolean {
Expand Down Expand Up @@ -272,7 +283,6 @@ export default class Cart extends Vue {
hasUnallocatedFunds(): boolean {
return (
this.errorMessage === null &&
this.contribution !== null &&
!this.contribution.isZero() &&
this.getTotal().lt(this.contribution)
)
Expand All @@ -298,7 +308,7 @@ export default class Cart extends Vue {
)
}
submit() {
submitCart() {
const { nativeTokenDecimals, voiceCreditFactor } = this.$store.state.currentRound
const votes = this.cart.map((item: CartItem) => {
const amount = parseFixed(item.amount, nativeTokenDecimals)
Expand Down Expand Up @@ -422,23 +432,23 @@ $project-image-size: 50px;
}
}
.submit-btn-wrapper {
.action-btn-wrapper {
align-self: flex-end;
box-sizing: border-box;
margin-top: auto;
padding: $content-space;
text-align: center;
width: 100%;
.submit-error {
.action-error {
padding: 15px 0 0;
}
.submit-suggestion {
.action-suggestion {
padding-top: 5px;
}
.submit-btn {
.action-btn {
margin-top: 15px;
width: 100%;
}
Expand Down

0 comments on commit 5c3f615

Please sign in to comment.