@ecency/wallets 1.4.35 → 1.5.1
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 +255 -6
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +259 -5
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +253 -6
- 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;
|
|
@@ -209,7 +211,14 @@ function useGetExternalWalletBalanceQuery(currency, address) {
|
|
|
209
211
|
function useSeedPhrase(username) {
|
|
210
212
|
return reactQuery.useQuery({
|
|
211
213
|
queryKey: ["ecency-wallets", "seed", username],
|
|
212
|
-
queryFn: async () => bip39__default.default.generateMnemonic(128)
|
|
214
|
+
queryFn: async () => bip39__default.default.generateMnemonic(128),
|
|
215
|
+
// CRITICAL: Prevent seed regeneration - cache forever
|
|
216
|
+
// Once generated, the seed must NEVER change to ensure consistency between:
|
|
217
|
+
// 1. Displayed seed phrase
|
|
218
|
+
// 2. Downloaded seed file
|
|
219
|
+
// 3. Keys sent to API for account creation
|
|
220
|
+
staleTime: Infinity,
|
|
221
|
+
gcTime: Infinity
|
|
213
222
|
});
|
|
214
223
|
}
|
|
215
224
|
var options = {
|
|
@@ -1928,6 +1937,221 @@ function getLarynxPowerAssetGeneralInfoQueryOptions(username) {
|
|
|
1928
1937
|
}
|
|
1929
1938
|
});
|
|
1930
1939
|
}
|
|
1940
|
+
function getAllHiveEngineTokensQueryOptions(account, symbol) {
|
|
1941
|
+
return reactQuery.queryOptions({
|
|
1942
|
+
queryKey: ["assets", "hive-engine", "all-tokens", account, symbol],
|
|
1943
|
+
queryFn: async () => {
|
|
1944
|
+
try {
|
|
1945
|
+
const response = await fetch(
|
|
1946
|
+
`${sdk.CONFIG.privateApiHost}/private-api/engine-api`,
|
|
1947
|
+
{
|
|
1948
|
+
method: "POST",
|
|
1949
|
+
body: JSON.stringify({
|
|
1950
|
+
jsonrpc: "2.0",
|
|
1951
|
+
method: "find",
|
|
1952
|
+
params: {
|
|
1953
|
+
contract: "market",
|
|
1954
|
+
table: "metrics",
|
|
1955
|
+
query: {
|
|
1956
|
+
...symbol && { symbol },
|
|
1957
|
+
...account && { account }
|
|
1958
|
+
}
|
|
1959
|
+
},
|
|
1960
|
+
id: 1
|
|
1961
|
+
}),
|
|
1962
|
+
headers: { "Content-type": "application/json" }
|
|
1963
|
+
}
|
|
1964
|
+
);
|
|
1965
|
+
const data = await response.json();
|
|
1966
|
+
return data.result;
|
|
1967
|
+
} catch (e) {
|
|
1968
|
+
return [];
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
});
|
|
1972
|
+
}
|
|
1973
|
+
function formattedNumber(value, options2 = void 0) {
|
|
1974
|
+
let opts = {
|
|
1975
|
+
fractionDigits: 3,
|
|
1976
|
+
prefix: "",
|
|
1977
|
+
suffix: ""
|
|
1978
|
+
};
|
|
1979
|
+
if (options2) {
|
|
1980
|
+
opts = { ...opts, ...options2 };
|
|
1981
|
+
}
|
|
1982
|
+
const { fractionDigits, prefix, suffix } = opts;
|
|
1983
|
+
let format4 = "0,0";
|
|
1984
|
+
if (fractionDigits) {
|
|
1985
|
+
format4 += "." + "0".repeat(fractionDigits);
|
|
1986
|
+
}
|
|
1987
|
+
let out = "";
|
|
1988
|
+
if (prefix) out += prefix + " ";
|
|
1989
|
+
const av = Math.abs(parseFloat(value.toString())) < 1e-4 ? 0 : value;
|
|
1990
|
+
out += numeral__default.default(av).format(format4);
|
|
1991
|
+
if (suffix) out += " " + suffix;
|
|
1992
|
+
return out;
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
// src/modules/assets/hive-engine/utils/hive-engine-token.ts
|
|
1996
|
+
var HiveEngineToken = class {
|
|
1997
|
+
symbol;
|
|
1998
|
+
name;
|
|
1999
|
+
icon;
|
|
2000
|
+
precision;
|
|
2001
|
+
stakingEnabled;
|
|
2002
|
+
delegationEnabled;
|
|
2003
|
+
balance;
|
|
2004
|
+
stake;
|
|
2005
|
+
stakedBalance;
|
|
2006
|
+
delegationsIn;
|
|
2007
|
+
delegationsOut;
|
|
2008
|
+
usdValue;
|
|
2009
|
+
constructor(props) {
|
|
2010
|
+
this.symbol = props.symbol;
|
|
2011
|
+
this.name = props.name || "";
|
|
2012
|
+
this.icon = props.icon || "";
|
|
2013
|
+
this.precision = props.precision || 0;
|
|
2014
|
+
this.stakingEnabled = props.stakingEnabled || false;
|
|
2015
|
+
this.delegationEnabled = props.delegationEnabled || false;
|
|
2016
|
+
this.balance = parseFloat(props.balance) || 0;
|
|
2017
|
+
this.stake = parseFloat(props.stake) || 0;
|
|
2018
|
+
this.delegationsIn = parseFloat(props.delegationsIn) || 0;
|
|
2019
|
+
this.delegationsOut = parseFloat(props.delegationsOut) || 0;
|
|
2020
|
+
this.stakedBalance = this.stake + this.delegationsIn - this.delegationsOut;
|
|
2021
|
+
this.usdValue = props.usdValue;
|
|
2022
|
+
}
|
|
2023
|
+
hasDelegations = () => {
|
|
2024
|
+
if (!this.delegationEnabled) {
|
|
2025
|
+
return false;
|
|
2026
|
+
}
|
|
2027
|
+
return this.delegationsIn > 0 && this.delegationsOut > 0;
|
|
2028
|
+
};
|
|
2029
|
+
delegations = () => {
|
|
2030
|
+
if (!this.hasDelegations()) {
|
|
2031
|
+
return "";
|
|
2032
|
+
}
|
|
2033
|
+
return `(${formattedNumber(this.stake, {
|
|
2034
|
+
fractionDigits: this.precision
|
|
2035
|
+
})} + ${formattedNumber(this.delegationsIn, {
|
|
2036
|
+
fractionDigits: this.precision
|
|
2037
|
+
})} - ${formattedNumber(this.delegationsOut, {
|
|
2038
|
+
fractionDigits: this.precision
|
|
2039
|
+
})})`;
|
|
2040
|
+
};
|
|
2041
|
+
staked = () => {
|
|
2042
|
+
if (!this.stakingEnabled) {
|
|
2043
|
+
return "-";
|
|
2044
|
+
}
|
|
2045
|
+
if (this.stakedBalance < 1e-4) {
|
|
2046
|
+
return this.stakedBalance.toString();
|
|
2047
|
+
}
|
|
2048
|
+
return formattedNumber(this.stakedBalance, {
|
|
2049
|
+
fractionDigits: this.precision
|
|
2050
|
+
});
|
|
2051
|
+
};
|
|
2052
|
+
balanced = () => {
|
|
2053
|
+
if (this.balance < 1e-4) {
|
|
2054
|
+
return this.balance.toString();
|
|
2055
|
+
}
|
|
2056
|
+
return formattedNumber(this.balance, { fractionDigits: this.precision });
|
|
2057
|
+
};
|
|
2058
|
+
};
|
|
2059
|
+
|
|
2060
|
+
// src/modules/assets/hive-engine/queries/get-hive-engine-balances-with-usd-query-options.ts
|
|
2061
|
+
function getHiveEngineBalancesWithUsdQueryOptions(account, dynamicProps, allTokens) {
|
|
2062
|
+
return reactQuery.queryOptions({
|
|
2063
|
+
queryKey: [
|
|
2064
|
+
"assets",
|
|
2065
|
+
"hive-engine",
|
|
2066
|
+
"balances-with-usd",
|
|
2067
|
+
account,
|
|
2068
|
+
dynamicProps,
|
|
2069
|
+
allTokens
|
|
2070
|
+
],
|
|
2071
|
+
queryFn: async () => {
|
|
2072
|
+
if (!account) {
|
|
2073
|
+
throw new Error("[HiveEngine] No account in a balances query");
|
|
2074
|
+
}
|
|
2075
|
+
const balancesResponse = await fetch(
|
|
2076
|
+
`${sdk.CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2077
|
+
{
|
|
2078
|
+
method: "POST",
|
|
2079
|
+
body: JSON.stringify({
|
|
2080
|
+
jsonrpc: "2.0",
|
|
2081
|
+
method: "find",
|
|
2082
|
+
params: {
|
|
2083
|
+
contract: "tokens",
|
|
2084
|
+
table: "balances",
|
|
2085
|
+
query: {
|
|
2086
|
+
account
|
|
2087
|
+
}
|
|
2088
|
+
},
|
|
2089
|
+
id: 1
|
|
2090
|
+
}),
|
|
2091
|
+
headers: { "Content-type": "application/json" }
|
|
2092
|
+
}
|
|
2093
|
+
);
|
|
2094
|
+
const balancesData = await balancesResponse.json();
|
|
2095
|
+
const balances = balancesData.result || [];
|
|
2096
|
+
const tokensResponse = await fetch(
|
|
2097
|
+
`${sdk.CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2098
|
+
{
|
|
2099
|
+
method: "POST",
|
|
2100
|
+
body: JSON.stringify({
|
|
2101
|
+
jsonrpc: "2.0",
|
|
2102
|
+
method: "find",
|
|
2103
|
+
params: {
|
|
2104
|
+
contract: "tokens",
|
|
2105
|
+
table: "tokens",
|
|
2106
|
+
query: {
|
|
2107
|
+
symbol: { $in: balances.map((t) => t.symbol) }
|
|
2108
|
+
}
|
|
2109
|
+
},
|
|
2110
|
+
id: 2
|
|
2111
|
+
}),
|
|
2112
|
+
headers: { "Content-type": "application/json" }
|
|
2113
|
+
}
|
|
2114
|
+
);
|
|
2115
|
+
const tokensData = await tokensResponse.json();
|
|
2116
|
+
const tokens = tokensData.result || [];
|
|
2117
|
+
const pricePerHive = dynamicProps ? dynamicProps.base / dynamicProps.quote : 0;
|
|
2118
|
+
const metrics = Array.isArray(
|
|
2119
|
+
allTokens
|
|
2120
|
+
) ? allTokens : [];
|
|
2121
|
+
return balances.map((balance) => {
|
|
2122
|
+
const token = tokens.find((t) => t.symbol === balance.symbol);
|
|
2123
|
+
let tokenMetadata;
|
|
2124
|
+
if (token?.metadata) {
|
|
2125
|
+
try {
|
|
2126
|
+
tokenMetadata = JSON.parse(token.metadata);
|
|
2127
|
+
} catch {
|
|
2128
|
+
tokenMetadata = void 0;
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
const metric = metrics.find((m) => m.symbol === balance.symbol);
|
|
2132
|
+
const lastPrice = Number(metric?.lastPrice ?? "0");
|
|
2133
|
+
const balanceAmount = Number(balance.balance);
|
|
2134
|
+
const usdValue = balance.symbol === "SWAP.HIVE" ? pricePerHive * balanceAmount : lastPrice === 0 ? 0 : Number(
|
|
2135
|
+
(lastPrice * pricePerHive * balanceAmount).toFixed(10)
|
|
2136
|
+
);
|
|
2137
|
+
return new HiveEngineToken({
|
|
2138
|
+
symbol: balance.symbol,
|
|
2139
|
+
name: token?.name ?? balance.symbol,
|
|
2140
|
+
icon: tokenMetadata?.icon ?? "",
|
|
2141
|
+
precision: token?.precision ?? 0,
|
|
2142
|
+
stakingEnabled: token?.stakingEnabled ?? false,
|
|
2143
|
+
delegationEnabled: token?.delegationEnabled ?? false,
|
|
2144
|
+
balance: balance.balance,
|
|
2145
|
+
stake: balance.stake,
|
|
2146
|
+
delegationsIn: balance.delegationsIn,
|
|
2147
|
+
delegationsOut: balance.delegationsOut,
|
|
2148
|
+
usdValue
|
|
2149
|
+
});
|
|
2150
|
+
});
|
|
2151
|
+
},
|
|
2152
|
+
enabled: !!account
|
|
2153
|
+
});
|
|
2154
|
+
}
|
|
1931
2155
|
function getHiveEngineTokensMetadataQueryOptions(tokens) {
|
|
1932
2156
|
return reactQuery.queryOptions({
|
|
1933
2157
|
queryKey: ["assets", "hive-engine", "metadata-list", tokens],
|
|
@@ -2115,6 +2339,30 @@ function getHiveEngineTokensMetricsQueryOptions(symbol, interval = "daily") {
|
|
|
2115
2339
|
}
|
|
2116
2340
|
});
|
|
2117
2341
|
}
|
|
2342
|
+
function getHiveEngineUnclaimedRewardsQueryOptions(username) {
|
|
2343
|
+
return reactQuery.queryOptions({
|
|
2344
|
+
queryKey: ["assets", "hive-engine", "unclaimed", username],
|
|
2345
|
+
staleTime: 6e4,
|
|
2346
|
+
refetchInterval: 9e4,
|
|
2347
|
+
enabled: !!username,
|
|
2348
|
+
queryFn: async () => {
|
|
2349
|
+
try {
|
|
2350
|
+
const response = await fetch(
|
|
2351
|
+
sdk.CONFIG.privateApiHost + `/private-api/engine-reward-api/${username}?hive=1`
|
|
2352
|
+
);
|
|
2353
|
+
if (!response.ok) {
|
|
2354
|
+
return [];
|
|
2355
|
+
}
|
|
2356
|
+
const data = await response.json();
|
|
2357
|
+
return Object.values(data).filter(
|
|
2358
|
+
({ pending_token }) => pending_token > 0
|
|
2359
|
+
);
|
|
2360
|
+
} catch (e) {
|
|
2361
|
+
return [];
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
});
|
|
2365
|
+
}
|
|
2118
2366
|
async function delegateEngineToken(payload) {
|
|
2119
2367
|
const parsedAsset = parseAsset(payload.amount);
|
|
2120
2368
|
const quantity = parsedAsset.amount.toString();
|
|
@@ -3568,13 +3816,13 @@ function getTronAssetGeneralInfoQueryOptions(username) {
|
|
|
3568
3816
|
// src/modules/wallets/queries/get-account-wallet-asset-info-query-options.ts
|
|
3569
3817
|
function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { refetch: false }) {
|
|
3570
3818
|
const queryClient = sdk.getQueryClient();
|
|
3571
|
-
const fetchQuery = async (
|
|
3819
|
+
const fetchQuery = async (queryOptions43) => {
|
|
3572
3820
|
if (options2.refetch) {
|
|
3573
|
-
await queryClient.fetchQuery(
|
|
3821
|
+
await queryClient.fetchQuery(queryOptions43);
|
|
3574
3822
|
} else {
|
|
3575
|
-
await queryClient.prefetchQuery(
|
|
3823
|
+
await queryClient.prefetchQuery(queryOptions43);
|
|
3576
3824
|
}
|
|
3577
|
-
return queryClient.getQueryData(
|
|
3825
|
+
return queryClient.getQueryData(queryOptions43.queryKey);
|
|
3578
3826
|
};
|
|
3579
3827
|
const portfolioQuery = getVisionPortfolioQueryOptions(username);
|
|
3580
3828
|
const getPortfolioAssetInfo = async () => {
|
|
@@ -4119,6 +4367,7 @@ exports.HIVE_ACCOUNT_OPERATION_GROUPS = HIVE_ACCOUNT_OPERATION_GROUPS;
|
|
|
4119
4367
|
exports.HIVE_OPERATION_LIST = HIVE_OPERATION_LIST;
|
|
4120
4368
|
exports.HIVE_OPERATION_NAME_BY_ID = HIVE_OPERATION_NAME_BY_ID;
|
|
4121
4369
|
exports.HIVE_OPERATION_ORDERS = HIVE_OPERATION_ORDERS;
|
|
4370
|
+
exports.HiveEngineToken = HiveEngineToken;
|
|
4122
4371
|
exports.NaiMap = NaiMap;
|
|
4123
4372
|
exports.PointTransactionType = PointTransactionType;
|
|
4124
4373
|
exports.Symbol = Symbol2;
|
|
@@ -4143,8 +4392,10 @@ exports.deriveHiveMasterPasswordKeys = deriveHiveMasterPasswordKeys;
|
|
|
4143
4392
|
exports.detectHiveKeyDerivation = detectHiveKeyDerivation;
|
|
4144
4393
|
exports.encryptMemoWithAccounts = encryptMemoWithAccounts;
|
|
4145
4394
|
exports.encryptMemoWithKeys = encryptMemoWithKeys;
|
|
4395
|
+
exports.formattedNumber = formattedNumber;
|
|
4146
4396
|
exports.getAccountWalletAssetInfoQueryOptions = getAccountWalletAssetInfoQueryOptions;
|
|
4147
4397
|
exports.getAccountWalletListQueryOptions = getAccountWalletListQueryOptions;
|
|
4398
|
+
exports.getAllHiveEngineTokensQueryOptions = getAllHiveEngineTokensQueryOptions;
|
|
4148
4399
|
exports.getAllTokensListQueryOptions = getAllTokensListQueryOptions;
|
|
4149
4400
|
exports.getBoundFetch = getBoundFetch;
|
|
4150
4401
|
exports.getHbdAssetGeneralInfoQueryOptions = getHbdAssetGeneralInfoQueryOptions;
|
|
@@ -4153,12 +4404,14 @@ exports.getHiveAssetGeneralInfoQueryOptions = getHiveAssetGeneralInfoQueryOption
|
|
|
4153
4404
|
exports.getHiveAssetMetricQueryOptions = getHiveAssetMetricQueryOptions;
|
|
4154
4405
|
exports.getHiveAssetTransactionsQueryOptions = getHiveAssetTransactionsQueryOptions;
|
|
4155
4406
|
exports.getHiveAssetWithdrawalRoutesQueryOptions = getHiveAssetWithdrawalRoutesQueryOptions;
|
|
4407
|
+
exports.getHiveEngineBalancesWithUsdQueryOptions = getHiveEngineBalancesWithUsdQueryOptions;
|
|
4156
4408
|
exports.getHiveEngineTokenGeneralInfoQueryOptions = getHiveEngineTokenGeneralInfoQueryOptions;
|
|
4157
4409
|
exports.getHiveEngineTokenTransactionsQueryOptions = getHiveEngineTokenTransactionsQueryOptions;
|
|
4158
4410
|
exports.getHiveEngineTokensBalancesQueryOptions = getHiveEngineTokensBalancesQueryOptions;
|
|
4159
4411
|
exports.getHiveEngineTokensMarketQueryOptions = getHiveEngineTokensMarketQueryOptions;
|
|
4160
4412
|
exports.getHiveEngineTokensMetadataQueryOptions = getHiveEngineTokensMetadataQueryOptions;
|
|
4161
4413
|
exports.getHiveEngineTokensMetricsQueryOptions = getHiveEngineTokensMetricsQueryOptions;
|
|
4414
|
+
exports.getHiveEngineUnclaimedRewardsQueryOptions = getHiveEngineUnclaimedRewardsQueryOptions;
|
|
4162
4415
|
exports.getHivePowerAssetGeneralInfoQueryOptions = getHivePowerAssetGeneralInfoQueryOptions;
|
|
4163
4416
|
exports.getHivePowerAssetTransactionsQueryOptions = getHivePowerAssetTransactionsQueryOptions;
|
|
4164
4417
|
exports.getHivePowerDelegatesInfiniteQueryOptions = getHivePowerDelegatesInfiniteQueryOptions;
|
|
@@ -4170,6 +4423,7 @@ exports.getPointsAssetTransactionsQueryOptions = getPointsAssetTransactionsQuery
|
|
|
4170
4423
|
exports.getPointsQueryOptions = getPointsQueryOptions;
|
|
4171
4424
|
exports.getSpkAssetGeneralInfoQueryOptions = getSpkAssetGeneralInfoQueryOptions;
|
|
4172
4425
|
exports.getSpkMarketsQueryOptions = getSpkMarketsQueryOptions;
|
|
4426
|
+
exports.getSpkWalletQueryOptions = getSpkWalletQueryOptions;
|
|
4173
4427
|
exports.getTokenOperationsQueryOptions = getTokenOperationsQueryOptions;
|
|
4174
4428
|
exports.getTokenPriceQueryOptions = getTokenPriceQueryOptions;
|
|
4175
4429
|
exports.getVisionPortfolioQueryOptions = getVisionPortfolioQueryOptions;
|