Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/wallets/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Patch Changes

- fix(wallets): saving chain addresses no longer deletes engine tokens (#1408)
- Updated dependencies []:
- @ecency/sdk@2.3.82

Expand Down
31 changes: 29 additions & 2 deletions packages/wallets/dist/browser/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as _tanstack_react_query from '@tanstack/react-query';
import { UseMutationOptions } from '@tanstack/react-query';
import { AuthContext, HiveEngineTokenMetadataResponse, AssetOperation } from '@ecency/sdk';
import { AccountProfile, AuthContext, HiveEngineTokenMetadataResponse, AssetOperation } from '@ecency/sdk';
export { Asset, AssetOperation, AuthorReward, CancelTransferFromSavings, ClaimRewardBalance, CollateralizedConvert, CommentBenefactor, CommentPayoutUpdate, CommentReward, CurationReward, DelegateVestingShares, DelegatedVestingShare, EffectiveCommentVote, FillCollateralizedConvertRequest, FillConvertRequest, FillOrder, FillRecurrentTransfers, FillVestingWithdraw, GeneralAssetInfo, GeneralAssetTransaction, HIVE_ACCOUNT_OPERATION_GROUPS, HIVE_OPERATION_LIST, HIVE_OPERATION_NAME_BY_ID, HIVE_OPERATION_ORDERS, HiveBasedAssetSignType, HiveEngineMarketResponse, HiveEngineMetric, HiveEngineOpenOrder, HiveEngineOrderBookEntry, HiveEngineToken, HiveEngineTokenBalance, HiveEngineTokenInfo, HiveEngineTokenMetadataResponse, HiveEngineTokenStatus, HiveEngineTransaction, HiveMarketMetric, HiveOperationFilter, HiveOperationFilterKey, HiveOperationFilterValue, HiveOperationGroup, HiveOperationName, HiveTransaction, WithdrawRoute as HiveWithdrawRoute, Interest, LimitOrderCancel, LimitOrderCreate, NaiMap, PointTransaction, PointTransactionType, Points, PointsResponse, ProducerReward, ProposalPay, ReceivedVestingShare, RecurrentTransfers, ReturnVestingDelegation, SetWithdrawRoute, Symbol, Token, TokenMetadata, Transfer, TransferToSavings, TransferToVesting, UpdateProposalVotes, VoteProxy, WalletOperationPayload, WithdrawVesting, formattedNumber, getAccountWalletAssetInfoQueryOptions, getAllHiveEngineTokensQueryOptions, getHbdAssetGeneralInfoQueryOptions, getHbdAssetTransactionsQueryOptions, getHiveAssetGeneralInfoQueryOptions, getHiveAssetMetricQueryOptions, getHiveAssetTransactionsQueryOptions, getHiveAssetWithdrawalRoutesQueryOptions, getHiveEngineBalancesWithUsdQueryOptions, getHiveEngineTokenGeneralInfoQueryOptions, getHiveEngineTokenTransactionsQueryOptions, getHiveEngineTokensBalancesQueryOptions, getHiveEngineTokensMarketQueryOptions, getHiveEngineTokensMetadataQueryOptions, getHiveEngineTokensMetricsQueryOptions, getHiveEngineUnclaimedRewardsQueryOptions, getHivePowerAssetGeneralInfoQueryOptions, getHivePowerAssetTransactionsQueryOptions, getHivePowerDelegatesInfiniteQueryOptions, getHivePowerDelegatingsQueryOptions, getPointsAssetGeneralInfoQueryOptions, getPointsAssetTransactionsQueryOptions, getPointsQueryOptions, isEmptyDate, parseAsset, resolveHiveOperationFilters, useClaimPoints, useWalletOperation, vestsToHp } from '@ecency/sdk';

declare enum EcencyWalletCurrency {
Expand Down Expand Up @@ -87,6 +87,33 @@ interface AccountPointsResponse {
unclaimed_points: string;
}

/**
* Assemble the `profile.tokens` array to broadcast.
*
* `profile.tokens` is written wholesale, so whatever this returns IS the user's
* new on-chain token list — anything omitted is deleted, and since no app other
* than Ecency writes this field, the deletion is unrecoverable.
*
* Which entries survive depends on what the caller manages, inferred from the
* payload itself:
*
* - A payload carrying non-chain entries comes from the wallet token picker,
* which owns the COMPLETE list — it always sends the basic Hive assets plus
* every selected engine token, and deselecting one means omitting it. Unlisted
* entries are therefore dropped, which is what the user asked for.
* - A CHAIN-only payload comes from the external-wallet screens, which know
* nothing about engine tokens. Their unlisted entries are carried forward.
*
* Inferring rather than taking a flag keeps this fix inside the package (the
* apps resolve it through the committed dist, so a new public option could not
* be used by a caller until the next release). It is also safe in the degenerate
* case: if the picker somehow submits before its token list has loaded, the
* payload is chain-only and we preserve — the non-destructive outcome.
*
* @param existingTokens the account's current on-chain `profile.tokens`
* @param tokens the caller's payload
*/
declare function buildTokensPayload(existingTokens: AccountProfile["tokens"], tokens: EcencyTokenMetadata[]): AccountProfile["tokens"];
/**
* Saving of token(s) metadata to Hive profile
* It may contain: external wallets(see EcencyWalletCurrency), Hive tokens arrangement
Expand Down Expand Up @@ -284,4 +311,4 @@ declare function installHiveSnap(): Promise<void>;
*/
declare function getHivePublicKeys(): Promise<HivePublicKey[]>;

export { type AccountPointsResponse, type EcencyHiveKeys, type EcencyTokenMetadata, EcencyWalletBasicTokens, EcencyWalletCurrency, index as EcencyWalletsPrivateApi, type ExternalWalletBalance, type HiveKeyDerivation, type HivePublicKey, type HiveRole, type TransferableCurrency, type WalletAddressMap, deriveHiveKey, deriveHiveKeys, deriveHiveMasterPasswordKey, deriveHiveMasterPasswordKeys, detectHiveKeyDerivation, discoverMetaMaskWallets, ensureEvmChain, estimateEvmGas, fetchEvmAddress, fetchMultichainAddresses, formatLamports, formatWei, getAccountWalletListQueryOptions, getAllTokensListQueryOptions, getEvmChainConfig, getEvmExplorerUrl, getHivePublicKeys, getSolExplorerUrl, getTokenOperationsQueryOptions, getTokenPriceQueryOptions, installHiveSnap, parseToLamports, parseToWei, sendEvmTransfer, sendSolTransfer, useExternalTransfer, useGetExternalWalletBalanceQuery, useSaveWalletInformationToMetadata };
export { type AccountPointsResponse, type EcencyHiveKeys, type EcencyTokenMetadata, EcencyWalletBasicTokens, EcencyWalletCurrency, index as EcencyWalletsPrivateApi, type ExternalWalletBalance, type HiveKeyDerivation, type HivePublicKey, type HiveRole, type TransferableCurrency, type WalletAddressMap, buildTokensPayload, deriveHiveKey, deriveHiveKeys, deriveHiveMasterPasswordKey, deriveHiveMasterPasswordKeys, detectHiveKeyDerivation, discoverMetaMaskWallets, ensureEvmChain, estimateEvmGas, fetchEvmAddress, fetchMultichainAddresses, formatLamports, formatWei, getAccountWalletListQueryOptions, getAllTokensListQueryOptions, getEvmChainConfig, getEvmExplorerUrl, getHivePublicKeys, getSolExplorerUrl, getTokenOperationsQueryOptions, getTokenPriceQueryOptions, installHiveSnap, parseToLamports, parseToWei, sendEvmTransfer, sendSolTransfer, useExternalTransfer, useGetExternalWalletBalanceQuery, useSaveWalletInformationToMetadata };
61 changes: 36 additions & 25 deletions packages/wallets/dist/browser/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/wallets/dist/browser/index.js.map

Large diffs are not rendered by default.

60 changes: 36 additions & 24 deletions packages/wallets/dist/node/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -652,15 +652,17 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false, cur
}

// src/modules/wallets/mutations/save-wallet-information-to-metadata.ts
var isChainToken = ({
type,
symbol
}) => type === "CHAIN" || Object.values(EcencyWalletCurrency).includes(symbol);
function getGroupedChainTokens(tokens, defaultShow) {
if (!tokens) {
return {};
}
return R__namespace.pipe(
tokens,
R__namespace.filter(
({ type, symbol }) => type === "CHAIN" || Object.values(EcencyWalletCurrency).includes(symbol)
),
R__namespace.filter(isChainToken),
R__namespace.map((item) => {
const meta = {
...item.meta ?? {}
Expand All @@ -680,6 +682,35 @@ function getGroupedChainTokens(tokens, defaultShow) {
)
);
}
function buildTokensPayload(existingTokens, tokens) {
const profileChainTokens = getGroupedChainTokens(existingTokens);
const payloadTokens = tokens.map(({ currency, type, privateKey, username, ...meta }) => ({
symbol: currency,
type: type ?? (Object.values(EcencyWalletCurrency).includes(currency) ? "CHAIN" : void 0),
meta
})) ?? [];
const payloadChainTokens = getGroupedChainTokens(payloadTokens, true);
const payloadNonChainTokens = (payloadTokens ?? []).filter(
(token) => !isChainToken(token)
);
const mergedChainTokens = R__namespace.pipe(
profileChainTokens,
R__namespace.mergeDeep(payloadChainTokens),
R__namespace.values()
);
const managesNonChainTokens = payloadNonChainTokens.length > 0;
const payloadSymbols = new Set(
(payloadTokens ?? []).map(({ symbol }) => symbol)
);
const preservedTokens = managesNonChainTokens ? [] : (existingTokens ?? []).filter(
(token) => !isChainToken(token) && !payloadSymbols.has(token.symbol)
);
return [
...preservedTokens,
...payloadNonChainTokens,
...mergedChainTokens
];
}
function useSaveWalletInformationToMetadata(username, auth, options2) {
const queryClient = reactQuery.useQueryClient();
const { data: accountData } = reactQuery.useQuery(sdk.getAccountFullQueryOptions(username));
Expand All @@ -694,28 +725,8 @@ function useSaveWalletInformationToMetadata(username, auth, options2) {
if (!accountData) {
throw new Error("[SDK][Wallets] \u2013 no account data to save wallets");
}
const profileChainTokens = getGroupedChainTokens(
accountData.profile?.tokens
);
const payloadTokens = tokens.map(({ currency, type, privateKey, username: username2, ...meta }) => ({
symbol: currency,
type: type ?? (Object.values(EcencyWalletCurrency).includes(currency) ? "CHAIN" : void 0),
meta
})) ?? [];
const payloadChainTokens = getGroupedChainTokens(payloadTokens, true);
const payloadNonChainTokens = payloadTokens.filter(
({ type, symbol }) => type !== "CHAIN" && !Object.values(EcencyWalletCurrency).includes(symbol)
);
const mergedChainTokens = R__namespace.pipe(
profileChainTokens,
R__namespace.mergeDeep(payloadChainTokens),
R__namespace.values()
);
return updateProfile({
tokens: [
...payloadNonChainTokens,
...mergedChainTokens
]
tokens: buildTokensPayload(accountData.profile?.tokens, tokens)
});
},
onError: options2?.onError,
Expand Down Expand Up @@ -1322,6 +1333,7 @@ Object.defineProperty(exports, "vestsToHp", {
exports.EcencyWalletBasicTokens = EcencyWalletBasicTokens;
exports.EcencyWalletCurrency = EcencyWalletCurrency;
exports.EcencyWalletsPrivateApi = private_api_exports;
exports.buildTokensPayload = buildTokensPayload;
exports.deriveHiveKey = deriveHiveKey;
exports.deriveHiveKeys = deriveHiveKeys;
exports.deriveHiveMasterPasswordKey = deriveHiveMasterPasswordKey;
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/dist/node/index.cjs.map

Large diffs are not rendered by default.

61 changes: 36 additions & 25 deletions packages/wallets/dist/node/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -631,15 +631,17 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false, cur
}

// src/modules/wallets/mutations/save-wallet-information-to-metadata.ts
var isChainToken = ({
type,
symbol
}) => type === "CHAIN" || Object.values(EcencyWalletCurrency).includes(symbol);
function getGroupedChainTokens(tokens, defaultShow) {
if (!tokens) {
return {};
}
return R.pipe(
tokens,
R.filter(
({ type, symbol }) => type === "CHAIN" || Object.values(EcencyWalletCurrency).includes(symbol)
),
R.filter(isChainToken),
R.map((item) => {
const meta = {
...item.meta ?? {}
Expand All @@ -659,6 +661,35 @@ function getGroupedChainTokens(tokens, defaultShow) {
)
);
}
function buildTokensPayload(existingTokens, tokens) {
const profileChainTokens = getGroupedChainTokens(existingTokens);
const payloadTokens = tokens.map(({ currency, type, privateKey, username, ...meta }) => ({
symbol: currency,
type: type ?? (Object.values(EcencyWalletCurrency).includes(currency) ? "CHAIN" : void 0),
meta
})) ?? [];
const payloadChainTokens = getGroupedChainTokens(payloadTokens, true);
const payloadNonChainTokens = (payloadTokens ?? []).filter(
(token) => !isChainToken(token)
);
const mergedChainTokens = R.pipe(
profileChainTokens,
R.mergeDeep(payloadChainTokens),
R.values()
);
const managesNonChainTokens = payloadNonChainTokens.length > 0;
const payloadSymbols = new Set(
(payloadTokens ?? []).map(({ symbol }) => symbol)
);
const preservedTokens = managesNonChainTokens ? [] : (existingTokens ?? []).filter(
(token) => !isChainToken(token) && !payloadSymbols.has(token.symbol)
);
return [
...preservedTokens,
...payloadNonChainTokens,
...mergedChainTokens
];
}
function useSaveWalletInformationToMetadata(username, auth, options2) {
const queryClient = useQueryClient();
const { data: accountData } = useQuery(getAccountFullQueryOptions(username));
Expand All @@ -673,28 +704,8 @@ function useSaveWalletInformationToMetadata(username, auth, options2) {
if (!accountData) {
throw new Error("[SDK][Wallets] \u2013 no account data to save wallets");
}
const profileChainTokens = getGroupedChainTokens(
accountData.profile?.tokens
);
const payloadTokens = tokens.map(({ currency, type, privateKey, username: username2, ...meta }) => ({
symbol: currency,
type: type ?? (Object.values(EcencyWalletCurrency).includes(currency) ? "CHAIN" : void 0),
meta
})) ?? [];
const payloadChainTokens = getGroupedChainTokens(payloadTokens, true);
const payloadNonChainTokens = payloadTokens.filter(
({ type, symbol }) => type !== "CHAIN" && !Object.values(EcencyWalletCurrency).includes(symbol)
);
const mergedChainTokens = R.pipe(
profileChainTokens,
R.mergeDeep(payloadChainTokens),
R.values()
);
return updateProfile({
tokens: [
...payloadNonChainTokens,
...mergedChainTokens
]
tokens: buildTokensPayload(accountData.profile?.tokens, tokens)
});
},
onError: options2?.onError,
Expand Down Expand Up @@ -1142,6 +1153,6 @@ async function getHivePublicKeys() {
// src/index.ts
rememberScryptBsvVersion();

export { EcencyWalletBasicTokens, EcencyWalletCurrency, private_api_exports as EcencyWalletsPrivateApi, deriveHiveKey, deriveHiveKeys, deriveHiveMasterPasswordKey, deriveHiveMasterPasswordKeys, detectHiveKeyDerivation, discoverMetaMaskWallets, ensureEvmChain, estimateEvmGas, fetchEvmAddress, fetchMultichainAddresses, formatLamports, formatWei, getAccountWalletListQueryOptions, getAllTokensListQueryOptions, getEvmChainConfig, getEvmExplorerUrl, getHivePublicKeys, getSolExplorerUrl, getTokenOperationsQueryOptions, getTokenPriceQueryOptions, installHiveSnap, parseToLamports, parseToWei, sendEvmTransfer, sendSolTransfer, useExternalTransfer, useGetExternalWalletBalanceQuery, useSaveWalletInformationToMetadata };
export { EcencyWalletBasicTokens, EcencyWalletCurrency, private_api_exports as EcencyWalletsPrivateApi, buildTokensPayload, deriveHiveKey, deriveHiveKeys, deriveHiveMasterPasswordKey, deriveHiveMasterPasswordKeys, detectHiveKeyDerivation, discoverMetaMaskWallets, ensureEvmChain, estimateEvmGas, fetchEvmAddress, fetchMultichainAddresses, formatLamports, formatWei, getAccountWalletListQueryOptions, getAllTokensListQueryOptions, getEvmChainConfig, getEvmExplorerUrl, getHivePublicKeys, getSolExplorerUrl, getTokenOperationsQueryOptions, getTokenPriceQueryOptions, installHiveSnap, parseToLamports, parseToWei, sendEvmTransfer, sendSolTransfer, useExternalTransfer, useGetExternalWalletBalanceQuery, useSaveWalletInformationToMetadata };
//# sourceMappingURL=index.mjs.map
//# sourceMappingURL=index.mjs.map
2 changes: 1 addition & 1 deletion packages/wallets/dist/node/index.mjs.map

Large diffs are not rendered by default.

Loading
Loading