Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
fix: handle new node fees response (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
luciorubeens committed Dec 10, 2019
1 parent 49417a3 commit 1960cc5
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 15 deletions.
32 changes: 32 additions & 0 deletions src/app/app.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,35 @@ export const PRIVACY_POLICY_URL = 'https://ark.io/PrivacyPolicy.txt';
export const URI_QRCODE_SCHEME_PREFIX = 'ark:';
export const NUM_ACTIVE_DELEGATES = 51;
export const TOP_WALLETS_TO_FETCH = 50;

export const TRANSACTION_GROUPS = {
STANDARD: 1,
MAGISTRATE: 2
};

export const TRANSACTION_TYPES = {
MULTI_SIGN: -1,

GROUP_1: {
TRANSFER: 0,
SECOND_SIGNATURE: 1,
DELEGATE_REGISTRATION: 2,
VOTE: 3,
MULTI_SIGNATURE: 4,
IPFS: 5,
MULTI_PAYMENT: 6,
DELEGATE_RESIGNATION: 7,
HTLC_LOCK: 8,
HTLC_CLAIM: 9,
HTLC_REFUND: 10
},

GROUP_2: {
BUSINESS_REGISTRATION: 0,
BUSINESS_RESIGNATION: 1,
BUSINESS_UPDATE: 2,
BRIDGECHAIN_REGISTRATION: 3,
BRIDGECHAIN_RESIGNATION: 4,
BRIDGECHAIN_UPDATE: 5
}
};
43 changes: 33 additions & 10 deletions src/app/services/ark-api/ark-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ interface NodeFees {
}

interface NodeFeesResponse {
data: NodeFees[];
data: NodeFees[] | {
[group: string]: {
[type: string]: NodeFees;
}
};
}

@Injectable({ providedIn: 'root' })
Expand Down Expand Up @@ -455,18 +459,37 @@ export class ArkApiProvider {
`${this._network.getPeerAPIUrl()}/api/v2/node/fees?days=7`
).subscribe((response: NodeFeesResponse) => {
const data = response.data;
// Converts the new response to the old template
const feeStatistics: FeeStatistic[] = data.map(item => ({
type: Number(item.type),
fees: {
minFee: Number(item.min),
maxFee: Number(item.max),
avgFee: Number(item.avg),
let feeStatistics: FeeStatistic[] = [];

if (Array.isArray(data)) {
feeStatistics = data.map(fee => ({
type: Number(fee.type),
fees: {
minFee: Number(fee.min),
maxFee: Number(fee.max),
avgFee: Number(fee.avg)
}
}));
} else {
const standard = data[constants.TRANSACTION_GROUPS.STANDARD];

for (const type in standard) {
const fee = standard[type];
const typeFormatted = lodash.snakeCase(type).toUpperCase();

feeStatistics.push({
type: constants.TRANSACTION_TYPES.GROUP_1[typeFormatted],
fees: {
minFee: Number(fee.min),
maxFee: Number(fee.max),
avgFee: Number(fee.avg)
}
});
}
}));
}

this._network.feeStatistics = feeStatistics;
observer.next(feeStatistics);
observer.next(this._network.feeStatistics);
}, (e) => observer.error(e));
});
}
Expand Down
13 changes: 8 additions & 5 deletions src/app/utils/ark-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import lodash from 'lodash';
import { Observable, of } from 'rxjs';
import { timeout } from 'rxjs/operators';
import { INodeConfiguration } from '@/models/node';
import { TRANSACTION_GROUPS } from '@/app/app.constants';

export interface PeerApiResponse extends Peer {
latency?: number;
Expand Down Expand Up @@ -130,14 +131,16 @@ export default class ApiClient {
return Observable.create(observer => {
this.get('transactions/fees').subscribe((response: any) => {
const data = response.data;
const payload = data[TRANSACTION_GROUPS.STANDARD] ? data[TRANSACTION_GROUPS.STANDARD] : data;

observer.next({
success: true,
fees: {
send: data.transfer,
vote: data.vote,
secondsignature: data.secondSignature,
delegate: data.delegateRegistration,
multisignature: data.multiSignature
send: payload.transfer,
vote: payload.vote,
secondsignature: payload.secondSignature,
delegate: payload.delegateRegistration,
multisignature: payload.multiSignature
}
});
observer.complete();
Expand Down

0 comments on commit 1960cc5

Please sign in to comment.