Skip to content

Commit

Permalink
Display dao contract details in UI (#46)
Browse files Browse the repository at this point in the history
* Started work on a simple component to show DAO contract details

* small fixes on the DAO UI

* remove double braces

* Added total deposits

* Add links fomr constract address and some display some more data

Co-authored-by: TheDude <david@vsodir.onmicrosoft.com>
Co-authored-by: dangershony <dan.gershony@gmail.com>
  • Loading branch information
3 people authored Mar 23, 2022
1 parent 3e644e6 commit e7569b7
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/Blockcore.Explorer/Blockcore.Explorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<None Remove="$(SpaRoot)**" />
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
</ItemGroup>
<ItemGroup>
<Folder Include="ClientApp\src\app\explorer\DaoContract\Proposal" />
</ItemGroup>
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
<!-- Ensure Node.js is installed -->
<Exec Command="node --version" ContinueOnError="true">
Expand Down
7 changes: 7 additions & 0 deletions src/Blockcore.Explorer/ClientApp/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { ContractCodeComponent } from './explorer/contract-code/contract-code.co
import { MempoolComponent } from './explorer/mempool/mempool.component';
import { SearchGlobalComponent } from './search-global/search-global.component';
import { OrphansComponent } from './explorer/orphans/orphans.component';
import {DaoContractComponent} from "./explorer/DaoContract/dao-contract.component";

const routes: Routes = [
{
Expand Down Expand Up @@ -129,6 +130,11 @@ const routes: Routes = [
chain: LoadingResolverService
}
},
{
path: ':chain/explorer/dao-contract/:address', component: DaoContractComponent, resolve: {
chain: LoadingResolverService
}
},
];

@NgModule({
Expand Down Expand Up @@ -167,6 +173,7 @@ const routes: Routes = [
ContractAddressComponent,
ContractCodeComponent,
OrphansComponent,
DaoContractComponent
],
imports: [
BrowserModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<app-search></app-search>

<div class="box">
<div *ngIf="daoContract">
<div class="grid-hash">
<div>
<span class="grid-hash-left"><i class="fas fa-hashtag"></i></span>
<span class="grid-hash-middle breakable">{{daoContract.contractAddress}}</span>
<span class="grid-hash-right">
<div class="grid-double">
</div>
</span>
</div>
</div>
</div>
</div>

<div class="box">

<h3><i class="fas fa-receipt"></i>&nbsp;&nbsp;DAO Contract Details</h3>

<app-progress class="centered" *ngIf="!daoContract"></app-progress>
<app-error class="centered" [error]="error"></app-error>

<div class="grid-label-value" *ngIf="daoContract">
<div *ngIf="daoContract">
<span>Available amount</span>
<span>{{daoContract.currentAmount | amount}} {{setup.Chain.Symbol}}</span>
</div>
<div *ngIf="daoContract.minVotingDuration">
<span>Min voting duration</span>
<span>{{daoContract.minVotingDuration}}</span>
</div>
<div *ngIf="daoContract.maxVotingDuration">
<span>Max voting duration</span>
<span>{{daoContract.maxVotingDuration}}</span>
</div>
<div>
<span>Created on Transaction</span>
<span><a [routerLink]="['../../','contract-transaction', daoContract.contractCreateTransactionId]">{{daoContract.contractCreateTransactionId | slice:0:20}}</a></span>
</div>
<div *ngIf="totalDepositsAmount">
<span>Total deposits amount</span>
<span>{{totalDepositsAmount | amount}} {{setup.Chain.Symbol}}</span>
</div>
<div *ngIf="totalDepositsAmount">
<span>Amounts on approved proposals</span>
<span>{{totalAmountOnApprovedProposals | amount}} {{setup.Chain.Symbol}}</span>
</div>

<div *ngIf="daoContract.error">
<span>Error</span>
<span>{{daoContract.error}}</span>
</div>

<div>
</div>

</div>




</div>

<div class="box">
<h3>Deposits</h3>

<div *ngIf="daoContract.deposits" class="left">
<h3>Deposits</h3>

<div *ngIf="daoContract.deposits">
<div class="grid grid-odd-line" *ngFor="let item of daoContract.deposits">
<span class="address left">{{item.senderAddress}}</span>
<span class="right">{{item.amount | amount}}</span>
<span><a [routerLink]="['../../','contract-transaction', item.transactionId]">{{item.transactionId | slice:0:20}}</a></span>

</div>
</div>
</div>
</div>

<div class="box">
<h3>Proposals</h3>

<div *ngIf="daoContract.proposals" class="left">
<div>
<div class="grid grid-odd-line" *ngFor="let item of daoContract.proposals">
<span class="left">{{item.description}}</span>
<!--<span class="left">Start block: {{item.proposalStartedAtBlock}}</span>
<span class="left">End block: {{item.proposalCompletedAtBlock}}</span>-->
<!--<span><a [routerLink]="['../../','address', item.recipient]">{{item.recipient | slice:0:20}}</a></span>-->
<span><a [routerLink]="['../../','contract-transaction', item.payoutTransactionId]">{{item.payoutTransactionId | slice:0:20}}</a></span>
<span class="right">{{item.amount| amount}}</span>
<span class="centered" *ngIf="!item.wasProposalAccepted">rejected</span>
<span class="centered" *ngIf="item.wasProposalAccepted">accepted</span>
</div>
</div>
</div>

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {Component, HostBinding, Input, OnDestroy, OnInit} from "@angular/core";
import {ApiService} from "../../services/api.service";
import {ActivatedRoute, Router} from "@angular/router";
import {SetupService} from "../../services/setup.service";

@Component({
selector: 'app-dao-contract-component',
templateUrl: './dao-contract.component.html'
})

export class DaoContractComponent implements OnInit,OnDestroy{
daoContract: any;
error: null;
totalDepositsAmount:number = 0;
totalAmountOnApprovedProposals:number = 0;
deposits: Map<string, any>;
@HostBinding('class.content-centered-top') private _hostClass = true;

constructor(
private api: ApiService,
private router: Router,
public setup: SetupService,
private activatedRoute: ActivatedRoute) {

this.activatedRoute.paramMap.subscribe(async params => {
const address: any = params.get('address');
console.log('Smart contract address:', address);

try {
this.daoContract = await this.api.getDaoContractTransaction(address);

this.totalDepositsAmount = this.daoContract.deposits.map((item)=> Number.parseInt(item.amount)).reduce((acc, curr) => acc + curr, 0);

this.totalAmountOnApprovedProposals = this.daoContract.proposals.map((item)=> {
Number.parseInt(item.amount) * (item.wasProposalAccepted ? 1 : -1)
}).reduce((acc, curr) => acc + curr, 0);

// this.daoContract.deposits.forEach((item) =>
// {
// if (this.deposits[item.senderAddress] == null)
// {
// this.deposits[item.senderAddress] = new item()
// }
//
// this.deposits[item.senderAddress].amount += item.amount;
// this.deposits[item.senderAddress].transactions += 1;
//
// })

this.error = null;
} catch (e) {
this.error = e;
}

console.log(this.daoContract);
});
}

ngOnDestroy(): void {
}

ngOnInit(): void {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ <h3><i class="fas fa-receipt"></i>&nbsp;&nbsp;Smart Contract Details</h3>
<div class="grid-label-value" *ngIf="transaction">
<div>
<span>Contract Type</span>
<span>{{transaction.contractCodeType}}</span>
<span *ngIf="!contractCodeTypeLink">{{transaction.contractCodeType}}</span>
<span *ngIf="contractCodeTypeLink"><a [routerLink]="[navPath, contractCodeTypeLinkPath, contractCodeTypeLinkParam]">{{transaction.contractCodeType}}</a></span>
</div>
<div>
<span>Block</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export class ContractAddressComponent implements OnInit, OnDestroy {
transactions: any;
transaction: any;

contractCodeTypeLink = false;
contractCodeTypeLinkPath: any;
contractCodeTypeLinkParam: any;

timerInfo: any;
timerBlocks: any;
timerTransactions: any;
Expand Down Expand Up @@ -60,6 +64,8 @@ export class ContractAddressComponent implements OnInit, OnDestroy {

try {
this.transaction = await this.api.getContractAddress(id);
this.buildLinkAddress();

} catch (err) {
if (err.message[0] === '{') {
this.error = JSON.parse(err.message);
Expand Down Expand Up @@ -107,6 +113,17 @@ export class ContractAddressComponent implements OnInit, OnDestroy {

}

buildLinkAddress() {

if (this.transaction.contractCodeType == "DAOContract") {

this.contractCodeTypeLink = true;
this.contractCodeTypeLinkPath = "dao-contract";
this.contractCodeTypeLinkParam = this.transaction.contractAddress;

}
}

async updateTransactions(url) {
// If no URL, then likely reached the end.
if (!url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ <h3><i class="fas fa-receipt"></i>&nbsp;&nbsp;Smart Contract Transaction Details
<div class="grid-label-value" *ngIf="transaction">
<div>
<span>Contract Type</span>
<span>{{transaction.contractCodeType}}</span>
<span *ngIf="!contractCodeTypeLink">{{transaction.contractCodeType}}</span>
<span *ngIf="contractCodeTypeLink"><a [routerLink]="['../../',contractCodeTypeLinkPath, contractCodeTypeLinkParam]">{{transaction.contractCodeType}}</a></span>
</div>
<div *ngIf="transaction.methodName">
<span>Method Name</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export class ContractTransactionComponent implements OnInit, OnDestroy {
blocks: any;
transactions: any;

timerInfo: any;
contractCodeTypeLink = false;
contractCodeTypeLinkPath: any;
contractCodeTypeLinkParam: any;

timerInfo: any;
timerBlocks: any;
timerTransactions: any;
transaction: any;
Expand All @@ -42,6 +46,7 @@ export class ContractTransactionComponent implements OnInit, OnDestroy {

try {
this.transaction = await this.api.getContractTransaction(id);
this.buildLink();

this.error = null;
} catch (e) {
Expand All @@ -62,6 +67,22 @@ export class ContractTransactionComponent implements OnInit, OnDestroy {

ngOnDestroy(): void {

}
}

buildLink() {

if (this.transaction.contractCodeType == "DAOContract") {

this.contractCodeTypeLink = true;
this.contractCodeTypeLinkPath = "dao-contract";

if (this.transaction.newContractAddress) {
this.contractCodeTypeLinkParam = this.transaction.newContractAddress;
}
else {
this.contractCodeTypeLinkParam = this.transaction.toAddress;
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ export class ApiService {
return this.downloadRelative('/query/cirrus/contract/code/' + address);
}

async getDaoContractTransaction(address: string) {
return this.downloadRelative('/query/cirrus/contract/Dao/' + address);
}

parseLinkHeader(linkHeader: string) {
const sections = linkHeader.split(', ');
//const links: Record<string, string> = { };
Expand Down
9 changes: 9 additions & 0 deletions src/Blockcore.Explorer/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Cirrus": {
"commandName": "Project",
"commandLineArgs": "--chain=CRS",
"launchBrowser": true,
"applicationUrl": "http://localhost:9911",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

0 comments on commit e7569b7

Please sign in to comment.