-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/ae-voting' into 'master'
feat(ae): add voting See merge request papers/airgap/airgap-wallet!134
- Loading branch information
Showing
12 changed files
with
248 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<ion-header no-border no-shadow> | ||
<ion-navbar color="whiteSecondaryContrast"> | ||
<ion-title>{{ 'voting.title' | translate }}</ion-title> | ||
</ion-navbar> | ||
</ion-header> | ||
|
||
<ion-content padding> | ||
<h3 no-margin>{{ 'voting.heading' | translate }}</h3> | ||
|
||
<p *ngIf="config" no-margin padding-bottom> | ||
Vote from | ||
<strong> | ||
{{ config?.startDate | amFromUnix | date: 'longDate' }} | ||
</strong> | ||
to | ||
<strong> | ||
{{ config?.endDate | amFromUnix | date: 'longDate' }} | ||
</strong> | ||
</p> | ||
|
||
<ion-row justify-content-center> | ||
<img src="../assets/img/vote.svg" /> | ||
</ion-row> | ||
<p> | ||
{{ 'voting.text' | translate }} | ||
</p> | ||
|
||
<p *ngIf="config?.showSelfVoted && oldVotePercentage && oldVoteTimestamp"> | ||
<strong>Your last vote: {{ oldVotePercentage }}% on {{ oldVoteTimestamp | amFromUnix | date: 'longDate' }}</strong> | ||
</p> | ||
|
||
<ion-range [disabled]="!config?.enabled" min="0" max="20" [(ngModel)]="votePercentage" [snaps]="true" [pin]="true" no-padding> | ||
<ion-label range-left>0%</ion-label> | ||
<ion-label range-right>20%</ion-label> | ||
</ion-range> | ||
<p> | ||
<strong | ||
*ngIf="config?.enabled && votePercentage > 0" | ||
[innerHTML]="'voting.your-vote_label' | translate: { votePercentage: votePercentage }" | ||
></strong> | ||
<strong *ngIf="config?.enabled && votePercentage === 0">I am NOT supporting the BRI</strong> | ||
<strong *ngIf="!config?.enabled">Voting is currently disabled</strong> | ||
</p> | ||
|
||
<h6 padding-top margin-bottom>{{ 'voting.further-information.heading' | translate }}</h6> | ||
<p> | ||
<a href="#" (click)="openUrl('https://blog.aeternity.com/aeternity-first-on-chain-governance-vote-decentralization-2-0-5e0c8a01891a')"> | ||
{{ 'voting.further-information.blog-post_label' | translate }} | ||
<ion-icon md-name="open_in_new"></ion-icon> | ||
</a> | ||
<br /> | ||
<a | ||
href="#" | ||
(click)="openUrl('https://forum.aeternity.com/t/discussion-block-reward-initiative-and-first-on-chain-governance-vote/3278')" | ||
> | ||
{{ 'voting.further-information.forum_label' | translate }} | ||
<ion-icon md-name="open_in_new"></ion-icon> | ||
</a> | ||
</p> | ||
|
||
<ion-fab right bottom> | ||
<button round ion-button color="primary" [disabled]="!config?.enabled" (click)="vote()"> | ||
{{ 'voting.vote_label' | translate }} | ||
</button> | ||
</ion-fab> | ||
</ion-content> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
page-voting { | ||
img { | ||
height: 40vh; | ||
} | ||
ion-icon { | ||
vertical-align: middle; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { Component } from '@angular/core' | ||
import { NavController, NavParams, Platform } from 'ionic-angular' | ||
import BigNumber from 'bignumber.js' | ||
import { InteractionSelectionPage } from '../interaction-selection/interaction-selection' | ||
import { AirGapMarketWallet, IAirGapTransaction } from 'airgap-coin-lib' | ||
import { handleErrorSentry, ErrorCategory } from '../../providers/sentry-error-handler/sentry-error-handler' | ||
import { OperationsProvider } from '../../providers/operations/operations' | ||
import { RemoteConfigProvider, AeFirstVote } from '../../providers/remote-config/remote-config' | ||
|
||
declare let cordova | ||
|
||
@Component({ | ||
selector: 'page-voting', | ||
templateUrl: 'voting.html' | ||
}) | ||
export class VotingPage { | ||
public oldVotePercentage: number | ||
public oldVoteTimestamp: number | ||
public config: AeFirstVote | ||
public wallet: AirGapMarketWallet | ||
|
||
public votePercentage: number = 10 | ||
public votingAddress: string = 'ak_11111111111111111111111111111111273Yts' | ||
|
||
constructor( | ||
public navCtrl: NavController, | ||
public navParams: NavParams, | ||
private operationsProvider: OperationsProvider, | ||
private remoteConfigProvider: RemoteConfigProvider, | ||
private platform: Platform | ||
) { | ||
this.wallet = this.navParams.get('wallet') | ||
} | ||
|
||
ngOnInit() { | ||
this.remoteConfigProvider.aeFirstVote().then(config => (this.config = config)) | ||
|
||
this.wallet | ||
.fetchTransactions(1000, 0) | ||
.then(txs => { | ||
const oldVote = txs.find(tx => !!tx.data) | ||
console.log(oldVote) | ||
if (oldVote) { | ||
try { | ||
console.log(JSON.parse(oldVote.data)) | ||
this.oldVotePercentage = JSON.parse(oldVote.data).vote.option | ||
this.oldVoteTimestamp = oldVote.timestamp | ||
} catch (error) { | ||
console.log(error) | ||
} | ||
} | ||
}) | ||
.catch(console.log) | ||
} | ||
|
||
public openUrl(url: string) { | ||
if (this.platform.is('ios') || this.platform.is('android')) { | ||
cordova.InAppBrowser.open(url, '_system', 'location=true') | ||
} else { | ||
window.open(url, '_blank') | ||
} | ||
} | ||
|
||
public async vote() { | ||
try { | ||
const { airGapTx, serializedTx } = await this.operationsProvider.prepareTransaction( | ||
this.wallet, | ||
this.votingAddress, | ||
new BigNumber(0), | ||
new BigNumber(17240000000000), | ||
JSON.stringify({ | ||
vote: { id: 1, option: Math.round(this.votePercentage) } | ||
}) | ||
) | ||
|
||
this.navCtrl | ||
.push(InteractionSelectionPage, { | ||
wallet: this.wallet, | ||
airGapTx: airGapTx, | ||
data: 'airgap-vault://?d=' + serializedTx | ||
}) | ||
.catch(handleErrorSentry(ErrorCategory.NAVIGATION)) | ||
} catch (error) { | ||
// | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.