diff --git a/vue-app/package.json b/vue-app/package.json index cbbb9b36a..626c24236 100644 --- a/vue-app/package.json +++ b/vue-app/package.json @@ -16,6 +16,7 @@ "maci-domainobjs": "^0.1.8", "vue": "^2.6.11", "vue-class-component": "^7.2.2", + "vue-js-modal": "^2.0.0-rc.6", "vue-property-decorator": "^8.3.0", "vue-router": "^3.1.5", "vuex": "^3.1.2" diff --git a/vue-app/public/favicon.ico b/vue-app/public/favicon.ico index df36fcfb7..74c783347 100644 Binary files a/vue-app/public/favicon.ico and b/vue-app/public/favicon.ico differ diff --git a/vue-app/src/App.vue b/vue-app/src/App.vue index 00c403761..01fc74d56 100644 --- a/vue-app/src/App.vue +++ b/vue-app/src/App.vue @@ -59,6 +59,12 @@ html { background-color: $highlight-color; color: $bg-secondary-color; } + + &[disabled], + &[disabled]:hover { + background-color: $button-disabled-color !important; + color: $text-color !important; + } } #app { diff --git a/vue-app/src/api/projects.ts b/vue-app/src/api/projects.ts index e0c6da036..c3a6c783b 100644 --- a/vue-app/src/api/projects.ts +++ b/vue-app/src/api/projects.ts @@ -22,7 +22,7 @@ export async function getProjects(): Promise { name: metadata.name, description: metadata.description, imageUrl: `${ipfsGatewayUrl}${metadata.imageHash}`, - index: event.args._index, + index: event.args._index.toNumber(), }) }) return projects diff --git a/vue-app/src/api/round.ts b/vue-app/src/api/round.ts index 204763351..0df5666ea 100644 --- a/vue-app/src/api/round.ts +++ b/vue-app/src/api/round.ts @@ -1,5 +1,7 @@ import { ethers, BigNumber, FixedNumber } from 'ethers' import { DateTime } from 'luxon' +import { bigInt } from 'maci-crypto' +import { PubKey } from 'maci-domainobjs' import { FundingRound, ERC20 } from './abi' import { provider, factory } from './core' @@ -7,6 +9,7 @@ import { provider, factory } from './core' export interface RoundInfo { fundingRoundAddress: string; maciAddress: string; + coordinatorPubKey: PubKey; nativeTokenAddress: string; nativeTokenSymbol: string; nativeTokenDecimals: number; @@ -37,6 +40,11 @@ export async function getRoundInfo(): Promise { provider, ) const maciAddress = await fundingRound.maci() + const coordinatorPubKeyRaw = await fundingRound.coordinatorPubKey() + const coordinatorPubKey = new PubKey([ + bigInt(coordinatorPubKeyRaw.x), + bigInt(coordinatorPubKeyRaw.y), + ]) const nativeTokenAddress = await fundingRound.nativeToken() const nativeToken = new ethers.Contract( nativeTokenAddress, @@ -88,6 +96,7 @@ export async function getRoundInfo(): Promise { return { fundingRoundAddress, maciAddress, + coordinatorPubKey, nativeTokenAddress, nativeTokenSymbol, nativeTokenDecimals, diff --git a/vue-app/src/components/Cart.vue b/vue-app/src/components/Cart.vue index be14b651d..0e763c6bb 100644 --- a/vue-app/src/components/Cart.vue +++ b/vue-app/src/components/Cart.vue @@ -35,66 +35,18 @@ import Vue from 'vue' import Component from 'vue-class-component' import { DateTime } from 'luxon' -import { Contract, FixedNumber } from 'ethers' -import { Web3Provider } from '@ethersproject/providers' -import { parseFixed } from '@ethersproject/bignumber' -import { Keypair } from 'maci-domainobjs' + +import ContributionModal from '@/components/ContributionModal.vue' import { CartItem } from '@/api/contributions' import { ADD_CART_ITEM, UPDATE_CART_ITEM, REMOVE_CART_ITEM, - SET_CONTRIBUTION, } from '@/store/mutation-types' -import { getEventArg } from '@/utils/contracts' - -import { FundingRound, ERC20, MACI } from '@/api/abi' const CART_STORAGE_KEY = 'clrfund-cart' -interface ContributorData { - privateKey: string; - stateIndex: number; - contribution: FixedNumber; - voiceCredits: number; -} - -async function contribute( - provider: Web3Provider, - tokenAddress: string, - tokenDecimals: number, - fundingRoundAddress: string, - maciAddress: string, - amount: number, -): Promise { - const signer = provider.getSigner() - const token = new Contract(tokenAddress, ERC20, signer) - const amountRaw = parseFixed(amount.toString(), tokenDecimals) - // Approve transfer - const allowance = await token.allowance(signer.getAddress(), fundingRoundAddress) - if (allowance < amountRaw) { - await token.approve(fundingRoundAddress, amountRaw) - } - // Contribute - const contributorKeypair = new Keypair() - const fundingRound = new Contract(fundingRoundAddress, FundingRound, signer) - const contributionTx = await fundingRound.contribute( - contributorKeypair.pubKey.asContractParam(), - amountRaw, - ) - // Get state index and amount of voice credits - const maci = new Contract(maciAddress, MACI, signer) - const stateIndex = await getEventArg(contributionTx, maci, 'SignUp', '_stateIndex') - const voiceCredits = await getEventArg(contributionTx, maci, 'SignUp', '_voiceCreditBalance') - return { - privateKey: contributorKeypair.privKey.serialize(), - stateIndex, - contribution: FixedNumber.fromValue(amountRaw, tokenDecimals), - voiceCredits, - } -} - @Component({ watch: { cart(items: CartItem[]) { @@ -157,24 +109,15 @@ export default class Cart extends Vue { } async contribute() { - const walletProvider = this.$store.state.walletProvider - const currentRound = this.$store.state.currentRound - if (!walletProvider || !currentRound) { - return - } - const contributorData = await contribute( - walletProvider, - currentRound.nativeTokenAddress, - currentRound.nativeTokenDecimals, - currentRound.fundingRoundAddress, - currentRound.maciAddress, - this.total, + this.$modal.show( + ContributionModal, + { }, + { + clickToClose: false, + height: 'auto', + width: 450, + }, ) - this.$store.commit(SET_CONTRIBUTION, contributorData.contribution) - this.cart.slice().forEach((item) => { - this.$store.commit(REMOVE_CART_ITEM, item) - }) - console.info(contributorData) // eslint-disable-line no-console } } diff --git a/vue-app/src/components/ContributionModal.vue b/vue-app/src/components/ContributionModal.vue new file mode 100644 index 000000000..717b47ace --- /dev/null +++ b/vue-app/src/components/ContributionModal.vue @@ -0,0 +1,202 @@ + + + + + + diff --git a/vue-app/src/components/ProjectItem.vue b/vue-app/src/components/ProjectItem.vue index 0d96660a2..976f7e4b8 100644 --- a/vue-app/src/components/ProjectItem.vue +++ b/vue-app/src/components/ProjectItem.vue @@ -6,6 +6,7 @@
{{ project.description }}