@ecency/sdk 1.5.21 → 1.5.22

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.
@@ -2353,8 +2353,8 @@ function toEntryArray(x) {
2353
2353
  return Array.isArray(x) ? x : [];
2354
2354
  }
2355
2355
  async function getVisibleFirstLevelThreadItems(container) {
2356
- const queryOptions88 = getDiscussionsQueryOptions(container, "created" /* created */, true);
2357
- const discussionItemsRaw = await CONFIG.queryClient.fetchQuery(queryOptions88);
2356
+ const queryOptions89 = getDiscussionsQueryOptions(container, "created" /* created */, true);
2357
+ const discussionItemsRaw = await CONFIG.queryClient.fetchQuery(queryOptions89);
2358
2358
  const discussionItems = toEntryArray(discussionItemsRaw);
2359
2359
  if (discussionItems.length <= 1) {
2360
2360
  return [];
@@ -4926,6 +4926,163 @@ function getRecurrentTransfersQueryOptions(username) {
4926
4926
  enabled: !!username
4927
4927
  });
4928
4928
  }
4929
+ function normalizeString(value) {
4930
+ if (typeof value === "string") {
4931
+ const trimmed = value.trim();
4932
+ return trimmed.length > 0 ? trimmed : void 0;
4933
+ }
4934
+ return void 0;
4935
+ }
4936
+ function normalizeNumber(value) {
4937
+ if (typeof value === "number" && Number.isFinite(value)) {
4938
+ return value;
4939
+ }
4940
+ if (typeof value === "string") {
4941
+ const trimmed = value.trim();
4942
+ if (!trimmed) {
4943
+ return void 0;
4944
+ }
4945
+ const direct = Number.parseFloat(trimmed);
4946
+ if (Number.isFinite(direct)) {
4947
+ return direct;
4948
+ }
4949
+ const sanitized = trimmed.replace(/,/g, "");
4950
+ const match = sanitized.match(/[-+]?\d+(?:\.\d+)?/);
4951
+ if (match) {
4952
+ const parsed = Number.parseFloat(match[0]);
4953
+ if (Number.isFinite(parsed)) {
4954
+ return parsed;
4955
+ }
4956
+ }
4957
+ }
4958
+ return void 0;
4959
+ }
4960
+ function parseToken(rawToken) {
4961
+ if (!rawToken || typeof rawToken !== "object") {
4962
+ return void 0;
4963
+ }
4964
+ const token = rawToken;
4965
+ return {
4966
+ name: normalizeString(token.name) ?? "",
4967
+ symbol: normalizeString(token.symbol) ?? "",
4968
+ layer: normalizeString(token.layer) ?? "hive",
4969
+ balance: normalizeNumber(token.balance) ?? 0,
4970
+ fiatRate: normalizeNumber(token.fiatRate) ?? 0,
4971
+ currency: normalizeString(token.currency) ?? "usd",
4972
+ precision: normalizeNumber(token.precision) ?? 3,
4973
+ address: normalizeString(token.address),
4974
+ error: normalizeString(token.error),
4975
+ pendingRewards: normalizeNumber(token.pendingRewards),
4976
+ pendingRewardsFiat: normalizeNumber(token.pendingRewardsFiat),
4977
+ liquid: normalizeNumber(token.liquid),
4978
+ liquidFiat: normalizeNumber(token.liquidFiat),
4979
+ savings: normalizeNumber(token.savings),
4980
+ savingsFiat: normalizeNumber(token.savingsFiat),
4981
+ staked: normalizeNumber(token.staked),
4982
+ stakedFiat: normalizeNumber(token.stakedFiat),
4983
+ iconUrl: normalizeString(token.iconUrl),
4984
+ actions: token.actions ?? [],
4985
+ extraData: token.extraData ?? [],
4986
+ apr: normalizeNumber(token.apr)
4987
+ };
4988
+ }
4989
+ function extractTokens(payload) {
4990
+ if (!payload || typeof payload !== "object") {
4991
+ return [];
4992
+ }
4993
+ const containers = [payload];
4994
+ const record = payload;
4995
+ if (record.data && typeof record.data === "object") {
4996
+ containers.push(record.data);
4997
+ }
4998
+ if (record.result && typeof record.result === "object") {
4999
+ containers.push(record.result);
5000
+ }
5001
+ if (record.portfolio && typeof record.portfolio === "object") {
5002
+ containers.push(record.portfolio);
5003
+ }
5004
+ for (const container of containers) {
5005
+ if (Array.isArray(container)) {
5006
+ return container;
5007
+ }
5008
+ if (container && typeof container === "object") {
5009
+ for (const key of [
5010
+ "wallets",
5011
+ "tokens",
5012
+ "assets",
5013
+ "items",
5014
+ "portfolio",
5015
+ "balances"
5016
+ ]) {
5017
+ const value = container[key];
5018
+ if (Array.isArray(value)) {
5019
+ return value;
5020
+ }
5021
+ }
5022
+ }
5023
+ }
5024
+ return [];
5025
+ }
5026
+ function resolveUsername(payload) {
5027
+ if (!payload || typeof payload !== "object") {
5028
+ return void 0;
5029
+ }
5030
+ const record = payload;
5031
+ return normalizeString(record.username) ?? normalizeString(record.name) ?? normalizeString(record.account);
5032
+ }
5033
+ function getPortfolioQueryOptions(username, currency = "usd", onlyEnabled = true) {
5034
+ return queryOptions({
5035
+ queryKey: [
5036
+ "wallet",
5037
+ "portfolio",
5038
+ "v2",
5039
+ username,
5040
+ onlyEnabled ? "only-enabled" : "all",
5041
+ currency
5042
+ ],
5043
+ enabled: Boolean(username),
5044
+ staleTime: 6e4,
5045
+ refetchInterval: 12e4,
5046
+ queryFn: async () => {
5047
+ if (!username) {
5048
+ throw new Error("[SDK][Wallet] \u2013 username is required");
5049
+ }
5050
+ if (CONFIG.privateApiHost === void 0 || CONFIG.privateApiHost === null) {
5051
+ throw new Error(
5052
+ "[SDK][Wallet] \u2013 privateApiHost isn't configured for portfolio"
5053
+ );
5054
+ }
5055
+ const endpoint = `${CONFIG.privateApiHost}/wallet-api/portfolio-v2`;
5056
+ const response = await fetch(endpoint, {
5057
+ method: "POST",
5058
+ headers: {
5059
+ Accept: "application/json",
5060
+ "Content-Type": "application/json"
5061
+ },
5062
+ body: JSON.stringify({ username, onlyEnabled, currency })
5063
+ });
5064
+ if (!response.ok) {
5065
+ throw new Error(
5066
+ `[SDK][Wallet] \u2013 Portfolio request failed (${response.status})`
5067
+ );
5068
+ }
5069
+ const payload = await response.json();
5070
+ const tokens = extractTokens(payload).map((item) => parseToken(item)).filter((item) => Boolean(item));
5071
+ if (!tokens.length) {
5072
+ throw new Error(
5073
+ "[SDK][Wallet] \u2013 Portfolio payload contained no tokens"
5074
+ );
5075
+ }
5076
+ return {
5077
+ username: resolveUsername(payload) ?? username,
5078
+ currency: normalizeString(
5079
+ payload?.fiatCurrency ?? payload?.currency
5080
+ )?.toUpperCase(),
5081
+ wallets: tokens
5082
+ };
5083
+ }
5084
+ });
5085
+ }
4929
5086
  function getWitnessesInfiniteQueryOptions(limit) {
4930
5087
  return infiniteQueryOptions({
4931
5088
  queryKey: ["witnesses", "list", limit],
@@ -5799,6 +5956,6 @@ async function getSpkMarkets() {
5799
5956
  return await response.json();
5800
5957
  }
5801
5958
 
5802
- export { ACCOUNT_OPERATION_GROUPS, ALL_ACCOUNT_OPERATIONS, ALL_NOTIFY_TYPES, CONFIG, ConfigManager, mutations_exports as EcencyAnalytics, EcencyQueriesManager, HiveSignerIntegration, NaiMap, NotificationFilter, NotificationViewType, NotifyTypes, ROLES, SortOrder, Symbol2 as Symbol, ThreeSpeakIntegration, addDraft, addImage, addSchedule, bridgeApiCall, broadcastJson, buildProfileMetadata, checkUsernameWalletsPendingQueryOptions, decodeObj, dedupeAndSortKeyAuths, deleteDraft, deleteImage, deleteSchedule, downVotingPower, encodeObj, extractAccountProfile, getAccountFullQueryOptions, getAccountNotificationsInfiniteQueryOptions, getAccountPendingRecoveryQueryOptions, getAccountPosts, getAccountPostsInfiniteQueryOptions, getAccountPostsQueryOptions, getAccountRcQueryOptions, getAccountRecoveriesQueryOptions, getAccountReputationsQueryOptions, getAccountSubscriptionsQueryOptions, getAccountVoteHistoryInfiniteQueryOptions, getAccountsQueryOptions, getAnnouncementsQueryOptions, getBookmarksInfiniteQueryOptions, getBookmarksQueryOptions, getBoostPlusAccountPricesQueryOptions, getBoostPlusPricesQueryOptions, getBotsQueryOptions, getBoundFetch, getChainPropertiesQueryOptions, getCollateralizedConversionRequestsQueryOptions, getCommentHistoryQueryOptions, getCommunities, getCommunitiesQueryOptions, getCommunity, getCommunityContextQueryOptions, getCommunityPermissions, getCommunityQueryOptions, getCommunitySubscribersQueryOptions, getCommunityType, getContentQueryOptions, getContentRepliesQueryOptions, getControversialRisingInfiniteQueryOptions, getConversionRequestsQueryOptions, getCurrencyRate, getCurrencyRates, getCurrencyTokenRate, getDeletedEntryQueryOptions, getDiscoverCurationQueryOptions, getDiscoverLeaderboardQueryOptions, getDiscussion, getDiscussionQueryOptions, getDiscussionsQueryOptions, getDraftsInfiniteQueryOptions, getDraftsQueryOptions, getDynamicPropsQueryOptions, getEntryActiveVotesQueryOptions, getFavouritesInfiniteQueryOptions, getFavouritesQueryOptions, getFollowCountQueryOptions, getFollowersQueryOptions, getFollowingQueryOptions, getFragmentsInfiniteQueryOptions, getFragmentsQueryOptions, getFriendsInfiniteQueryOptions, getGalleryImagesQueryOptions, getGameStatusCheckQueryOptions, getHiveEngineMetrics, getHiveEngineOpenOrders, getHiveEngineOrderBook, getHiveEngineTokenMetrics, getHiveEngineTokenTransactions, getHiveEngineTokensBalances, getHiveEngineTokensMarket, getHiveEngineTokensMetadata, getHiveEngineTradeHistory, getHiveEngineUnclaimedRewards, getHiveHbdStatsQueryOptions, getHivePoshLinksQueryOptions, getHivePrice, getImagesInfiniteQueryOptions, getImagesQueryOptions, getIncomingRcQueryOptions, getMarketData, getMarketDataQueryOptions, getMarketHistoryQueryOptions, getMarketStatisticsQueryOptions, getMutedUsersQueryOptions, getNormalizePostQueryOptions, getNotificationSetting, getNotifications, getNotificationsInfiniteQueryOptions, getNotificationsSettingsQueryOptions, getNotificationsUnreadCountQueryOptions, getOpenOrdersQueryOptions, getOrderBookQueryOptions, getOutgoingRcDelegationsInfiniteQueryOptions, getPageStatsQueryOptions, getPointsQueryOptions, getPost, getPostHeader, getPostHeaderQueryOptions, getPostQueryOptions, getPostTipsQueryOptions, getPostsRanked, getPostsRankedInfiniteQueryOptions, getPostsRankedQueryOptions, getProfiles, getProfilesQueryOptions, getPromotePriceQueryOptions, getPromotedPost, getPromotedPostsQuery, getProposalQueryOptions, getProposalVotesInfiniteQueryOptions, getProposalsQueryOptions, getQueryClient, getRcStatsQueryOptions, getReblogsQueryOptions, getReceivedVestingSharesQueryOptions, getRecurrentTransfersQueryOptions, getReferralsInfiniteQueryOptions, getReferralsStatsQueryOptions, getRelationshipBetweenAccounts, getRelationshipBetweenAccountsQueryOptions, getRewardedCommunitiesQueryOptions, getSavingsWithdrawFromQueryOptions, getSchedulesInfiniteQueryOptions, getSchedulesQueryOptions, getSearchAccountQueryOptions, getSearchAccountsByUsernameQueryOptions, getSearchApiInfiniteQueryOptions, getSearchFriendsQueryOptions, getSearchPathQueryOptions, getSearchTopicsQueryOptions, getSimilarEntriesQueryOptions, getSpkMarkets, getSpkWallet, getStatsQueryOptions, getSubscribers, getSubscriptions, getTradeHistoryQueryOptions, getTransactionsInfiniteQueryOptions, getTrendingTagsQueryOptions, getTrendingTagsWithStatsQueryOptions, getUserPostVoteQueryOptions, getUserProposalVotesQueryOptions, getVestingDelegationsQueryOptions, getVisibleFirstLevelThreadItems, getWavesByHostQueryOptions, getWavesByTagQueryOptions, getWavesFollowingQueryOptions, getWavesTrendingTagsQueryOptions, getWithdrawRoutesQueryOptions, getWitnessesInfiniteQueryOptions, hsTokenRenew, isCommunity, isWrappedResponse, lookupAccountsQueryOptions, makeQueryClient, mapThreadItemsToWaveEntries, markNotifications, moveSchedule, normalizePost, normalizeToWrappedResponse, normalizeWaveEntryFromApi, onboardEmail, parseAccounts, parseAsset, parseProfileMetadata, powerRechargeTime, rcPower, resolvePost, roleMap, saveNotificationSetting, search, searchAccount, searchPath, searchQueryOptions, searchTag, signUp, sortDiscussions, subscribeEmail, toEntryArray, updateDraft, uploadImage, useAccountFavouriteAdd, useAccountFavouriteDelete, useAccountRelationsUpdate, useAccountRevokeKey, useAccountRevokePosting, useAccountUpdate, useAccountUpdateKeyAuths, useAccountUpdatePassword, useAccountUpdateRecovery, useAddDraft, useAddFragment, useAddImage, useAddSchedule, useBookmarkAdd, useBookmarkDelete, useBroadcastMutation, useDeleteDraft, useDeleteImage, useDeleteSchedule, useEditFragment, useGameClaim, useMarkNotificationsRead, useMoveSchedule, useRecordActivity, useRemoveFragment, useSignOperationByHivesigner, useSignOperationByKey, useSignOperationByKeychain, useUpdateDraft, useUploadImage, usrActivity, validatePostCreating, votingPower, votingValue };
5959
+ export { ACCOUNT_OPERATION_GROUPS, ALL_ACCOUNT_OPERATIONS, ALL_NOTIFY_TYPES, CONFIG, ConfigManager, mutations_exports as EcencyAnalytics, EcencyQueriesManager, HiveSignerIntegration, NaiMap, NotificationFilter, NotificationViewType, NotifyTypes, ROLES, SortOrder, Symbol2 as Symbol, ThreeSpeakIntegration, addDraft, addImage, addSchedule, bridgeApiCall, broadcastJson, buildProfileMetadata, checkUsernameWalletsPendingQueryOptions, decodeObj, dedupeAndSortKeyAuths, deleteDraft, deleteImage, deleteSchedule, downVotingPower, encodeObj, extractAccountProfile, getAccountFullQueryOptions, getAccountNotificationsInfiniteQueryOptions, getAccountPendingRecoveryQueryOptions, getAccountPosts, getAccountPostsInfiniteQueryOptions, getAccountPostsQueryOptions, getAccountRcQueryOptions, getAccountRecoveriesQueryOptions, getAccountReputationsQueryOptions, getAccountSubscriptionsQueryOptions, getAccountVoteHistoryInfiniteQueryOptions, getAccountsQueryOptions, getAnnouncementsQueryOptions, getBookmarksInfiniteQueryOptions, getBookmarksQueryOptions, getBoostPlusAccountPricesQueryOptions, getBoostPlusPricesQueryOptions, getBotsQueryOptions, getBoundFetch, getChainPropertiesQueryOptions, getCollateralizedConversionRequestsQueryOptions, getCommentHistoryQueryOptions, getCommunities, getCommunitiesQueryOptions, getCommunity, getCommunityContextQueryOptions, getCommunityPermissions, getCommunityQueryOptions, getCommunitySubscribersQueryOptions, getCommunityType, getContentQueryOptions, getContentRepliesQueryOptions, getControversialRisingInfiniteQueryOptions, getConversionRequestsQueryOptions, getCurrencyRate, getCurrencyRates, getCurrencyTokenRate, getDeletedEntryQueryOptions, getDiscoverCurationQueryOptions, getDiscoverLeaderboardQueryOptions, getDiscussion, getDiscussionQueryOptions, getDiscussionsQueryOptions, getDraftsInfiniteQueryOptions, getDraftsQueryOptions, getDynamicPropsQueryOptions, getEntryActiveVotesQueryOptions, getFavouritesInfiniteQueryOptions, getFavouritesQueryOptions, getFollowCountQueryOptions, getFollowersQueryOptions, getFollowingQueryOptions, getFragmentsInfiniteQueryOptions, getFragmentsQueryOptions, getFriendsInfiniteQueryOptions, getGalleryImagesQueryOptions, getGameStatusCheckQueryOptions, getHiveEngineMetrics, getHiveEngineOpenOrders, getHiveEngineOrderBook, getHiveEngineTokenMetrics, getHiveEngineTokenTransactions, getHiveEngineTokensBalances, getHiveEngineTokensMarket, getHiveEngineTokensMetadata, getHiveEngineTradeHistory, getHiveEngineUnclaimedRewards, getHiveHbdStatsQueryOptions, getHivePoshLinksQueryOptions, getHivePrice, getImagesInfiniteQueryOptions, getImagesQueryOptions, getIncomingRcQueryOptions, getMarketData, getMarketDataQueryOptions, getMarketHistoryQueryOptions, getMarketStatisticsQueryOptions, getMutedUsersQueryOptions, getNormalizePostQueryOptions, getNotificationSetting, getNotifications, getNotificationsInfiniteQueryOptions, getNotificationsSettingsQueryOptions, getNotificationsUnreadCountQueryOptions, getOpenOrdersQueryOptions, getOrderBookQueryOptions, getOutgoingRcDelegationsInfiniteQueryOptions, getPageStatsQueryOptions, getPointsQueryOptions, getPortfolioQueryOptions, getPost, getPostHeader, getPostHeaderQueryOptions, getPostQueryOptions, getPostTipsQueryOptions, getPostsRanked, getPostsRankedInfiniteQueryOptions, getPostsRankedQueryOptions, getProfiles, getProfilesQueryOptions, getPromotePriceQueryOptions, getPromotedPost, getPromotedPostsQuery, getProposalQueryOptions, getProposalVotesInfiniteQueryOptions, getProposalsQueryOptions, getQueryClient, getRcStatsQueryOptions, getReblogsQueryOptions, getReceivedVestingSharesQueryOptions, getRecurrentTransfersQueryOptions, getReferralsInfiniteQueryOptions, getReferralsStatsQueryOptions, getRelationshipBetweenAccounts, getRelationshipBetweenAccountsQueryOptions, getRewardedCommunitiesQueryOptions, getSavingsWithdrawFromQueryOptions, getSchedulesInfiniteQueryOptions, getSchedulesQueryOptions, getSearchAccountQueryOptions, getSearchAccountsByUsernameQueryOptions, getSearchApiInfiniteQueryOptions, getSearchFriendsQueryOptions, getSearchPathQueryOptions, getSearchTopicsQueryOptions, getSimilarEntriesQueryOptions, getSpkMarkets, getSpkWallet, getStatsQueryOptions, getSubscribers, getSubscriptions, getTradeHistoryQueryOptions, getTransactionsInfiniteQueryOptions, getTrendingTagsQueryOptions, getTrendingTagsWithStatsQueryOptions, getUserPostVoteQueryOptions, getUserProposalVotesQueryOptions, getVestingDelegationsQueryOptions, getVisibleFirstLevelThreadItems, getWavesByHostQueryOptions, getWavesByTagQueryOptions, getWavesFollowingQueryOptions, getWavesTrendingTagsQueryOptions, getWithdrawRoutesQueryOptions, getWitnessesInfiniteQueryOptions, hsTokenRenew, isCommunity, isWrappedResponse, lookupAccountsQueryOptions, makeQueryClient, mapThreadItemsToWaveEntries, markNotifications, moveSchedule, normalizePost, normalizeToWrappedResponse, normalizeWaveEntryFromApi, onboardEmail, parseAccounts, parseAsset, parseProfileMetadata, powerRechargeTime, rcPower, resolvePost, roleMap, saveNotificationSetting, search, searchAccount, searchPath, searchQueryOptions, searchTag, signUp, sortDiscussions, subscribeEmail, toEntryArray, updateDraft, uploadImage, useAccountFavouriteAdd, useAccountFavouriteDelete, useAccountRelationsUpdate, useAccountRevokeKey, useAccountRevokePosting, useAccountUpdate, useAccountUpdateKeyAuths, useAccountUpdatePassword, useAccountUpdateRecovery, useAddDraft, useAddFragment, useAddImage, useAddSchedule, useBookmarkAdd, useBookmarkDelete, useBroadcastMutation, useDeleteDraft, useDeleteImage, useDeleteSchedule, useEditFragment, useGameClaim, useMarkNotificationsRead, useMoveSchedule, useRecordActivity, useRemoveFragment, useSignOperationByHivesigner, useSignOperationByKey, useSignOperationByKeychain, useUpdateDraft, useUploadImage, usrActivity, validatePostCreating, votingPower, votingValue };
5803
5960
  //# sourceMappingURL=index.mjs.map
5804
5961
  //# sourceMappingURL=index.mjs.map