@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.mjs
CHANGED
|
@@ -14,6 +14,7 @@ import { cryptoUtils } from '@hiveio/dhive/lib/crypto';
|
|
|
14
14
|
import { Memo } from '@hiveio/dhive/lib/memo';
|
|
15
15
|
import dayjs from 'dayjs';
|
|
16
16
|
import hs from 'hivesigner';
|
|
17
|
+
import numeral from 'numeral';
|
|
17
18
|
import * as R from 'remeda';
|
|
18
19
|
|
|
19
20
|
var __defProp = Object.defineProperty;
|
|
@@ -1901,6 +1902,221 @@ function getLarynxPowerAssetGeneralInfoQueryOptions(username) {
|
|
|
1901
1902
|
}
|
|
1902
1903
|
});
|
|
1903
1904
|
}
|
|
1905
|
+
function getAllHiveEngineTokensQueryOptions(account, symbol) {
|
|
1906
|
+
return queryOptions({
|
|
1907
|
+
queryKey: ["assets", "hive-engine", "all-tokens", account, symbol],
|
|
1908
|
+
queryFn: async () => {
|
|
1909
|
+
try {
|
|
1910
|
+
const response = await fetch(
|
|
1911
|
+
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
1912
|
+
{
|
|
1913
|
+
method: "POST",
|
|
1914
|
+
body: JSON.stringify({
|
|
1915
|
+
jsonrpc: "2.0",
|
|
1916
|
+
method: "find",
|
|
1917
|
+
params: {
|
|
1918
|
+
contract: "market",
|
|
1919
|
+
table: "metrics",
|
|
1920
|
+
query: {
|
|
1921
|
+
...symbol && { symbol },
|
|
1922
|
+
...account && { account }
|
|
1923
|
+
}
|
|
1924
|
+
},
|
|
1925
|
+
id: 1
|
|
1926
|
+
}),
|
|
1927
|
+
headers: { "Content-type": "application/json" }
|
|
1928
|
+
}
|
|
1929
|
+
);
|
|
1930
|
+
const data = await response.json();
|
|
1931
|
+
return data.result;
|
|
1932
|
+
} catch (e) {
|
|
1933
|
+
return [];
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
});
|
|
1937
|
+
}
|
|
1938
|
+
function formattedNumber(value, options2 = void 0) {
|
|
1939
|
+
let opts = {
|
|
1940
|
+
fractionDigits: 3,
|
|
1941
|
+
prefix: "",
|
|
1942
|
+
suffix: ""
|
|
1943
|
+
};
|
|
1944
|
+
if (options2) {
|
|
1945
|
+
opts = { ...opts, ...options2 };
|
|
1946
|
+
}
|
|
1947
|
+
const { fractionDigits, prefix, suffix } = opts;
|
|
1948
|
+
let format4 = "0,0";
|
|
1949
|
+
if (fractionDigits) {
|
|
1950
|
+
format4 += "." + "0".repeat(fractionDigits);
|
|
1951
|
+
}
|
|
1952
|
+
let out = "";
|
|
1953
|
+
if (prefix) out += prefix + " ";
|
|
1954
|
+
const av = Math.abs(parseFloat(value.toString())) < 1e-4 ? 0 : value;
|
|
1955
|
+
out += numeral(av).format(format4);
|
|
1956
|
+
if (suffix) out += " " + suffix;
|
|
1957
|
+
return out;
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
// src/modules/assets/hive-engine/utils/hive-engine-token.ts
|
|
1961
|
+
var HiveEngineToken = class {
|
|
1962
|
+
symbol;
|
|
1963
|
+
name;
|
|
1964
|
+
icon;
|
|
1965
|
+
precision;
|
|
1966
|
+
stakingEnabled;
|
|
1967
|
+
delegationEnabled;
|
|
1968
|
+
balance;
|
|
1969
|
+
stake;
|
|
1970
|
+
stakedBalance;
|
|
1971
|
+
delegationsIn;
|
|
1972
|
+
delegationsOut;
|
|
1973
|
+
usdValue;
|
|
1974
|
+
constructor(props) {
|
|
1975
|
+
this.symbol = props.symbol;
|
|
1976
|
+
this.name = props.name || "";
|
|
1977
|
+
this.icon = props.icon || "";
|
|
1978
|
+
this.precision = props.precision || 0;
|
|
1979
|
+
this.stakingEnabled = props.stakingEnabled || false;
|
|
1980
|
+
this.delegationEnabled = props.delegationEnabled || false;
|
|
1981
|
+
this.balance = parseFloat(props.balance) || 0;
|
|
1982
|
+
this.stake = parseFloat(props.stake) || 0;
|
|
1983
|
+
this.delegationsIn = parseFloat(props.delegationsIn) || 0;
|
|
1984
|
+
this.delegationsOut = parseFloat(props.delegationsOut) || 0;
|
|
1985
|
+
this.stakedBalance = this.stake + this.delegationsIn - this.delegationsOut;
|
|
1986
|
+
this.usdValue = props.usdValue;
|
|
1987
|
+
}
|
|
1988
|
+
hasDelegations = () => {
|
|
1989
|
+
if (!this.delegationEnabled) {
|
|
1990
|
+
return false;
|
|
1991
|
+
}
|
|
1992
|
+
return this.delegationsIn > 0 && this.delegationsOut > 0;
|
|
1993
|
+
};
|
|
1994
|
+
delegations = () => {
|
|
1995
|
+
if (!this.hasDelegations()) {
|
|
1996
|
+
return "";
|
|
1997
|
+
}
|
|
1998
|
+
return `(${formattedNumber(this.stake, {
|
|
1999
|
+
fractionDigits: this.precision
|
|
2000
|
+
})} + ${formattedNumber(this.delegationsIn, {
|
|
2001
|
+
fractionDigits: this.precision
|
|
2002
|
+
})} - ${formattedNumber(this.delegationsOut, {
|
|
2003
|
+
fractionDigits: this.precision
|
|
2004
|
+
})})`;
|
|
2005
|
+
};
|
|
2006
|
+
staked = () => {
|
|
2007
|
+
if (!this.stakingEnabled) {
|
|
2008
|
+
return "-";
|
|
2009
|
+
}
|
|
2010
|
+
if (this.stakedBalance < 1e-4) {
|
|
2011
|
+
return this.stakedBalance.toString();
|
|
2012
|
+
}
|
|
2013
|
+
return formattedNumber(this.stakedBalance, {
|
|
2014
|
+
fractionDigits: this.precision
|
|
2015
|
+
});
|
|
2016
|
+
};
|
|
2017
|
+
balanced = () => {
|
|
2018
|
+
if (this.balance < 1e-4) {
|
|
2019
|
+
return this.balance.toString();
|
|
2020
|
+
}
|
|
2021
|
+
return formattedNumber(this.balance, { fractionDigits: this.precision });
|
|
2022
|
+
};
|
|
2023
|
+
};
|
|
2024
|
+
|
|
2025
|
+
// src/modules/assets/hive-engine/queries/get-hive-engine-balances-with-usd-query-options.ts
|
|
2026
|
+
function getHiveEngineBalancesWithUsdQueryOptions(account, dynamicProps, allTokens) {
|
|
2027
|
+
return queryOptions({
|
|
2028
|
+
queryKey: [
|
|
2029
|
+
"assets",
|
|
2030
|
+
"hive-engine",
|
|
2031
|
+
"balances-with-usd",
|
|
2032
|
+
account,
|
|
2033
|
+
dynamicProps,
|
|
2034
|
+
allTokens
|
|
2035
|
+
],
|
|
2036
|
+
queryFn: async () => {
|
|
2037
|
+
if (!account) {
|
|
2038
|
+
throw new Error("[HiveEngine] No account in a balances query");
|
|
2039
|
+
}
|
|
2040
|
+
const balancesResponse = await fetch(
|
|
2041
|
+
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2042
|
+
{
|
|
2043
|
+
method: "POST",
|
|
2044
|
+
body: JSON.stringify({
|
|
2045
|
+
jsonrpc: "2.0",
|
|
2046
|
+
method: "find",
|
|
2047
|
+
params: {
|
|
2048
|
+
contract: "tokens",
|
|
2049
|
+
table: "balances",
|
|
2050
|
+
query: {
|
|
2051
|
+
account
|
|
2052
|
+
}
|
|
2053
|
+
},
|
|
2054
|
+
id: 1
|
|
2055
|
+
}),
|
|
2056
|
+
headers: { "Content-type": "application/json" }
|
|
2057
|
+
}
|
|
2058
|
+
);
|
|
2059
|
+
const balancesData = await balancesResponse.json();
|
|
2060
|
+
const balances = balancesData.result || [];
|
|
2061
|
+
const tokensResponse = await fetch(
|
|
2062
|
+
`${CONFIG.privateApiHost}/private-api/engine-api`,
|
|
2063
|
+
{
|
|
2064
|
+
method: "POST",
|
|
2065
|
+
body: JSON.stringify({
|
|
2066
|
+
jsonrpc: "2.0",
|
|
2067
|
+
method: "find",
|
|
2068
|
+
params: {
|
|
2069
|
+
contract: "tokens",
|
|
2070
|
+
table: "tokens",
|
|
2071
|
+
query: {
|
|
2072
|
+
symbol: { $in: balances.map((t) => t.symbol) }
|
|
2073
|
+
}
|
|
2074
|
+
},
|
|
2075
|
+
id: 2
|
|
2076
|
+
}),
|
|
2077
|
+
headers: { "Content-type": "application/json" }
|
|
2078
|
+
}
|
|
2079
|
+
);
|
|
2080
|
+
const tokensData = await tokensResponse.json();
|
|
2081
|
+
const tokens = tokensData.result || [];
|
|
2082
|
+
const pricePerHive = dynamicProps ? dynamicProps.base / dynamicProps.quote : 0;
|
|
2083
|
+
const metrics = Array.isArray(
|
|
2084
|
+
allTokens
|
|
2085
|
+
) ? allTokens : [];
|
|
2086
|
+
return balances.map((balance) => {
|
|
2087
|
+
const token = tokens.find((t) => t.symbol === balance.symbol);
|
|
2088
|
+
let tokenMetadata;
|
|
2089
|
+
if (token?.metadata) {
|
|
2090
|
+
try {
|
|
2091
|
+
tokenMetadata = JSON.parse(token.metadata);
|
|
2092
|
+
} catch {
|
|
2093
|
+
tokenMetadata = void 0;
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
const metric = metrics.find((m) => m.symbol === balance.symbol);
|
|
2097
|
+
const lastPrice = Number(metric?.lastPrice ?? "0");
|
|
2098
|
+
const balanceAmount = Number(balance.balance);
|
|
2099
|
+
const usdValue = balance.symbol === "SWAP.HIVE" ? pricePerHive * balanceAmount : lastPrice === 0 ? 0 : Number(
|
|
2100
|
+
(lastPrice * pricePerHive * balanceAmount).toFixed(10)
|
|
2101
|
+
);
|
|
2102
|
+
return new HiveEngineToken({
|
|
2103
|
+
symbol: balance.symbol,
|
|
2104
|
+
name: token?.name ?? balance.symbol,
|
|
2105
|
+
icon: tokenMetadata?.icon ?? "",
|
|
2106
|
+
precision: token?.precision ?? 0,
|
|
2107
|
+
stakingEnabled: token?.stakingEnabled ?? false,
|
|
2108
|
+
delegationEnabled: token?.delegationEnabled ?? false,
|
|
2109
|
+
balance: balance.balance,
|
|
2110
|
+
stake: balance.stake,
|
|
2111
|
+
delegationsIn: balance.delegationsIn,
|
|
2112
|
+
delegationsOut: balance.delegationsOut,
|
|
2113
|
+
usdValue
|
|
2114
|
+
});
|
|
2115
|
+
});
|
|
2116
|
+
},
|
|
2117
|
+
enabled: !!account
|
|
2118
|
+
});
|
|
2119
|
+
}
|
|
1904
2120
|
function getHiveEngineTokensMetadataQueryOptions(tokens) {
|
|
1905
2121
|
return queryOptions({
|
|
1906
2122
|
queryKey: ["assets", "hive-engine", "metadata-list", tokens],
|
|
@@ -2088,6 +2304,30 @@ function getHiveEngineTokensMetricsQueryOptions(symbol, interval = "daily") {
|
|
|
2088
2304
|
}
|
|
2089
2305
|
});
|
|
2090
2306
|
}
|
|
2307
|
+
function getHiveEngineUnclaimedRewardsQueryOptions(username) {
|
|
2308
|
+
return queryOptions({
|
|
2309
|
+
queryKey: ["assets", "hive-engine", "unclaimed", username],
|
|
2310
|
+
staleTime: 6e4,
|
|
2311
|
+
refetchInterval: 9e4,
|
|
2312
|
+
enabled: !!username,
|
|
2313
|
+
queryFn: async () => {
|
|
2314
|
+
try {
|
|
2315
|
+
const response = await fetch(
|
|
2316
|
+
CONFIG.privateApiHost + `/private-api/engine-reward-api/${username}?hive=1`
|
|
2317
|
+
);
|
|
2318
|
+
if (!response.ok) {
|
|
2319
|
+
return [];
|
|
2320
|
+
}
|
|
2321
|
+
const data = await response.json();
|
|
2322
|
+
return Object.values(data).filter(
|
|
2323
|
+
({ pending_token }) => pending_token > 0
|
|
2324
|
+
);
|
|
2325
|
+
} catch (e) {
|
|
2326
|
+
return [];
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
});
|
|
2330
|
+
}
|
|
2091
2331
|
async function delegateEngineToken(payload) {
|
|
2092
2332
|
const parsedAsset = parseAsset(payload.amount);
|
|
2093
2333
|
const quantity = parsedAsset.amount.toString();
|
|
@@ -3541,13 +3781,13 @@ function getTronAssetGeneralInfoQueryOptions(username) {
|
|
|
3541
3781
|
// src/modules/wallets/queries/get-account-wallet-asset-info-query-options.ts
|
|
3542
3782
|
function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { refetch: false }) {
|
|
3543
3783
|
const queryClient = getQueryClient();
|
|
3544
|
-
const fetchQuery = async (
|
|
3784
|
+
const fetchQuery = async (queryOptions43) => {
|
|
3545
3785
|
if (options2.refetch) {
|
|
3546
|
-
await queryClient.fetchQuery(
|
|
3786
|
+
await queryClient.fetchQuery(queryOptions43);
|
|
3547
3787
|
} else {
|
|
3548
|
-
await queryClient.prefetchQuery(
|
|
3788
|
+
await queryClient.prefetchQuery(queryOptions43);
|
|
3549
3789
|
}
|
|
3550
|
-
return queryClient.getQueryData(
|
|
3790
|
+
return queryClient.getQueryData(queryOptions43.queryKey);
|
|
3551
3791
|
};
|
|
3552
3792
|
const portfolioQuery = getVisionPortfolioQueryOptions(username);
|
|
3553
3793
|
const getPortfolioAssetInfo = async () => {
|
|
@@ -4084,6 +4324,6 @@ function useWalletOperation(username, asset, operation) {
|
|
|
4084
4324
|
// src/index.ts
|
|
4085
4325
|
rememberScryptBsvVersion();
|
|
4086
4326
|
|
|
4087
|
-
export { AssetOperation, EcencyWalletBasicTokens, EcencyWalletCurrency, private_api_exports as EcencyWalletsPrivateApi, HIVE_ACCOUNT_OPERATION_GROUPS, HIVE_OPERATION_LIST, HIVE_OPERATION_NAME_BY_ID, HIVE_OPERATION_ORDERS, NaiMap, PointTransactionType, Symbol2 as Symbol, broadcastWithWalletHiveAuth, buildAptTx, buildEthTx, buildExternalTx, buildPsbt, buildSolTx, buildTonTx, buildTronTx, claimInterestHive, decryptMemoWithAccounts, decryptMemoWithKeys, delay, delegateEngineToken, delegateHive, deriveHiveKey, deriveHiveKeys, deriveHiveMasterPasswordKey, deriveHiveMasterPasswordKeys, detectHiveKeyDerivation, encryptMemoWithAccounts, encryptMemoWithKeys, getAccountWalletAssetInfoQueryOptions, getAccountWalletListQueryOptions, getAllTokensListQueryOptions, getBoundFetch, getHbdAssetGeneralInfoQueryOptions, getHbdAssetTransactionsQueryOptions, getHiveAssetGeneralInfoQueryOptions, getHiveAssetMetricQueryOptions, getHiveAssetTransactionsQueryOptions, getHiveAssetWithdrawalRoutesQueryOptions, getHiveEngineTokenGeneralInfoQueryOptions, getHiveEngineTokenTransactionsQueryOptions, getHiveEngineTokensBalancesQueryOptions, getHiveEngineTokensMarketQueryOptions, getHiveEngineTokensMetadataQueryOptions, getHiveEngineTokensMetricsQueryOptions, getHivePowerAssetGeneralInfoQueryOptions, getHivePowerAssetTransactionsQueryOptions, getHivePowerDelegatesInfiniteQueryOptions, getHivePowerDelegatingsQueryOptions, getLarynxAssetGeneralInfoQueryOptions, getLarynxPowerAssetGeneralInfoQueryOptions, getPointsAssetGeneralInfoQueryOptions, getPointsAssetTransactionsQueryOptions, getPointsQueryOptions, getSpkAssetGeneralInfoQueryOptions, getSpkMarketsQueryOptions, getTokenOperationsQueryOptions, getTokenPriceQueryOptions, getVisionPortfolioQueryOptions, getWallet, hasWalletHiveAuthBroadcast, isEmptyDate, lockLarynx, mnemonicToSeedBip39, parseAsset, powerDownHive, powerUpHive, powerUpLarynx, registerWalletHiveAuthBroadcast, resolveHiveOperationFilters, rewardSpk, signDigest, signExternalTx, signExternalTxAndBroadcast, signTx, signTxAndBroadcast, stakeEngineToken, transferEngineToken, transferFromSavingsHive, transferHive, transferLarynx, transferPoint, transferSpk, transferToSavingsHive, undelegateEngineToken, unstakeEngineToken, useClaimPoints, useClaimRewards, useGetExternalWalletBalanceQuery, useHiveKeysQuery, useImportWallet, useSaveWalletInformationToMetadata, useSeedPhrase, useWalletCreate, useWalletOperation, useWalletsCacheQuery, vestsToHp, withdrawVestingRouteHive };
|
|
4327
|
+
export { AssetOperation, EcencyWalletBasicTokens, EcencyWalletCurrency, private_api_exports as EcencyWalletsPrivateApi, HIVE_ACCOUNT_OPERATION_GROUPS, HIVE_OPERATION_LIST, HIVE_OPERATION_NAME_BY_ID, HIVE_OPERATION_ORDERS, HiveEngineToken, NaiMap, PointTransactionType, Symbol2 as Symbol, broadcastWithWalletHiveAuth, buildAptTx, buildEthTx, buildExternalTx, buildPsbt, buildSolTx, buildTonTx, buildTronTx, claimInterestHive, decryptMemoWithAccounts, decryptMemoWithKeys, delay, delegateEngineToken, delegateHive, deriveHiveKey, deriveHiveKeys, deriveHiveMasterPasswordKey, deriveHiveMasterPasswordKeys, detectHiveKeyDerivation, encryptMemoWithAccounts, encryptMemoWithKeys, formattedNumber, getAccountWalletAssetInfoQueryOptions, getAccountWalletListQueryOptions, getAllHiveEngineTokensQueryOptions, getAllTokensListQueryOptions, getBoundFetch, getHbdAssetGeneralInfoQueryOptions, getHbdAssetTransactionsQueryOptions, getHiveAssetGeneralInfoQueryOptions, getHiveAssetMetricQueryOptions, getHiveAssetTransactionsQueryOptions, getHiveAssetWithdrawalRoutesQueryOptions, getHiveEngineBalancesWithUsdQueryOptions, getHiveEngineTokenGeneralInfoQueryOptions, getHiveEngineTokenTransactionsQueryOptions, getHiveEngineTokensBalancesQueryOptions, getHiveEngineTokensMarketQueryOptions, getHiveEngineTokensMetadataQueryOptions, getHiveEngineTokensMetricsQueryOptions, getHiveEngineUnclaimedRewardsQueryOptions, getHivePowerAssetGeneralInfoQueryOptions, getHivePowerAssetTransactionsQueryOptions, getHivePowerDelegatesInfiniteQueryOptions, getHivePowerDelegatingsQueryOptions, getLarynxAssetGeneralInfoQueryOptions, getLarynxPowerAssetGeneralInfoQueryOptions, getPointsAssetGeneralInfoQueryOptions, getPointsAssetTransactionsQueryOptions, getPointsQueryOptions, getSpkAssetGeneralInfoQueryOptions, getSpkMarketsQueryOptions, getSpkWalletQueryOptions, getTokenOperationsQueryOptions, getTokenPriceQueryOptions, getVisionPortfolioQueryOptions, getWallet, hasWalletHiveAuthBroadcast, isEmptyDate, lockLarynx, mnemonicToSeedBip39, parseAsset, powerDownHive, powerUpHive, powerUpLarynx, registerWalletHiveAuthBroadcast, resolveHiveOperationFilters, rewardSpk, signDigest, signExternalTx, signExternalTxAndBroadcast, signTx, signTxAndBroadcast, stakeEngineToken, transferEngineToken, transferFromSavingsHive, transferHive, transferLarynx, transferPoint, transferSpk, transferToSavingsHive, undelegateEngineToken, unstakeEngineToken, useClaimPoints, useClaimRewards, useGetExternalWalletBalanceQuery, useHiveKeysQuery, useImportWallet, useSaveWalletInformationToMetadata, useSeedPhrase, useWalletCreate, useWalletOperation, useWalletsCacheQuery, vestsToHp, withdrawVestingRouteHive };
|
|
4088
4328
|
//# sourceMappingURL=index.mjs.map
|
|
4089
4329
|
//# sourceMappingURL=index.mjs.map
|