@ecency/wallets 1.4.35 → 1.5.0
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/dist/browser/index.d.ts +177 -44
- package/dist/browser/index.js +247 -5
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +251 -4
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +245 -5
- package/dist/node/index.mjs.map +1 -1
- package/package.json +3 -1
package/dist/node/index.cjs
CHANGED
|
@@ -16,6 +16,7 @@ var crypto = require('@hiveio/dhive/lib/crypto');
|
|
|
16
16
|
var memo = require('@hiveio/dhive/lib/memo');
|
|
17
17
|
var dayjs = require('dayjs');
|
|
18
18
|
var hs = require('hivesigner');
|
|
19
|
+
var numeral = require('numeral');
|
|
19
20
|
var R = require('remeda');
|
|
20
21
|
|
|
21
22
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -41,6 +42,7 @@ function _interopNamespace(e) {
|
|
|
41
42
|
var bip39__default = /*#__PURE__*/_interopDefault(bip39);
|
|
42
43
|
var dayjs__default = /*#__PURE__*/_interopDefault(dayjs);
|
|
43
44
|
var hs__default = /*#__PURE__*/_interopDefault(hs);
|
|
45
|
+
var numeral__default = /*#__PURE__*/_interopDefault(numeral);
|
|
44
46
|
var R__namespace = /*#__PURE__*/_interopNamespace(R);
|
|
45
47
|
|
|
46
48
|
var __defProp = Object.defineProperty;
|
|
@@ -1928,6 +1930,221 @@ function getLarynxPowerAssetGeneralInfoQueryOptions(username) {
|
|
|
1928
1930
|
}
|
|
1929
1931
|
});
|
|
1930
1932
|
}
|
|
1933
|
+
function getAllHiveEngineTokensQueryOptions(account, symbol) {
|
|
1934
|
+
return reactQuery.queryOptions({
|
|
1935
|
+
queryKey: ["assets", "hive-engine", "all-tokens", account, symbol],
|
|
1936
|
+
queryFn: async () => {
|
|
1937
|
+
try {
|
|
1938
|
+
const response = await fetch(
|
|
1939
|
+
`${sdk.CONFIG.privateApiHost}/private-api/engine-api`,
|
|
1940
|
+
{
|
|
1941
|
+
method: "POST",
|
|
1942
|
+
body: JSON.stringify({
|
|
1943
|
+
jsonrpc: "2.0",
|
|
1944
|
+
method: "find",
|
|
1945
|
+
params: {
|
|
1946
|
+
contract: "market",
|
|
1947
|
+
table: "metrics",
|
|
1948
|
+
query: {
|
|
1949
|
+
...symbol && { symbol },
|
|
1950
|
+
...account && { account }
|
|
1951
|
+
}
|
|
1952
|
+
},
|
|
1953
|
+
id: 1
|
|
1954
|
+
}),
|
|
1955
|
+
headers: { "Content-type": "application/json" }
|
|
1956
|
+
}
|
|
1957
|
+
);
|
|
1958
|
+
const data = await response.json();
|
|
1959
|
+
return data.result;
|
|
1960
|
+
} catch (e) {
|
|
1961
|
+
return [];
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
});
|
|
1965
|
+
}
|
|
1966
|
+
function formattedNumber(value, options2 = void 0) {
|
|
1967
|
+
let opts = {
|
|
1968
|
+
fractionDigits: 3,
|
|
1969
|
+
prefix: "",
|
|
1970
|
+
suffix: ""
|
|
1971
|
+
};
|
|
1972
|
+
if (options2) {
|
|
1973
|
+
opts = { ...opts, ...options2 };
|
|
1974
|
+
}
|
|
1975
|
+
const { fractionDigits, prefix, suffix } = opts;
|
|
1976
|
+
let format4 = "0,0";
|
|
1977
|
+
if (fractionDigits) {
|
|
1978
|
+
format4 += "." + "0".repeat(fractionDigits);
|
|
1979
|
+
}
|
|
1980
|
+
let out = "";
|
|
1981
|
+
if (prefix) out += prefix + " ";
|
|
1982
|
+
const av = Math.abs(parseFloat(value.toString())) < 1e-4 ? 0 : value;
|
|
1983
|
+
out += numeral__default.default(av).format(format4);
|
|
1984
|
+
if (suffix) out += " " + suffix;
|
|
1985
|
+
return out;
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
// src/modules/assets/hive-engine/utils/hive-engine-token.ts
|
|
1989
|
+
var HiveEngineToken = class {
|
|
1990
|
+
symbol;
|
|
1991
|
+
name;
|
|
1992
|
+
icon;
|
|
1993
|
+
precision;
|
|
1994
|
+
stakingEnabled;
|
|
1995
|
+
delegationEnabled;
|
|
1996
|
+
balance;
|
|
1997
|
+
stake;
|
|
1998
|
+
stakedBalance;
|
|
1999
|
+
delegationsIn;
|
|
2000
|
+
delegationsOut;
|
|
2001
|
+
usdValue;
|
|
2002
|
+
constructor(props) {
|
|
2003
|
+
this.symbol = props.symbol;
|
|
2004
|
+
this.name = props.name || "";
|
|
2005
|
+
this.icon = props.icon || "";
|
|
2006
|
+
this.precision = props.precision || 0;
|
|
2007
|
+
this.stakingEnabled = props.stakingEnabled || false;
|
|
2008
|
+
this.delegationEnabled = props.delegationEnabled || false;
|
|
2009
|
+
this.balance = parseFloat(props.balance) || 0;
|
|
2010
|
+
this.stake = parseFloat(props.stake) || 0;
|
|
2011
|
+
this.delegationsIn = parseFloat(props.delegationsIn) || 0;
|
|
2012
|
+
this.delegationsOut = parseFloat(props.delegationsOut) || 0;
|
|
2013
|
+
this.stakedBalance = this.stake + this.delegationsIn - this.delegationsOut;
|
|
2014
|
+
this.usdValue = props.usdValue;
|
|
2015
|
+
}
|
|
2016
|
+
hasDelegations = () => {
|
|
2017
|
+
if (!this.delegationEnabled) {
|
|
2018
|
+
return false;
|
|
2019
|
+
}
|
|
2020
|
+
return this.delegationsIn > 0 && this.delegationsOut > 0;
|
|
2021
|
+
};
|
|
2022
|
+
delegations = () => {
|
|
2023
|
+
if (!this.hasDelegations()) {
|
|
2024
|
+
return "";
|
|
2025
|
+
}
|
|
2026
|
+
return `(${formattedNumber(this.stake, {
|
|
2027
|
+
fractionDigits: this.precision
|
|
2028
|
+
})} + ${formattedNumber(this.delegationsIn, {
|
|
2029
|
+
fractionDigits: this.precision
|
|
2030
|
+
})} - ${formattedNumber(this.delegationsOut, {
|
|
2031
|
+
fractionDigits: this.precision
|
|
2032
|
+
})})`;
|
|
2033
|
+
};
|
|
2034
|
+
staked = () => {
|
|
2035
|
+
if (!this.stakingEnabled) {
|
|
2036
|
+
return "-";
|
|
2037
|
+
}
|
|
2038
|
+
if (this.stakedBalance < 1e-4) {
|
|
2039
|
+
return this.stakedBalance.toString();
|
|
2040
|
+
}
|
|
2041
|
+
return formattedNumber(this.stakedBalance, {
|
|
2042
|
+
fractionDigits: this.precision
|
|
2043
|
+
});
|
|
2044
|
+
};
|
|
2045
|
+
balanced = () => {
|
|
2046
|
+
if (this.balance < 1e-4) {
|
|
2047
|
+
return this.balance.toString();
|
|
2048
|
+
}
|
|
2049
|
+
return formattedNumber(this.balance, { fractionDigits: this.precision });
|
|
2050
|
+
};
|
|
2051
|
+
};
|
|
2052
|
+
|
|
2053
|
+
// src/modules/assets/hive-engine/queries/get-hive-engine-balances-with-usd-query-options.ts
|
|
2054
|
+
function getHiveEngineBalancesWithUsdQueryOptions(account, dynamicProps, allTokens) {
|
|
2055
|
+
return reactQuery.queryOptions({
|
|
2056
|
+
queryKey: [
|
|
2057
|
+
"assets",
|
|
2058
|
+
"hive-engine",
|
|
2059
|
+
"balances-with-usd",
|
|
2060
|
+
account,
|
|
2061
|
+
dynamicProps,
|
|
2062
|
+
allTokens
|
|
2063
|
+
],
|
|
2064
|
+
queryFn: async () => {
|
|
2065
|
+
if (!account) {
|
|
2066
|
+
throw new Error("[HiveEngine] No account in a balances query");
|
|
2067
|
+
}
|
|
2068
|
+
const balancesResponse = await fetch(
|
|
2069
|
+
`${sdk.CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2070
|
+
{
|
|
2071
|
+
method: "POST",
|
|
2072
|
+
body: JSON.stringify({
|
|
2073
|
+
jsonrpc: "2.0",
|
|
2074
|
+
method: "find",
|
|
2075
|
+
params: {
|
|
2076
|
+
contract: "tokens",
|
|
2077
|
+
table: "balances",
|
|
2078
|
+
query: {
|
|
2079
|
+
account
|
|
2080
|
+
}
|
|
2081
|
+
},
|
|
2082
|
+
id: 1
|
|
2083
|
+
}),
|
|
2084
|
+
headers: { "Content-type": "application/json" }
|
|
2085
|
+
}
|
|
2086
|
+
);
|
|
2087
|
+
const balancesData = await balancesResponse.json();
|
|
2088
|
+
const balances = balancesData.result || [];
|
|
2089
|
+
const tokensResponse = await fetch(
|
|
2090
|
+
`${sdk.CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2091
|
+
{
|
|
2092
|
+
method: "POST",
|
|
2093
|
+
body: JSON.stringify({
|
|
2094
|
+
jsonrpc: "2.0",
|
|
2095
|
+
method: "find",
|
|
2096
|
+
params: {
|
|
2097
|
+
contract: "tokens",
|
|
2098
|
+
table: "tokens",
|
|
2099
|
+
query: {
|
|
2100
|
+
symbol: { $in: balances.map((t) => t.symbol) }
|
|
2101
|
+
}
|
|
2102
|
+
},
|
|
2103
|
+
id: 2
|
|
2104
|
+
}),
|
|
2105
|
+
headers: { "Content-type": "application/json" }
|
|
2106
|
+
}
|
|
2107
|
+
);
|
|
2108
|
+
const tokensData = await tokensResponse.json();
|
|
2109
|
+
const tokens = tokensData.result || [];
|
|
2110
|
+
const pricePerHive = dynamicProps ? dynamicProps.base / dynamicProps.quote : 0;
|
|
2111
|
+
const metrics = Array.isArray(
|
|
2112
|
+
allTokens
|
|
2113
|
+
) ? allTokens : [];
|
|
2114
|
+
return balances.map((balance) => {
|
|
2115
|
+
const token = tokens.find((t) => t.symbol === balance.symbol);
|
|
2116
|
+
let tokenMetadata;
|
|
2117
|
+
if (token?.metadata) {
|
|
2118
|
+
try {
|
|
2119
|
+
tokenMetadata = JSON.parse(token.metadata);
|
|
2120
|
+
} catch {
|
|
2121
|
+
tokenMetadata = void 0;
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
const metric = metrics.find((m) => m.symbol === balance.symbol);
|
|
2125
|
+
const lastPrice = Number(metric?.lastPrice ?? "0");
|
|
2126
|
+
const balanceAmount = Number(balance.balance);
|
|
2127
|
+
const usdValue = balance.symbol === "SWAP.HIVE" ? pricePerHive * balanceAmount : lastPrice === 0 ? 0 : Number(
|
|
2128
|
+
(lastPrice * pricePerHive * balanceAmount).toFixed(10)
|
|
2129
|
+
);
|
|
2130
|
+
return new HiveEngineToken({
|
|
2131
|
+
symbol: balance.symbol,
|
|
2132
|
+
name: token?.name ?? balance.symbol,
|
|
2133
|
+
icon: tokenMetadata?.icon ?? "",
|
|
2134
|
+
precision: token?.precision ?? 0,
|
|
2135
|
+
stakingEnabled: token?.stakingEnabled ?? false,
|
|
2136
|
+
delegationEnabled: token?.delegationEnabled ?? false,
|
|
2137
|
+
balance: balance.balance,
|
|
2138
|
+
stake: balance.stake,
|
|
2139
|
+
delegationsIn: balance.delegationsIn,
|
|
2140
|
+
delegationsOut: balance.delegationsOut,
|
|
2141
|
+
usdValue
|
|
2142
|
+
});
|
|
2143
|
+
});
|
|
2144
|
+
},
|
|
2145
|
+
enabled: !!account
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
1931
2148
|
function getHiveEngineTokensMetadataQueryOptions(tokens) {
|
|
1932
2149
|
return reactQuery.queryOptions({
|
|
1933
2150
|
queryKey: ["assets", "hive-engine", "metadata-list", tokens],
|
|
@@ -2115,6 +2332,30 @@ function getHiveEngineTokensMetricsQueryOptions(symbol, interval = "daily") {
|
|
|
2115
2332
|
}
|
|
2116
2333
|
});
|
|
2117
2334
|
}
|
|
2335
|
+
function getHiveEngineUnclaimedRewardsQueryOptions(username) {
|
|
2336
|
+
return reactQuery.queryOptions({
|
|
2337
|
+
queryKey: ["assets", "hive-engine", "unclaimed", username],
|
|
2338
|
+
staleTime: 6e4,
|
|
2339
|
+
refetchInterval: 9e4,
|
|
2340
|
+
enabled: !!username,
|
|
2341
|
+
queryFn: async () => {
|
|
2342
|
+
try {
|
|
2343
|
+
const response = await fetch(
|
|
2344
|
+
sdk.CONFIG.privateApiHost + `/private-api/engine-reward-api/${username}?hive=1`
|
|
2345
|
+
);
|
|
2346
|
+
if (!response.ok) {
|
|
2347
|
+
return [];
|
|
2348
|
+
}
|
|
2349
|
+
const data = await response.json();
|
|
2350
|
+
return Object.values(data).filter(
|
|
2351
|
+
({ pending_token }) => pending_token > 0
|
|
2352
|
+
);
|
|
2353
|
+
} catch (e) {
|
|
2354
|
+
return [];
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
});
|
|
2358
|
+
}
|
|
2118
2359
|
async function delegateEngineToken(payload) {
|
|
2119
2360
|
const parsedAsset = parseAsset(payload.amount);
|
|
2120
2361
|
const quantity = parsedAsset.amount.toString();
|
|
@@ -3568,13 +3809,13 @@ function getTronAssetGeneralInfoQueryOptions(username) {
|
|
|
3568
3809
|
// src/modules/wallets/queries/get-account-wallet-asset-info-query-options.ts
|
|
3569
3810
|
function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { refetch: false }) {
|
|
3570
3811
|
const queryClient = sdk.getQueryClient();
|
|
3571
|
-
const fetchQuery = async (
|
|
3812
|
+
const fetchQuery = async (queryOptions43) => {
|
|
3572
3813
|
if (options2.refetch) {
|
|
3573
|
-
await queryClient.fetchQuery(
|
|
3814
|
+
await queryClient.fetchQuery(queryOptions43);
|
|
3574
3815
|
} else {
|
|
3575
|
-
await queryClient.prefetchQuery(
|
|
3816
|
+
await queryClient.prefetchQuery(queryOptions43);
|
|
3576
3817
|
}
|
|
3577
|
-
return queryClient.getQueryData(
|
|
3818
|
+
return queryClient.getQueryData(queryOptions43.queryKey);
|
|
3578
3819
|
};
|
|
3579
3820
|
const portfolioQuery = getVisionPortfolioQueryOptions(username);
|
|
3580
3821
|
const getPortfolioAssetInfo = async () => {
|
|
@@ -4119,6 +4360,7 @@ exports.HIVE_ACCOUNT_OPERATION_GROUPS = HIVE_ACCOUNT_OPERATION_GROUPS;
|
|
|
4119
4360
|
exports.HIVE_OPERATION_LIST = HIVE_OPERATION_LIST;
|
|
4120
4361
|
exports.HIVE_OPERATION_NAME_BY_ID = HIVE_OPERATION_NAME_BY_ID;
|
|
4121
4362
|
exports.HIVE_OPERATION_ORDERS = HIVE_OPERATION_ORDERS;
|
|
4363
|
+
exports.HiveEngineToken = HiveEngineToken;
|
|
4122
4364
|
exports.NaiMap = NaiMap;
|
|
4123
4365
|
exports.PointTransactionType = PointTransactionType;
|
|
4124
4366
|
exports.Symbol = Symbol2;
|
|
@@ -4143,8 +4385,10 @@ exports.deriveHiveMasterPasswordKeys = deriveHiveMasterPasswordKeys;
|
|
|
4143
4385
|
exports.detectHiveKeyDerivation = detectHiveKeyDerivation;
|
|
4144
4386
|
exports.encryptMemoWithAccounts = encryptMemoWithAccounts;
|
|
4145
4387
|
exports.encryptMemoWithKeys = encryptMemoWithKeys;
|
|
4388
|
+
exports.formattedNumber = formattedNumber;
|
|
4146
4389
|
exports.getAccountWalletAssetInfoQueryOptions = getAccountWalletAssetInfoQueryOptions;
|
|
4147
4390
|
exports.getAccountWalletListQueryOptions = getAccountWalletListQueryOptions;
|
|
4391
|
+
exports.getAllHiveEngineTokensQueryOptions = getAllHiveEngineTokensQueryOptions;
|
|
4148
4392
|
exports.getAllTokensListQueryOptions = getAllTokensListQueryOptions;
|
|
4149
4393
|
exports.getBoundFetch = getBoundFetch;
|
|
4150
4394
|
exports.getHbdAssetGeneralInfoQueryOptions = getHbdAssetGeneralInfoQueryOptions;
|
|
@@ -4153,12 +4397,14 @@ exports.getHiveAssetGeneralInfoQueryOptions = getHiveAssetGeneralInfoQueryOption
|
|
|
4153
4397
|
exports.getHiveAssetMetricQueryOptions = getHiveAssetMetricQueryOptions;
|
|
4154
4398
|
exports.getHiveAssetTransactionsQueryOptions = getHiveAssetTransactionsQueryOptions;
|
|
4155
4399
|
exports.getHiveAssetWithdrawalRoutesQueryOptions = getHiveAssetWithdrawalRoutesQueryOptions;
|
|
4400
|
+
exports.getHiveEngineBalancesWithUsdQueryOptions = getHiveEngineBalancesWithUsdQueryOptions;
|
|
4156
4401
|
exports.getHiveEngineTokenGeneralInfoQueryOptions = getHiveEngineTokenGeneralInfoQueryOptions;
|
|
4157
4402
|
exports.getHiveEngineTokenTransactionsQueryOptions = getHiveEngineTokenTransactionsQueryOptions;
|
|
4158
4403
|
exports.getHiveEngineTokensBalancesQueryOptions = getHiveEngineTokensBalancesQueryOptions;
|
|
4159
4404
|
exports.getHiveEngineTokensMarketQueryOptions = getHiveEngineTokensMarketQueryOptions;
|
|
4160
4405
|
exports.getHiveEngineTokensMetadataQueryOptions = getHiveEngineTokensMetadataQueryOptions;
|
|
4161
4406
|
exports.getHiveEngineTokensMetricsQueryOptions = getHiveEngineTokensMetricsQueryOptions;
|
|
4407
|
+
exports.getHiveEngineUnclaimedRewardsQueryOptions = getHiveEngineUnclaimedRewardsQueryOptions;
|
|
4162
4408
|
exports.getHivePowerAssetGeneralInfoQueryOptions = getHivePowerAssetGeneralInfoQueryOptions;
|
|
4163
4409
|
exports.getHivePowerAssetTransactionsQueryOptions = getHivePowerAssetTransactionsQueryOptions;
|
|
4164
4410
|
exports.getHivePowerDelegatesInfiniteQueryOptions = getHivePowerDelegatesInfiniteQueryOptions;
|
|
@@ -4170,6 +4416,7 @@ exports.getPointsAssetTransactionsQueryOptions = getPointsAssetTransactionsQuery
|
|
|
4170
4416
|
exports.getPointsQueryOptions = getPointsQueryOptions;
|
|
4171
4417
|
exports.getSpkAssetGeneralInfoQueryOptions = getSpkAssetGeneralInfoQueryOptions;
|
|
4172
4418
|
exports.getSpkMarketsQueryOptions = getSpkMarketsQueryOptions;
|
|
4419
|
+
exports.getSpkWalletQueryOptions = getSpkWalletQueryOptions;
|
|
4173
4420
|
exports.getTokenOperationsQueryOptions = getTokenOperationsQueryOptions;
|
|
4174
4421
|
exports.getTokenPriceQueryOptions = getTokenPriceQueryOptions;
|
|
4175
4422
|
exports.getVisionPortfolioQueryOptions = getVisionPortfolioQueryOptions;
|