hive-keychain-commons 1.9.0 → 1.9.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/interfaces/vsc.d.ts +19 -11
- package/lib/utils/vsc.utils.js +43 -66
- package/package.json +1 -1
package/lib/interfaces/vsc.d.ts
CHANGED
|
@@ -24,8 +24,8 @@ export type VscRequestParams = {
|
|
|
24
24
|
netId?: string;
|
|
25
25
|
};
|
|
26
26
|
export type VscHistoryResponse = {
|
|
27
|
-
findLedgerTXs: VscLedgerTxResponse[];
|
|
28
27
|
findTransaction: VscTxResponse[];
|
|
28
|
+
findLedgerTXs: VscLedgerTxResponse[];
|
|
29
29
|
};
|
|
30
30
|
declare enum VscAsset {
|
|
31
31
|
HIVE = "hive",
|
|
@@ -46,19 +46,26 @@ export type VscTxResponse = {
|
|
|
46
46
|
status: VscStatus;
|
|
47
47
|
id: string;
|
|
48
48
|
anchr_height: number;
|
|
49
|
-
timestamp: Date;
|
|
50
|
-
data: VscTxData;
|
|
51
|
-
required_auths: {
|
|
52
|
-
value: string;
|
|
53
|
-
}[];
|
|
54
49
|
anchr_index: number;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
anchr_ts: string;
|
|
51
|
+
type: string;
|
|
52
|
+
op_types: string[];
|
|
53
|
+
first_seen: string;
|
|
59
54
|
nonce: number;
|
|
60
55
|
rc_limit: number;
|
|
61
|
-
|
|
56
|
+
required_auths: string[];
|
|
57
|
+
ops: {
|
|
58
|
+
required_auths: string[];
|
|
59
|
+
type: string;
|
|
60
|
+
index: number;
|
|
61
|
+
data: {
|
|
62
|
+
amount: string;
|
|
63
|
+
asset: VscAsset;
|
|
64
|
+
from: string;
|
|
65
|
+
memo: string;
|
|
66
|
+
to: string;
|
|
67
|
+
};
|
|
68
|
+
}[];
|
|
62
69
|
};
|
|
63
70
|
export type VscTxData = {
|
|
64
71
|
amount: number;
|
|
@@ -83,5 +90,6 @@ export type VscAccountBalance = {
|
|
|
83
90
|
hbd_savings: number;
|
|
84
91
|
hive: number;
|
|
85
92
|
hive_consensus: number;
|
|
93
|
+
pending_hbd_unstaking: number;
|
|
86
94
|
};
|
|
87
95
|
export {};
|
package/lib/utils/vsc.utils.js
CHANGED
|
@@ -50,74 +50,48 @@ const checkStatus = (id) => {
|
|
|
50
50
|
};
|
|
51
51
|
const fetchHistory = (username) => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
52
|
const query = `{
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
# id
|
|
59
|
-
# owner
|
|
60
|
-
# timestamp
|
|
61
|
-
# tx_id
|
|
62
|
-
# type
|
|
63
|
-
# }
|
|
64
|
-
findTransaction(filterOptions: {byLedgerToFrom: "hive:${username}"}) {
|
|
65
|
-
anchr_height
|
|
66
|
-
anchr_index
|
|
67
|
-
anchr_opidx
|
|
68
|
-
anchr_ts
|
|
69
|
-
data
|
|
70
|
-
first_seen
|
|
71
|
-
id
|
|
72
|
-
ledger {
|
|
73
|
-
amount
|
|
74
|
-
asset
|
|
75
|
-
from
|
|
76
|
-
memo
|
|
77
|
-
params
|
|
78
|
-
to
|
|
53
|
+
findTransaction(filterOptions: {byLedgerToFrom: "hive:${username}"}) {
|
|
54
|
+
id
|
|
55
|
+
anchr_height
|
|
56
|
+
anchr_index
|
|
57
|
+
anchr_ts
|
|
79
58
|
type
|
|
59
|
+
op_types
|
|
60
|
+
first_seen
|
|
61
|
+
nonce
|
|
62
|
+
rc_limit
|
|
63
|
+
required_auths
|
|
64
|
+
status
|
|
65
|
+
ops {
|
|
66
|
+
required_auths
|
|
67
|
+
type
|
|
68
|
+
index
|
|
69
|
+
data
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}`;
|
|
73
|
+
const response = yield fetchQuery(query);
|
|
74
|
+
if (!(response === null || response === void 0 ? void 0 : response.data)) {
|
|
75
|
+
console.error('Invalid response from VSC API:', response);
|
|
76
|
+
return { findTransaction: [], findLedgerTXs: [] };
|
|
80
77
|
}
|
|
81
|
-
|
|
82
|
-
rc_limit
|
|
83
|
-
required_auths
|
|
84
|
-
status
|
|
85
|
-
type
|
|
86
|
-
}}
|
|
87
|
-
`;
|
|
88
|
-
return (yield fetchQuery(query)).data;
|
|
78
|
+
return response.data;
|
|
89
79
|
});
|
|
90
80
|
const getOrganizedHistory = (username) => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
81
|
const history = yield fetchHistory(username);
|
|
92
82
|
const organizedHistory = [
|
|
93
|
-
// ...(history.findLedgerTXs || [])
|
|
94
|
-
// .map((e) => {
|
|
95
|
-
// return {
|
|
96
|
-
// from: e.from,
|
|
97
|
-
// to: e.owner,
|
|
98
|
-
// amount: e.amount,
|
|
99
|
-
// timestamp: new Date(e.timestamp + 'Z'),
|
|
100
|
-
// txId: e.id,
|
|
101
|
-
// asset: e.asset,
|
|
102
|
-
// status: VscStatus.CONFIRMED,
|
|
103
|
-
// type: VscHistoryType.DEPOSIT,
|
|
104
|
-
// };
|
|
105
|
-
// })
|
|
106
|
-
// .filter((e) => e.to === `hive:${username}`),
|
|
107
83
|
...(history.findTransaction || [])
|
|
108
|
-
.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
};
|
|
120
|
-
})
|
|
84
|
+
.flatMap((e) => e.ops.map((op) => ({
|
|
85
|
+
from: op.data.from,
|
|
86
|
+
to: op.data.to,
|
|
87
|
+
amount: parseFloat(op.data.amount),
|
|
88
|
+
timestamp: new Date(e.first_seen),
|
|
89
|
+
txId: e.id,
|
|
90
|
+
memo: op.data.memo,
|
|
91
|
+
asset: op.data.asset,
|
|
92
|
+
status: e.status,
|
|
93
|
+
type: op.type,
|
|
94
|
+
})))
|
|
121
95
|
.filter((e) => !(e.type === 'withdraw' && e.from !== `hive:${username}`)),
|
|
122
96
|
].sort((a, b) => {
|
|
123
97
|
return new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime();
|
|
@@ -157,14 +131,16 @@ const getAccountBalance = (username) => __awaiter(void 0, void 0, void 0, functi
|
|
|
157
131
|
const query = `{
|
|
158
132
|
getAccountBalance(account: "hive:${username}") {
|
|
159
133
|
account
|
|
134
|
+
block_height
|
|
160
135
|
hbd
|
|
161
|
-
hive
|
|
162
|
-
hbd_savings
|
|
163
|
-
hbd_claim
|
|
164
|
-
hbd_modify
|
|
165
136
|
hbd_avg
|
|
166
|
-
|
|
137
|
+
hbd_modify
|
|
138
|
+
hbd_claim
|
|
139
|
+
hbd_savings
|
|
140
|
+
hive
|
|
167
141
|
hive_consensus
|
|
142
|
+
consensus_unstaking
|
|
143
|
+
pending_hbd_unstaking
|
|
168
144
|
}
|
|
169
145
|
}`;
|
|
170
146
|
return ((yield fetchQuery(query)).data.getAccountBalance || {
|
|
@@ -175,6 +151,7 @@ const getAccountBalance = (username) => __awaiter(void 0, void 0, void 0, functi
|
|
|
175
151
|
hbd_claim: 0,
|
|
176
152
|
hbd_modify: 0,
|
|
177
153
|
hbd_savings: 0,
|
|
154
|
+
pending_hbd_unstaking: 0,
|
|
178
155
|
});
|
|
179
156
|
});
|
|
180
157
|
const getWithdrawJson = (data, netId) => {
|