From 7d9e4a690556e1c7b0060699410ca96d3fd3f017 Mon Sep 17 00:00:00 2001 From: DOXE913 Date: Sun, 10 Mar 2019 11:58:43 +0100 Subject: [PATCH] Add page /candidate (create) --- package-lock.json | 5 ++ src/app/app-routing.module.ts | 3 +- src/app/app.module.ts | 4 +- .../new-candidate/new-candidate.component.css | 42 +++++++++++ .../new-candidate.component.html | 63 ++++++++++++++++ .../new-candidate.component.spec.ts | 0 .../new-candidate/new-candidate.component.ts | 73 +++++++++++++++++++ 7 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 src/app/new-candidate/new-candidate.component.css create mode 100644 src/app/new-candidate/new-candidate.component.html create mode 100644 src/app/new-candidate/new-candidate.component.spec.ts create mode 100644 src/app/new-candidate/new-candidate.component.ts diff --git a/package-lock.json b/package-lock.json index 345ea65c..737e96f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7807,6 +7807,11 @@ "integrity": "sha512-MFh0d/Wa7vkKO3Y3LlacqAEeHK0mckVqzDieUKTT+KGxi+zIpeVsFxymkIiRpbpDziHc290Xr9A1O4Om7otoRA==", "dev": true }, + "ng": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/ng/-/ng-0.0.0.tgz", + "integrity": "sha512-HwR40IBJa1ZU+CIGyuy7vSCN3xFYlSRfw5eIwwKOdOMNNNIl8KhT6PXKmHuFEFYpfrbOMaCYtr4QOJ3gkkubcg==" + }, "ng2-semantic-ui": { "version": "0.9.7", "resolved": "https://registry.npmjs.org/ng2-semantic-ui/-/ng2-semantic-ui-0.9.7.tgz", diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index b3e26b6f..893fdfba 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -4,12 +4,13 @@ import { CulottelistComponent } from "./projects/culottelist/culottelist.compone import { AboutComponent } from "./about/about.component"; import { IdComponent } from "./id/id.component"; import { DonateComponent } from './donate/donate.component'; +import { NewCandidateComponent } from './new-candidate/new-candidate.component'; const routes: Routes = [ { path: "", component: CulottelistComponent }, { path: "culottelist", component: CulottelistComponent }, { path: "about", component: AboutComponent }, - { path: "candidate", component: CulottelistComponent }, + { path: "candidate", component: NewCandidateComponent }, { path: "candidate/:address", component: IdComponent }, { path: "donate", component: DonateComponent }, ]; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 8cd283e4..d04640f6 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -23,6 +23,7 @@ import { OpenelectionComponent } from "./projects/electionTabs/openelection/open import { CompletedelectionComponent } from "./projects/electionTabs/completedelection/completedelection.component"; import { IdComponent } from './id/id.component'; import { DonateComponent } from './donate/donate.component'; +import { NewCandidateComponent } from './new-candidate/new-candidate.component'; @NgModule({ declarations: [ @@ -32,7 +33,8 @@ import { DonateComponent } from './donate/donate.component'; OpenelectionComponent, CompletedelectionComponent, IdComponent, - DonateComponent + DonateComponent, + NewCandidateComponent ], imports: [ SuiModule, diff --git a/src/app/new-candidate/new-candidate.component.css b/src/app/new-candidate/new-candidate.component.css new file mode 100644 index 00000000..588992d9 --- /dev/null +++ b/src/app/new-candidate/new-candidate.component.css @@ -0,0 +1,42 @@ + +.title { + text-align: center; + font-size: 2em; +margin-bottom: 25px; +} + +.purpose { + position: relative; + margin-top: 40px; + text-align: center; + font-size: 1em; + color: black; +} + +.ethAmount { + position:relative; + margin-top: 25px; + margin-bottom: 25px; + font-size: 2em; + text-align: center; + max-width: 35%; + min-width: 135px; +} + +.tab { + margin-top: 15px; +} + +.amounts { + margin-left: 35%; +} + +.button { + min-width: 145px; +} + +.fields{ + max-width: 50%; + text-align:center; + margin: auto; +} \ No newline at end of file diff --git a/src/app/new-candidate/new-candidate.component.html b/src/app/new-candidate/new-candidate.component.html new file mode 100644 index 00000000..e9130057 --- /dev/null +++ b/src/app/new-candidate/new-candidate.component.html @@ -0,0 +1,63 @@ +
+
+ Would you support "{{ purpose }}" ? +
+
+ +
+
+ +
Address
+
+
+ +
Bet Some ETH
+
+
+ +
+
+
+ Should not be empty / Should contain only (numbers || address) +
+
+
+
+ +
+
+
+ +
+
+ +
+
+ + + +
+
+ +
+
+ +
+
+
+
+
diff --git a/src/app/new-candidate/new-candidate.component.spec.ts b/src/app/new-candidate/new-candidate.component.spec.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/app/new-candidate/new-candidate.component.ts b/src/app/new-candidate/new-candidate.component.ts new file mode 100644 index 00000000..1fc7b868 --- /dev/null +++ b/src/app/new-candidate/new-candidate.component.ts @@ -0,0 +1,73 @@ +import { Component, OnInit } from '@angular/core'; +import {Web3Service} from '../util/web3.service'; +import { ActivatedRoute } from '@angular/router'; + +declare let require:any; +const culotteABI = require('../../../build/contracts/Culotte.json'); + +@Component({ + selector: 'app-new-candidate', + templateUrl: './new-candidate.component.html', + styleUrls: ['./new-candidate.component.css'] +}) +export class NewCandidateComponent implements OnInit { + + address: String = "0x"; + purpose: String = "A frequent contributor to Open Source Projects" + culottes: any; + account: any; + accounth: any; + amount; + isOk = false; + web3_eth_contract: any; + + constructor(private web3Service: Web3Service, private route: ActivatedRoute,) { + } + +async ngOnInit() { + this.getAddress(); + this.watchAccount(); + this.web3Service.artifactsToContract(culotteABI) + .then((web3_eth_contract) => { + this.web3_eth_contract = web3_eth_contract; + return web3_eth_contract.methods.criteria().call(); + }) + .then((criteria) => { + console.log("criteria: ", criteria); + }); +} + + +onClickMeT() { + if (!this.amount) + this.isOk=true; + else { + this.isOk=false; + const weiAmount = this.web3Service.etherToWei(this.amount); + console.log(weiAmount) + this.web3_eth_contract.methods.vote(true, this.address).send({from: this.account, value: weiAmount}) + } +} + +onClickMeF() { + if (!this.amount) + this.isOk=true; + else { + this.isOk=false; + const weiAmount = this.web3Service.etherToWei(this.amount); + console.log(weiAmount) + this.web3_eth_contract.methods.vote(false, this.address).send({from: this.account, value: weiAmount}) + } +} + + +getAddress(): void { + this.address = this.route.snapshot.paramMap.get('address'); + } + +async watchAccount() { + this.web3Service.accountsObservable.subscribe((accounts) => { + this.account = accounts[0]; + }); +} +}