hive-keychain-commons 1.7.1 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/interfaces/global-properties.d.ts +18 -0
- package/lib/interfaces/global-properties.js +2 -0
- package/lib/interfaces/keychain.d.ts +5 -0
- package/lib/interfaces/keychain.js +7 -1
- package/lib/interfaces/price.d.ts +9 -0
- package/lib/interfaces/price.js +2 -0
- package/lib/interfaces/tokens.d.ts +5 -0
- package/lib/interfaces/tokens.js +9 -0
- package/lib/interfaces/vsc.d.ts +50 -29
- package/lib/interfaces/vsc.js +11 -11
- package/lib/utils/format.utils.d.ts +24 -0
- package/lib/utils/format.utils.js +160 -0
- package/lib/utils/vsc.utils.d.ts +38 -2
- package/lib/utils/vsc.utils.js +151 -43
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
export * from './interfaces/global-properties';
|
|
1
2
|
export * from './interfaces/keychain';
|
|
3
|
+
export * from './interfaces/price';
|
|
4
|
+
export * from './interfaces/tokens';
|
|
2
5
|
export * from './interfaces/vsc';
|
|
3
6
|
export { LeaseKeys } from './lease-market/lease-keys';
|
|
4
7
|
export { AcceptRequestJSON, CancelDelegationJSON, CancelRequestJSON, PaymentJSON, ReimbursmentJSON, RequestCancelRequestJSON, RequestJSON, } from './lease-market/lease-market.interface';
|
|
@@ -8,6 +11,7 @@ export * from './swaps/swap.interface';
|
|
|
8
11
|
export * from './utils/assets.utils';
|
|
9
12
|
export * from './utils/crypto.utils';
|
|
10
13
|
export * from './utils/export-transactions.utils';
|
|
14
|
+
export * from './utils/format.utils';
|
|
11
15
|
export * from './utils/history-filters.utils';
|
|
12
16
|
export * from './utils/keys.utils';
|
|
13
17
|
export * from './utils/transaction.utils';
|
package/lib/index.js
CHANGED
|
@@ -15,7 +15,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.LeaseKeys = void 0;
|
|
18
|
+
__exportStar(require("./interfaces/global-properties"), exports);
|
|
18
19
|
__exportStar(require("./interfaces/keychain"), exports);
|
|
20
|
+
__exportStar(require("./interfaces/price"), exports);
|
|
21
|
+
__exportStar(require("./interfaces/tokens"), exports);
|
|
19
22
|
__exportStar(require("./interfaces/vsc"), exports);
|
|
20
23
|
var lease_keys_1 = require("./lease-market/lease-keys");
|
|
21
24
|
Object.defineProperty(exports, "LeaseKeys", { enumerable: true, get: function () { return lease_keys_1.LeaseKeys; } });
|
|
@@ -25,6 +28,7 @@ __exportStar(require("./swaps/swap.interface"), exports);
|
|
|
25
28
|
__exportStar(require("./utils/assets.utils"), exports);
|
|
26
29
|
__exportStar(require("./utils/crypto.utils"), exports);
|
|
27
30
|
__exportStar(require("./utils/export-transactions.utils"), exports);
|
|
31
|
+
__exportStar(require("./utils/format.utils"), exports);
|
|
28
32
|
__exportStar(require("./utils/history-filters.utils"), exports);
|
|
29
33
|
__exportStar(require("./utils/keys.utils"), exports);
|
|
30
34
|
__exportStar(require("./utils/transaction.utils"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DynamicGlobalProperties, Price } from '@hiveio/dhive';
|
|
2
|
+
export interface RewardFund {
|
|
3
|
+
author_reward_curve: string;
|
|
4
|
+
content_constant: string;
|
|
5
|
+
curation_reward_curve: string;
|
|
6
|
+
id: number;
|
|
7
|
+
last_update: string;
|
|
8
|
+
name: string;
|
|
9
|
+
percent_content_rewards: number;
|
|
10
|
+
percent_curation_rewards: number;
|
|
11
|
+
recent_claims: string;
|
|
12
|
+
reward_balance: string;
|
|
13
|
+
}
|
|
14
|
+
export interface GlobalProperties {
|
|
15
|
+
globals?: DynamicGlobalProperties;
|
|
16
|
+
price?: Price;
|
|
17
|
+
rewardFund?: RewardFund;
|
|
18
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KeychainKeyTypesLC = exports.KeychainKeyTypes = exports.KeychainRequestTypes = void 0;
|
|
3
|
+
exports.LoadingState = exports.KeychainKeyTypesLC = exports.KeychainKeyTypes = exports.KeychainRequestTypes = void 0;
|
|
4
4
|
var KeychainRequestTypes;
|
|
5
5
|
(function (KeychainRequestTypes) {
|
|
6
6
|
KeychainRequestTypes["decode"] = "decode";
|
|
@@ -50,3 +50,9 @@ var KeychainKeyTypesLC;
|
|
|
50
50
|
KeychainKeyTypesLC["active"] = "active";
|
|
51
51
|
KeychainKeyTypesLC["memo"] = "memo";
|
|
52
52
|
})(KeychainKeyTypesLC = exports.KeychainKeyTypesLC || (exports.KeychainKeyTypesLC = {}));
|
|
53
|
+
var LoadingState;
|
|
54
|
+
(function (LoadingState) {
|
|
55
|
+
LoadingState[LoadingState["LOADING"] = 0] = "LOADING";
|
|
56
|
+
LoadingState[LoadingState["LOADED"] = 1] = "LOADED";
|
|
57
|
+
LoadingState[LoadingState["FAILED"] = 2] = "FAILED";
|
|
58
|
+
})(LoadingState = exports.LoadingState || (exports.LoadingState = {}));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenType = void 0;
|
|
4
|
+
var TokenType;
|
|
5
|
+
(function (TokenType) {
|
|
6
|
+
TokenType["HIVE"] = "HIVE";
|
|
7
|
+
TokenType["HIVE_ENGINE"] = "HIVE_ENGINE";
|
|
8
|
+
TokenType["VSC"] = "VSC";
|
|
9
|
+
})(TokenType = exports.TokenType || (exports.TokenType = {}));
|
package/lib/interfaces/vsc.d.ts
CHANGED
|
@@ -6,15 +6,11 @@ export declare enum VscStatus {
|
|
|
6
6
|
}
|
|
7
7
|
export declare enum VscHistoryType {
|
|
8
8
|
CONTRACT_CALL = "CONTRACT_CALL",
|
|
9
|
-
TRANSFER = "
|
|
10
|
-
DEPOSIT = "
|
|
11
|
-
WITHDRAW = "WITHDRAW",
|
|
12
|
-
STAKING = "STAKING",
|
|
13
|
-
UNSTAKING = "UNSTAKING"
|
|
14
|
-
}
|
|
15
|
-
export declare enum VscLedgerType {
|
|
9
|
+
TRANSFER = "transfer",
|
|
10
|
+
DEPOSIT = "deposit",
|
|
16
11
|
WITHDRAW = "withdraw",
|
|
17
|
-
|
|
12
|
+
STAKING = "stake_hbd",
|
|
13
|
+
UNSTAKING = "unstake_hbd"
|
|
18
14
|
}
|
|
19
15
|
export declare enum VscToken {
|
|
20
16
|
HIVE = "HIVE",
|
|
@@ -28,39 +24,64 @@ export type VscRequestParams = {
|
|
|
28
24
|
netId?: string;
|
|
29
25
|
};
|
|
30
26
|
export type VscHistoryResponse = {
|
|
31
|
-
findLedgerTXs:
|
|
32
|
-
|
|
33
|
-
};
|
|
34
|
-
findTransaction: {
|
|
35
|
-
txs: VscCall[];
|
|
36
|
-
};
|
|
27
|
+
findLedgerTXs: VscLedgerTxResponse[];
|
|
28
|
+
findTransaction: VscTxResponse[];
|
|
37
29
|
};
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
declare enum VscAsset {
|
|
31
|
+
HIVE = "hive",
|
|
32
|
+
HBD = "hbd"
|
|
33
|
+
}
|
|
34
|
+
export type VscLedgerTxResponse = {
|
|
40
35
|
amount: number;
|
|
41
36
|
block_height: number;
|
|
42
37
|
from: string;
|
|
43
38
|
id: string;
|
|
44
|
-
memo: string | null;
|
|
45
39
|
owner: string;
|
|
46
|
-
t: VscLedgerType;
|
|
47
|
-
tk: VscToken;
|
|
48
40
|
timestamp: Date;
|
|
49
|
-
|
|
41
|
+
asset: VscAsset;
|
|
42
|
+
tx_id: string;
|
|
43
|
+
type: string;
|
|
50
44
|
};
|
|
51
|
-
export type
|
|
52
|
-
type?: VscHistoryType.CONTRACT_CALL;
|
|
45
|
+
export type VscTxResponse = {
|
|
53
46
|
status: VscStatus;
|
|
54
47
|
id: string;
|
|
55
|
-
|
|
48
|
+
anchr_height: number;
|
|
56
49
|
timestamp: Date;
|
|
57
|
-
data:
|
|
58
|
-
action: string;
|
|
59
|
-
contract_id: string;
|
|
60
|
-
op: string;
|
|
61
|
-
payload: object;
|
|
62
|
-
};
|
|
50
|
+
data: VscTxData;
|
|
63
51
|
required_auths: {
|
|
64
52
|
value: string;
|
|
65
53
|
}[];
|
|
54
|
+
anchr_index: number;
|
|
55
|
+
anchr_opidx: number;
|
|
56
|
+
anchr_ts: Date;
|
|
57
|
+
first_seen: Date;
|
|
58
|
+
ledger: any[];
|
|
59
|
+
nonce: number;
|
|
60
|
+
rc_limit: number;
|
|
61
|
+
type: string;
|
|
62
|
+
};
|
|
63
|
+
export type VscTxData = {
|
|
64
|
+
amount: number;
|
|
65
|
+
asset: VscAsset;
|
|
66
|
+
from: string;
|
|
67
|
+
memo?: string;
|
|
68
|
+
to: string;
|
|
69
|
+
type: VscHistoryType;
|
|
70
|
+
};
|
|
71
|
+
export type VscHistoryItem = VscTxData & {
|
|
72
|
+
timestamp: Date;
|
|
73
|
+
status: VscStatus;
|
|
74
|
+
txId: string;
|
|
75
|
+
};
|
|
76
|
+
export type VscAccountBalance = {
|
|
77
|
+
account: string;
|
|
78
|
+
block_height: number;
|
|
79
|
+
hbd: number;
|
|
80
|
+
hbd_avg: number;
|
|
81
|
+
hbd_claim: number;
|
|
82
|
+
hbd_modify: number;
|
|
83
|
+
hbd_savings: number;
|
|
84
|
+
hive: number;
|
|
85
|
+
hive_consensus: number;
|
|
66
86
|
};
|
|
87
|
+
export {};
|
package/lib/interfaces/vsc.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VscStakingOperation = exports.VscToken = exports.
|
|
3
|
+
exports.VscStakingOperation = exports.VscToken = exports.VscHistoryType = exports.VscStatus = void 0;
|
|
4
4
|
var VscStatus;
|
|
5
5
|
(function (VscStatus) {
|
|
6
6
|
VscStatus["UNCONFIRMED"] = "UNCONFIRMED";
|
|
@@ -11,17 +11,12 @@ var VscStatus;
|
|
|
11
11
|
var VscHistoryType;
|
|
12
12
|
(function (VscHistoryType) {
|
|
13
13
|
VscHistoryType["CONTRACT_CALL"] = "CONTRACT_CALL";
|
|
14
|
-
VscHistoryType["TRANSFER"] = "
|
|
15
|
-
VscHistoryType["DEPOSIT"] = "
|
|
16
|
-
VscHistoryType["WITHDRAW"] = "
|
|
17
|
-
VscHistoryType["STAKING"] = "
|
|
18
|
-
VscHistoryType["UNSTAKING"] = "
|
|
14
|
+
VscHistoryType["TRANSFER"] = "transfer";
|
|
15
|
+
VscHistoryType["DEPOSIT"] = "deposit";
|
|
16
|
+
VscHistoryType["WITHDRAW"] = "withdraw";
|
|
17
|
+
VscHistoryType["STAKING"] = "stake_hbd";
|
|
18
|
+
VscHistoryType["UNSTAKING"] = "unstake_hbd";
|
|
19
19
|
})(VscHistoryType = exports.VscHistoryType || (exports.VscHistoryType = {}));
|
|
20
|
-
var VscLedgerType;
|
|
21
|
-
(function (VscLedgerType) {
|
|
22
|
-
VscLedgerType["WITHDRAW"] = "withdraw";
|
|
23
|
-
VscLedgerType["DEPOSIT"] = "deposit";
|
|
24
|
-
})(VscLedgerType = exports.VscLedgerType || (exports.VscLedgerType = {}));
|
|
25
20
|
var VscToken;
|
|
26
21
|
(function (VscToken) {
|
|
27
22
|
VscToken["HIVE"] = "HIVE";
|
|
@@ -32,3 +27,8 @@ var VscStakingOperation;
|
|
|
32
27
|
VscStakingOperation["STAKING"] = "STAKING";
|
|
33
28
|
VscStakingOperation["UNSTAKING"] = "UNSTAKING";
|
|
34
29
|
})(VscStakingOperation = exports.VscStakingOperation || (exports.VscStakingOperation = {}));
|
|
30
|
+
var VscAsset;
|
|
31
|
+
(function (VscAsset) {
|
|
32
|
+
VscAsset["HIVE"] = "hive";
|
|
33
|
+
VscAsset["HBD"] = "hbd";
|
|
34
|
+
})(VscAsset || (VscAsset = {}));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DynamicGlobalProperties } from '@hiveio/dhive';
|
|
2
|
+
import { Asset } from '..';
|
|
3
|
+
import { GlobalProperties } from '../interfaces/global-properties';
|
|
4
|
+
import { CurrencyPrices } from '../interfaces/price';
|
|
5
|
+
export declare const FormatUtils: {
|
|
6
|
+
withCommas: (nb: string, decimals?: number, removeTrailingZeros?: boolean) => string;
|
|
7
|
+
toHP: (vests: string, props?: DynamicGlobalProperties) => number;
|
|
8
|
+
toFormattedHP: (vests: number, props?: DynamicGlobalProperties) => string;
|
|
9
|
+
fromHP: (hp: string, props: DynamicGlobalProperties) => number;
|
|
10
|
+
formatCurrencyValue: (value: string | Asset | number, digits?: number, removeTrailingZeros?: boolean) => string;
|
|
11
|
+
nFormatter: (num: number, digits: number) => string;
|
|
12
|
+
hasMoreThanXDecimal: (nb: number, decimal: number) => boolean;
|
|
13
|
+
toNumber: (value: string | Asset) => number;
|
|
14
|
+
getSymbol: (nai: string) => "HIVE" | "HBD" | "HP" | undefined;
|
|
15
|
+
getAmountFromNai: (obj: any) => number;
|
|
16
|
+
fromNaiAndSymbol: (obj: any) => string;
|
|
17
|
+
removeHtmlTags: (str: string) => string;
|
|
18
|
+
getValFromString: (str: string) => number;
|
|
19
|
+
trimUselessZero: (nb: number, precision: number) => string;
|
|
20
|
+
getUSDFromVests: (vestAmount: number, globalProperties: GlobalProperties, currencyPrices: CurrencyPrices) => string;
|
|
21
|
+
getOrdinalLabelTranslation: (activeRank: string) => "html_popup_witness_ranking_ordinal_st_label" | "html_popup_witness_ranking_ordinal_nd_label" | "html_popup_witness_ranking_ordinal_rd_label" | "html_popup_witness_ranking_ordinal_th_label";
|
|
22
|
+
dateToFormattedString: (date: Date) => string;
|
|
23
|
+
shortenString: (str: string, length?: number) => string;
|
|
24
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FormatUtils = void 0;
|
|
7
|
+
const moment_1 = __importDefault(require("moment"));
|
|
8
|
+
const __1 = require("..");
|
|
9
|
+
const withCommas = (nb, decimals = 3, removeTrailingZeros = false) => {
|
|
10
|
+
const currency = nb.split(' ')[1];
|
|
11
|
+
const value = parseFloat(nb).toFixed(decimals);
|
|
12
|
+
const parts = value.split('.');
|
|
13
|
+
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
14
|
+
let finalNumber = parts.join('.');
|
|
15
|
+
if (removeTrailingZeros) {
|
|
16
|
+
finalNumber = finalNumber.replace(/^([\d,]+)$|^([\d,]+)\.0*$|^([\d,]+\.[0-9]*?)0*$/, '$1$2$3');
|
|
17
|
+
}
|
|
18
|
+
if (currency) {
|
|
19
|
+
finalNumber = finalNumber + ' ' + currency;
|
|
20
|
+
}
|
|
21
|
+
return finalNumber;
|
|
22
|
+
};
|
|
23
|
+
const toHP = (vests, props) => props
|
|
24
|
+
? (parseFloat(vests) * parseFloat(props.total_vesting_fund_hive + '')) /
|
|
25
|
+
parseFloat(props.total_vesting_shares + '')
|
|
26
|
+
: 0;
|
|
27
|
+
const toFormattedHP = (vests, props) => {
|
|
28
|
+
return `${toHP(vests.toString(), props).toFixed(3)} HP`;
|
|
29
|
+
};
|
|
30
|
+
const fromHP = (hp, props) => (parseFloat(hp) / parseFloat(props.total_vesting_fund_hive + '')) *
|
|
31
|
+
parseFloat(props.total_vesting_shares + '');
|
|
32
|
+
const formatCurrencyValue = (value, digits = 3, removeTrailingZeros = false) => {
|
|
33
|
+
if (value === undefined || value === null) {
|
|
34
|
+
return '...';
|
|
35
|
+
}
|
|
36
|
+
return withCommas(value.toString().replace('HBD', '').replace('HIVE', '').trim(), digits, removeTrailingZeros);
|
|
37
|
+
};
|
|
38
|
+
const nFormatter = (num, digits) => {
|
|
39
|
+
const si = [
|
|
40
|
+
{
|
|
41
|
+
value: 1,
|
|
42
|
+
symbol: '',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
value: 1e3,
|
|
46
|
+
symbol: 'k',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
value: 1e6,
|
|
50
|
+
symbol: 'M',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
value: 1e9,
|
|
54
|
+
symbol: 'G',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
value: 1e12,
|
|
58
|
+
symbol: 'T',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
value: 1e15,
|
|
62
|
+
symbol: 'P',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
value: 1e18,
|
|
66
|
+
symbol: 'E',
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
|
|
70
|
+
let i;
|
|
71
|
+
for (i = si.length - 1; i > 0; i--) {
|
|
72
|
+
if (num >= si[i].value) {
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return (num / si[i].value).toFixed(digits).replace(rx, '$1') + si[i].symbol;
|
|
77
|
+
};
|
|
78
|
+
const hasMoreThanXDecimal = (nb, decimal) => {
|
|
79
|
+
const splitedNumber = nb.toString().split('.');
|
|
80
|
+
return splitedNumber.length > 1 ? splitedNumber[1].length > decimal : false;
|
|
81
|
+
};
|
|
82
|
+
const toNumber = (value) => {
|
|
83
|
+
return parseFloat(value.toString().split(' ')[0].trim());
|
|
84
|
+
};
|
|
85
|
+
const getSymbol = (nai) => {
|
|
86
|
+
if (nai === '@@000000013')
|
|
87
|
+
return 'HBD';
|
|
88
|
+
if (nai === '@@000000021')
|
|
89
|
+
return 'HIVE';
|
|
90
|
+
if (nai === '@@000000037')
|
|
91
|
+
return 'HP';
|
|
92
|
+
};
|
|
93
|
+
const fromNaiAndSymbol = (obj) => {
|
|
94
|
+
return `${(obj.amount / 1000).toFixed(obj.precision)} ${exports.FormatUtils.getSymbol(obj.nai)}`;
|
|
95
|
+
};
|
|
96
|
+
const getAmountFromNai = (obj) => {
|
|
97
|
+
const res = fromNaiAndSymbol(obj);
|
|
98
|
+
return __1.Asset.fromString(res).amount;
|
|
99
|
+
};
|
|
100
|
+
const removeHtmlTags = (str) => {
|
|
101
|
+
return str.replace(/<(?:.|\n)*?>/gm, '');
|
|
102
|
+
};
|
|
103
|
+
const getValFromString = (str) => {
|
|
104
|
+
return parseFloat(str.split(' ')[0]);
|
|
105
|
+
};
|
|
106
|
+
const trimUselessZero = (nb, precision) => {
|
|
107
|
+
var _a;
|
|
108
|
+
const numberWithPrecision = nb.toFixed(precision);
|
|
109
|
+
const n = parseFloat(numberWithPrecision).toString();
|
|
110
|
+
if (n.split('.').length > 0 && ((_a = n.split('.')[1]) === null || _a === void 0 ? void 0 : _a.length) > 3)
|
|
111
|
+
return exports.FormatUtils.withCommas(n);
|
|
112
|
+
else
|
|
113
|
+
return exports.FormatUtils.withCommas(parseFloat(n).toFixed(3));
|
|
114
|
+
};
|
|
115
|
+
const getUSDFromVests = (vestAmount, globalProperties, currencyPrices) => {
|
|
116
|
+
return (exports.FormatUtils.toHP(vestAmount.toString(), globalProperties.globals) *
|
|
117
|
+
currencyPrices.hive.usd).toFixed(2);
|
|
118
|
+
};
|
|
119
|
+
const getOrdinalLabelTranslation = (activeRank) => {
|
|
120
|
+
const result = parseFloat(activeRank) % 10;
|
|
121
|
+
switch (result) {
|
|
122
|
+
case 1:
|
|
123
|
+
return 'html_popup_witness_ranking_ordinal_st_label';
|
|
124
|
+
case 2:
|
|
125
|
+
return 'html_popup_witness_ranking_ordinal_nd_label';
|
|
126
|
+
case 3:
|
|
127
|
+
return 'html_popup_witness_ranking_ordinal_rd_label';
|
|
128
|
+
default:
|
|
129
|
+
return 'html_popup_witness_ranking_ordinal_th_label';
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
const dateToFormattedString = (date) => {
|
|
133
|
+
return (0, moment_1.default)(date).format('MM/DD/YY');
|
|
134
|
+
};
|
|
135
|
+
const shortenString = (str, length = 3) => {
|
|
136
|
+
// TODO : remove during merge EVM (duplicate)
|
|
137
|
+
return (str === null || str === void 0 ? void 0 : str.length) > length * 2
|
|
138
|
+
? `${str.substring(length, 0)}...${str === null || str === void 0 ? void 0 : str.toString().slice(-length)}`
|
|
139
|
+
: str;
|
|
140
|
+
};
|
|
141
|
+
exports.FormatUtils = {
|
|
142
|
+
withCommas,
|
|
143
|
+
toHP,
|
|
144
|
+
toFormattedHP,
|
|
145
|
+
fromHP,
|
|
146
|
+
formatCurrencyValue,
|
|
147
|
+
nFormatter,
|
|
148
|
+
hasMoreThanXDecimal,
|
|
149
|
+
toNumber,
|
|
150
|
+
getSymbol,
|
|
151
|
+
getAmountFromNai,
|
|
152
|
+
fromNaiAndSymbol,
|
|
153
|
+
removeHtmlTags,
|
|
154
|
+
getValFromString,
|
|
155
|
+
trimUselessZero,
|
|
156
|
+
getUSDFromVests,
|
|
157
|
+
getOrdinalLabelTranslation,
|
|
158
|
+
dateToFormattedString,
|
|
159
|
+
shortenString,
|
|
160
|
+
};
|
package/lib/utils/vsc.utils.d.ts
CHANGED
|
@@ -1,7 +1,43 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RequestVscStaking, RequestVscTransfer, RequestVscWithdrawal } from '../interfaces/keychain';
|
|
2
|
+
import { VscHistoryItem, VscHistoryType, VscStatus } from '../interfaces/vsc';
|
|
2
3
|
export declare const VscUtils: {
|
|
3
4
|
checkStatus: (id: string, type: VscHistoryType) => Promise<VscStatus>;
|
|
4
5
|
waitForStatus: (id: string, type: VscHistoryType, maxIterations?: number, wait?: number) => Promise<VscStatus>;
|
|
5
|
-
getOrganizedHistory: (username: string) => Promise<
|
|
6
|
+
getOrganizedHistory: (username: string) => Promise<VscHistoryItem[]>;
|
|
6
7
|
getAddressFromDid: (did: string) => string | undefined;
|
|
8
|
+
getAccountBalance: (username: string) => Promise<any>;
|
|
9
|
+
blockHeightToTimestamp: (height: number) => Date;
|
|
10
|
+
getFormattedAddress: (address: string) => string;
|
|
11
|
+
getWithdrawJson: (data: Omit<RequestVscWithdrawal, 'domain' | 'type'>, netId?: string) => {
|
|
12
|
+
id: string;
|
|
13
|
+
json: {
|
|
14
|
+
net_id: string | undefined;
|
|
15
|
+
from: string | undefined;
|
|
16
|
+
to: string;
|
|
17
|
+
amount: string;
|
|
18
|
+
asset: string;
|
|
19
|
+
memo: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
getTransferJson: (data: Omit<RequestVscTransfer, 'domain' | 'type'>, netId?: string) => {
|
|
23
|
+
id: string;
|
|
24
|
+
json: {
|
|
25
|
+
net_id: string | undefined;
|
|
26
|
+
from: string | undefined;
|
|
27
|
+
to: string;
|
|
28
|
+
amount: string;
|
|
29
|
+
asset: string;
|
|
30
|
+
memo: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
getStakingJson: (data: Omit<RequestVscStaking, 'domain' | 'type'>, netId?: string) => {
|
|
34
|
+
id: string;
|
|
35
|
+
json: {
|
|
36
|
+
net_id: string | undefined;
|
|
37
|
+
from: string | undefined;
|
|
38
|
+
to: string;
|
|
39
|
+
amount: string;
|
|
40
|
+
asset: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
7
43
|
};
|
package/lib/utils/vsc.utils.js
CHANGED
|
@@ -16,6 +16,7 @@ exports.VscUtils = void 0;
|
|
|
16
16
|
const moment_1 = __importDefault(require("moment"));
|
|
17
17
|
const config_1 = __importDefault(require("../config"));
|
|
18
18
|
const vsc_1 = require("../interfaces/vsc");
|
|
19
|
+
const format_utils_1 = require("./format.utils");
|
|
19
20
|
const waitForStatus = (id, type, maxIterations = 20, wait = 500) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
21
|
let iterations = 0;
|
|
21
22
|
let status = vsc_1.VscStatus.UNCONFIRMED;
|
|
@@ -45,49 +46,57 @@ const checkStatus = (id, type) => {
|
|
|
45
46
|
}
|
|
46
47
|
else if (type === vsc_1.VscHistoryType.DEPOSIT) {
|
|
47
48
|
query = `{
|
|
48
|
-
findLedgerTXs(filterOptions: {byTxId: "${id}
|
|
49
|
+
findLedgerTXs(filterOptions: {byTxId: "${id}"}) {
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
id
|
|
51
52
|
|
|
52
53
|
}
|
|
53
54
|
}`;
|
|
54
55
|
}
|
|
55
56
|
return fetchQuery(query).then((res) => {
|
|
56
57
|
var _a, _b, _c, _d, _e, _f;
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
if ((_b = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.findTransaction) === null || _b === void 0 ? void 0 : _b[0])
|
|
59
|
+
return (_c = res.data.findTransaction) === null || _c === void 0 ? void 0 : _c[0].status;
|
|
60
|
+
return ((_f = (_e = (_d = res === null || res === void 0 ? void 0 : res.data) === null || _d === void 0 ? void 0 : _d.findLedgerTXs) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.id) === id
|
|
61
|
+
? vsc_1.VscStatus.CONFIRMED
|
|
62
|
+
: vsc_1.VscStatus.UNCONFIRMED;
|
|
59
63
|
});
|
|
60
64
|
};
|
|
61
65
|
const fetchHistory = (username) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
66
|
const query = `{
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
67
|
+
# findLedgerTXs(filterOptions: {byToFrom: "hive:${username}",byTypes: "deposit"}) {
|
|
68
|
+
# amount
|
|
69
|
+
# asset
|
|
70
|
+
# block_height
|
|
71
|
+
# from
|
|
72
|
+
# id
|
|
73
|
+
# owner
|
|
74
|
+
# timestamp
|
|
75
|
+
# tx_id
|
|
76
|
+
# type
|
|
77
|
+
# }
|
|
78
|
+
findTransaction(filterOptions: {byLedgerToFrom: "hive:${username}"}) {
|
|
79
|
+
anchr_height
|
|
80
|
+
anchr_index
|
|
81
|
+
anchr_opidx
|
|
82
|
+
anchr_ts
|
|
83
|
+
data
|
|
84
|
+
first_seen
|
|
85
|
+
id
|
|
86
|
+
ledger {
|
|
87
|
+
amount
|
|
88
|
+
asset
|
|
89
|
+
from
|
|
90
|
+
memo
|
|
91
|
+
params
|
|
92
|
+
to
|
|
93
|
+
type
|
|
77
94
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
data {
|
|
84
|
-
action
|
|
85
|
-
contract_id
|
|
86
|
-
op
|
|
87
|
-
payload
|
|
88
|
-
}
|
|
89
|
-
required_auths{value}
|
|
90
|
-
}
|
|
95
|
+
nonce
|
|
96
|
+
rc_limit
|
|
97
|
+
required_auths
|
|
98
|
+
status
|
|
99
|
+
type
|
|
91
100
|
}}
|
|
92
101
|
`;
|
|
93
102
|
return (yield fetchQuery(query)).data;
|
|
@@ -95,18 +104,37 @@ const fetchHistory = (username) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
95
104
|
const getOrganizedHistory = (username) => __awaiter(void 0, void 0, void 0, function* () {
|
|
96
105
|
const history = yield fetchHistory(username);
|
|
97
106
|
const organizedHistory = [
|
|
98
|
-
...history.findLedgerTXs
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
// ...(history.findLedgerTXs || [])
|
|
108
|
+
// .map((e) => {
|
|
109
|
+
// return {
|
|
110
|
+
// from: e.from,
|
|
111
|
+
// to: e.owner,
|
|
112
|
+
// amount: e.amount,
|
|
113
|
+
// timestamp: new Date(e.timestamp + 'Z'),
|
|
114
|
+
// txId: e.id,
|
|
115
|
+
// asset: e.asset,
|
|
116
|
+
// status: VscStatus.CONFIRMED,
|
|
117
|
+
// type: VscHistoryType.DEPOSIT,
|
|
118
|
+
// };
|
|
119
|
+
// })
|
|
120
|
+
// .filter((e) => e.to === `hive:${username}`),
|
|
121
|
+
...(history.findTransaction || [])
|
|
122
|
+
.map((e) => {
|
|
123
|
+
return {
|
|
124
|
+
from: e.data.from,
|
|
125
|
+
to: e.data.to,
|
|
126
|
+
amount: e.data.amount,
|
|
127
|
+
timestamp: e.first_seen,
|
|
128
|
+
txId: e.id,
|
|
129
|
+
memo: e.data.memo,
|
|
130
|
+
asset: e.data.asset,
|
|
131
|
+
status: e.status,
|
|
132
|
+
type: e.data.type,
|
|
133
|
+
};
|
|
134
|
+
})
|
|
135
|
+
.filter((e) => !(e.type === 'withdraw' && e.from !== `hive:${username}`)),
|
|
108
136
|
].sort((a, b) => {
|
|
109
|
-
return b.timestamp.getTime() - a.timestamp.getTime();
|
|
137
|
+
return new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime();
|
|
110
138
|
});
|
|
111
139
|
return organizedHistory;
|
|
112
140
|
});
|
|
@@ -118,10 +146,16 @@ const blockHeightToTimestamp = (height) => {
|
|
|
118
146
|
.toDate();
|
|
119
147
|
};
|
|
120
148
|
const getAddressFromDid = (did) => {
|
|
121
|
-
const regex = new RegExp(':([a-zA-Z0-9]*)$');
|
|
149
|
+
const regex = new RegExp(':([a-zA-Z0-9.-]*)$');
|
|
122
150
|
const matches = did.match(regex);
|
|
123
151
|
return matches === null || matches === void 0 ? void 0 : matches[matches.length - 1];
|
|
124
152
|
};
|
|
153
|
+
const getFormattedAddress = (address) => {
|
|
154
|
+
if (address.startsWith('hive:'))
|
|
155
|
+
return `@${getAddressFromDid(address)}`;
|
|
156
|
+
else
|
|
157
|
+
return format_utils_1.FormatUtils.shortenString(getAddressFromDid(address), 4);
|
|
158
|
+
};
|
|
125
159
|
const fetchQuery = (query) => {
|
|
126
160
|
return fetch(config_1.default.vsc.API_URL, {
|
|
127
161
|
method: 'POST',
|
|
@@ -133,9 +167,83 @@ const fetchQuery = (query) => {
|
|
|
133
167
|
}),
|
|
134
168
|
}).then((res) => res.json());
|
|
135
169
|
};
|
|
170
|
+
const getAccountBalance = (username) => __awaiter(void 0, void 0, void 0, function* () {
|
|
171
|
+
const query = `{
|
|
172
|
+
getAccountBalance(account: "hive:${username}") {
|
|
173
|
+
account
|
|
174
|
+
hbd
|
|
175
|
+
hive
|
|
176
|
+
hbd_savings
|
|
177
|
+
hbd_claim
|
|
178
|
+
hbd_modify
|
|
179
|
+
hbd_avg
|
|
180
|
+
block_height
|
|
181
|
+
hive_consensus
|
|
182
|
+
}
|
|
183
|
+
}`;
|
|
184
|
+
return (yield fetchQuery(query)).data.getAccountBalance;
|
|
185
|
+
});
|
|
186
|
+
const getWithdrawJson = (data, netId) => {
|
|
187
|
+
const JSON_ID = 'vsc.withdraw';
|
|
188
|
+
const json = {
|
|
189
|
+
net_id: data.netId || netId,
|
|
190
|
+
from: data.username.startsWith('hive:')
|
|
191
|
+
? data.username
|
|
192
|
+
: `hive:${data.username}`,
|
|
193
|
+
to: data.to.startsWith('hive:') ? data.to : `hive:${data.to}`,
|
|
194
|
+
amount: data.amount,
|
|
195
|
+
asset: data.currency.toLowerCase(),
|
|
196
|
+
memo: data.memo,
|
|
197
|
+
};
|
|
198
|
+
return {
|
|
199
|
+
id: JSON_ID,
|
|
200
|
+
json,
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
const getTransferJson = (data, netId) => {
|
|
204
|
+
const JSON_ID = 'vsc.transfer';
|
|
205
|
+
const json = {
|
|
206
|
+
net_id: data.netId || netId,
|
|
207
|
+
from: data.username.startsWith('hive:')
|
|
208
|
+
? data.username
|
|
209
|
+
: `hive:${data.username}`,
|
|
210
|
+
to: data.to.startsWith('hive:') ? data.to : `hive:${data.to}`,
|
|
211
|
+
amount: data.amount,
|
|
212
|
+
asset: data.currency.toLowerCase(),
|
|
213
|
+
memo: data.memo,
|
|
214
|
+
};
|
|
215
|
+
return {
|
|
216
|
+
id: JSON_ID,
|
|
217
|
+
json,
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
const getStakingJson = (data, netId) => {
|
|
221
|
+
const JSON_ID = data.operation === vsc_1.VscStakingOperation.STAKING
|
|
222
|
+
? 'vsc.stake_hbd'
|
|
223
|
+
: 'vsc.unstake_hbd';
|
|
224
|
+
const json = {
|
|
225
|
+
net_id: data.netId || netId,
|
|
226
|
+
from: data.username.startsWith('hive:')
|
|
227
|
+
? data.username
|
|
228
|
+
: `hive:${data.username}`,
|
|
229
|
+
to: data.to.startsWith('hive:') ? data.to : `hive:${data.to}`,
|
|
230
|
+
amount: data.amount,
|
|
231
|
+
asset: data.currency.toLowerCase(),
|
|
232
|
+
};
|
|
233
|
+
return {
|
|
234
|
+
id: JSON_ID,
|
|
235
|
+
json,
|
|
236
|
+
};
|
|
237
|
+
};
|
|
136
238
|
exports.VscUtils = {
|
|
137
239
|
checkStatus,
|
|
138
240
|
waitForStatus,
|
|
139
241
|
getOrganizedHistory,
|
|
140
242
|
getAddressFromDid,
|
|
243
|
+
getAccountBalance,
|
|
244
|
+
blockHeightToTimestamp,
|
|
245
|
+
getFormattedAddress,
|
|
246
|
+
getWithdrawJson,
|
|
247
|
+
getTransferJson,
|
|
248
|
+
getStakingJson,
|
|
141
249
|
};
|