1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {Injectable} from '@angular/core';
import * as BN from 'bn.js';
import {DIVIDER_FOR_BALANCE, WEB3} from '../../../integrations/dictionaries/meta-mask.dictionary';
@Injectable({
providedIn: 'root'
})
export class UtilsService {
public parseAmount(amount: string, decimals: number): number {
const web3 = window[WEB3];
const divider = web3.utils.toBN(10).pow(web3.utils.toBN(decimals));
return new web3.utils.BN(amount).div(divider).toNumber();
}
public convertAmount(amount: any) {
const web3 = window[WEB3];
amount = web3.utils.toWei(amount.toString());
return amount;
}
public parseAmountDivider(amount: string): number {
const web3 = window[WEB3];
const divider = web3.utils.toBN(10).pow(web3.utils.toBN(DIVIDER_FOR_BALANCE));
let result = (new web3.utils.BN(amount)).div(divider).toNumber();
result = result / 100;
return result;
}
public lessOrEqual(amount1: string, amount2: string ) {
const web3 = window[WEB3];
amount1 = web3.utils.toWei(amount1);
return (new web3.utils.BN(amount1)).lte(new web3.utils.BN(amount2));
}
public greaterThen(amount1: string, amount2: string ) {
const web3 = window[WEB3];
amount1 = web3.utils.toWei(amount1);
return (new web3.utils.BN(amount1)).gt(new web3.utils.BN(amount2));
}
public lessThen(amount1: string, amount2: string ) {
const web3 = window[WEB3];
amount1 = web3.utils.toWei(amount1);
return (new web3.utils.BN(amount1)).lt(new web3.utils.BN(amount2));
}
}