Skip to content

Commit

Permalink
Merge pull request #629 from ripio/release/0.3.0
Browse files Browse the repository at this point in the history
Release/0.3.0
  • Loading branch information
NicolasMenendez authored Dec 10, 2020
2 parents 560978b + 6b28fdc commit 2519f55
Show file tree
Hide file tree
Showing 96 changed files with 2,774 additions and 1,910 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## **0.3.0** Boggart 👻

### Feature:
- USDC engine integration
- New withdraw component

### Enhancement:
- Implements RCN API v6
- Improves dialog approve UI
- Estimate Fee amount

### Fix:
- Fix "go back" button behavior
- Fix withdraw icon in loan history

## **0.2.7** Boggart 👻

### Feature:
Expand Down
58 changes: 29 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rcn-angular-dapp",
"version": "0.2.7",
"version": "0.3.0",
"version_name": "Boggart",
"license": "MIT",
"scripts": {
Expand Down
12 changes: 8 additions & 4 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Router, NavigationEnd } from '@angular/router';
import { MatDialog } from '@angular/material';
import { environment } from '../environments/environment';
// App services
import { ApiService } from './services/api.service';
import { ProxyApiService } from './services/proxy-api.service';
import { EventsService } from './services/events.service';
import { WalletConnectService } from './services/wallet-connect.service';
// App component
Expand All @@ -20,7 +20,7 @@ export class AppComponent implements OnInit {
constructor(
private router: Router,
private dialog: MatDialog,
private apiService: ApiService,
private proxyApiService: ProxyApiService,
private eventsService: EventsService,
private walletConnectService: WalletConnectService
) {}
Expand Down Expand Up @@ -66,8 +66,12 @@ export class AppComponent implements OnInit {
}

private async checkApiHealth() {
const synchronized: boolean = await this.apiService.isSynchronized();
if (!synchronized) {
const { last_block: lastBlock, current_block: currentBlock } =
await this.proxyApiService.getApiStatus();
const ALLOWABLE_BLOCK_DIFFERENCE = 6;
const blockDiff = currentBlock - lastBlock;
const isSynchronized: boolean = blockDiff <= ALLOWABLE_BLOCK_DIFFERENCE;
if (!isSynchronized) {
this.dialog.open(DialogApiSyncComponent);
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/app/core/balance/balance.component.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<!-- TODO: add USDC withdraw -->
<div
class="balance-withdraw"
[class.balance-withdraw--active]="canWithdraw"
(click)="clickWithdraw()"
[class.balance-withdraw--active]="usdcCanWithdraw"
(click)="clickWithdrawUsdc()"
[matTooltip]='
canWithdraw ?
"Click here to withdraw your RCN Balance" :
usdcCanWithdraw ?
"Click here to withdraw your USDC Balance" :
"You dont have any funds to withdraw yet"
'
>
Expand All @@ -16,10 +17,10 @@
<i class="fas fa-arrow-down"></i>
</div>
<div class="balance-withdraw__amount">
{{ displayAvailable || 0 }}
{{ usdcDisplayAvailable || 0 }}
</div>
<div class="balance-withdraw__currency">
RCN
USDC
</div>
</div>
</div>
8 changes: 4 additions & 4 deletions src/app/core/balance/balance.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ describe('BalanceComponent', () => {

it('should display balance', () => {
// set balance amount
component.diasporeLoansWithBalance = [3000];
component.rcnAvailable = 3000;
component.usdcLoansWithBalance = [3000];
component.usdcAvailable = 3000;

// update template
component.updateDisplay();
fixture.detectChanges();

// logic expect
expect(component.displayAvailable).toBe('3,000.00');
expect(component.canWithdraw).toBeTruthy();
expect(component.usdcDisplayAvailable).toBe('3,000.00');
expect(component.usdcCanWithdraw).toBeTruthy();

// ui expect
const withdrawPayments = readComponent(fixture, '.balance-withdraw__amount');
Expand Down
67 changes: 33 additions & 34 deletions src/app/core/balance/balance.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Component, OnInit, OnChanges, OnDestroy, Input } from '@angular/core';
import { Subscription } from 'rxjs';
import { environment } from '../../../environments/environment';
import { Engine } from '../../models/loan.model';
import { Utils } from '../../utils/utils';
// App Services
import { Web3Service } from '../../services/web3.service';
import { EventsService } from '../../services/events.service';
import { ContractsService } from '../../services/contracts.service';
Expand All @@ -16,13 +16,12 @@ import { Tx, Type, TxService } from '../../services/tx.service';
export class BalanceComponent implements OnInit, OnChanges, OnDestroy {
@Input() account: string;

rcnAvailable: number;
diasporeLoansWithBalance: number[] = [];
ongoingDiasporeWithdraw: Tx;

canWithdraw = false;
displayAvailable = '';
txSubscription: boolean;
usdcAvailable: number;
usdcLoansWithBalance: number[] = [];
usdcOngoingWithdraw: Tx;
usdcCanWithdraw = false;
usdcDisplayAvailable = '';
usdcTxSubscription: boolean;

// subscriptions
subscriptionBalance: Subscription;
Expand Down Expand Up @@ -53,7 +52,7 @@ export class BalanceComponent implements OnInit, OnChanges, OnDestroy {
if (this.subscriptionBalance) {
this.subscriptionBalance.unsubscribe();
}
if (this.txSubscription) {
if (this.usdcTxSubscription) {
this.txService.unsubscribeConfirmedTx(async (tx: Tx) => this.trackWithdrawTx(tx));
}
}
Expand All @@ -71,26 +70,26 @@ export class BalanceComponent implements OnInit, OnChanges, OnDestroy {
* Update balance and withdraw amount
*/
updateDisplay() {
if (this.rcnAvailable) {
this.displayAvailable = Utils.formatAmount(this.rcnAvailable);
if (this.usdcAvailable) {
this.usdcDisplayAvailable = Utils.formatAmount(this.usdcAvailable);
} else {
this.displayAvailable = '0';
this.usdcDisplayAvailable = '0';
}

this.canWithdraw =
this.diasporeLoansWithBalance !== undefined &&
this.diasporeLoansWithBalance.length > 0 &&
this.ongoingDiasporeWithdraw === undefined;
this.usdcCanWithdraw =
this.usdcLoansWithBalance !== undefined &&
this.usdcLoansWithBalance.length > 0 &&
this.usdcOngoingWithdraw === undefined;
}

/**
* Load balance to withdraw amounts. Then, add all the values ​​and show the
* total available
*/
async loadWithdrawBalance() {
const pendingWithdraws = await this.contractService.getPendingWithdraws();
this.rcnAvailable = pendingWithdraws[2] / 10 ** 18;
this.diasporeLoansWithBalance = pendingWithdraws[3];
const pendingWithdraws = await this.contractService.getPendingWithdraws(Engine.UsdcEngine);
this.usdcAvailable = pendingWithdraws[2] / 10 ** 6;
this.usdcLoansWithBalance = pendingWithdraws[3];
this.loadOngoingWithdraw();
this.updateDisplay();
}
Expand All @@ -99,18 +98,18 @@ export class BalanceComponent implements OnInit, OnChanges, OnDestroy {
* Load the pending withdraw
*/
loadOngoingWithdraw() {
this.ongoingDiasporeWithdraw = this.txService.getLastWithdraw(
environment.contracts.diaspore.debtEngine,
this.diasporeLoansWithBalance
this.usdcOngoingWithdraw = this.txService.getLastWithdraw(
environment.contracts[Engine.UsdcEngine].diaspore.debtEngine,
this.usdcLoansWithBalance
);
}

/**
* Handle click on withdraw
* Handle click on withdraw USDC
*/
async clickWithdraw() {
async clickWithdrawUsdc() {
try {
await this.withdraw();
await this.withdrawUsdc();
} catch (err) {
if (err.stack.indexOf('User denied transaction signature') < 0) {
this.eventsService.trackError(err);
Expand All @@ -121,11 +120,11 @@ export class BalanceComponent implements OnInit, OnChanges, OnDestroy {
/**
* Withdraw diaspore funds
*/
async withdraw() {
if (this.canWithdraw) {
if (this.diasporeLoansWithBalance.length > 0) {
const tx = await this.contractService.withdrawFundsDiaspore(this.diasporeLoansWithBalance);
this.txService.registerWithdrawTx(tx, environment.contracts.diaspore.debtEngine, this.diasporeLoansWithBalance);
private async withdrawUsdc() {
if (this.usdcCanWithdraw) {
if (this.usdcLoansWithBalance.length > 0) {
const tx = await this.contractService.withdrawFundsDiaspore(Engine.UsdcEngine, this.usdcLoansWithBalance);
this.txService.registerWithdrawTx(tx, environment.contracts[Engine.UsdcEngine].diaspore.debtEngine, this.usdcLoansWithBalance);
}
this.loadWithdrawBalance();
this.retrievePendingTx();
Expand All @@ -135,17 +134,17 @@ export class BalanceComponent implements OnInit, OnChanges, OnDestroy {
/**
* Retrieve pending Tx
*/
retrievePendingTx() {
if (!this.txSubscription) {
this.txSubscription = true;
private retrievePendingTx() {
if (!this.usdcTxSubscription) {
this.usdcTxSubscription = true;
this.txService.subscribeConfirmedTx(async (tx: Tx) => this.trackWithdrawTx(tx));
}
}

/**
* Track tx
*/
trackWithdrawTx(tx: Tx) {
private trackWithdrawTx(tx: Tx) {
if (tx.type === Type.withdraw) {
this.web3Service.updateBalanceEvent.emit();
}
Expand Down
Loading

0 comments on commit 2519f55

Please sign in to comment.