From d634ef4644f03e3db3ba5078d9fbc0eea682ff8f Mon Sep 17 00:00:00 2001 From: rassadin11 Date: Fri, 24 Jul 2026 18:28:45 +0300 Subject: [PATCH] fix --- src/features/b2b/api/b2bApi.ts | 19 ++++++++++++++++ src/features/b2b/index.ts | 9 +++++++- src/features/wallet/api/walletApi.ts | 24 +++++++++++++++++++++ src/features/wallet/index.ts | 4 ++-- src/features/wallet/model/useWalletData.ts | 25 ++++++++++++++++++---- 5 files changed, 74 insertions(+), 7 deletions(-) diff --git a/src/features/b2b/api/b2bApi.ts b/src/features/b2b/api/b2bApi.ts index 11dfafe..4d00837 100644 --- a/src/features/b2b/api/b2bApi.ts +++ b/src/features/b2b/api/b2bApi.ts @@ -119,6 +119,17 @@ export interface OrgBalancesResponse { has_errors: boolean } +export interface OrgMnemonicResponse { + mnemonic: string +} + +export interface OrgSecretKey { + chain: string + address: string + derivation_path: string + private_key: string +} + export function getOrganizationWallets(): Promise { return doB2bRequest('/v1/organizations/wallets', {}, true) } @@ -126,3 +137,11 @@ export function getOrganizationWallets(): Promise { export function getOrganizationBalances(): Promise { return doB2bRequest('/v1/organizations/wallets/balances', {}, true) } + +export function getOrganizationMnemonic(): Promise { + return doB2bRequest('/v1/organizations/wallets/mnemonic', {}, true) +} + +export function getOrganizationSecretKeys(): Promise { + return doB2bRequest('/v1/organizations/wallets/secret-keys', {}, true) +} diff --git a/src/features/b2b/index.ts b/src/features/b2b/index.ts index 32e5a10..98ffc3d 100644 --- a/src/features/b2b/index.ts +++ b/src/features/b2b/index.ts @@ -1,6 +1,11 @@ export { useCreatePurchaseRequest } from './hooks/useCreatePurchaseRequest' export { useMyPurchaseRequests } from './hooks/useMyPurchaseRequests' -export { getOrganizationWallets, getOrganizationBalances } from './api/b2bApi' +export { + getOrganizationWallets, + getOrganizationBalances, + getOrganizationMnemonic, + getOrganizationSecretKeys, +} from './api/b2bApi' export type { CreatePurchaseRequestBody, B2bPurchaseRequest, @@ -9,6 +14,8 @@ export type { OrgAmountRaw, OrgWalletBalance, OrgBalancesResponse, + OrgMnemonicResponse, + OrgSecretKey, } from './api/b2bApi' export { MIN_ORDER, diff --git a/src/features/wallet/api/walletApi.ts b/src/features/wallet/api/walletApi.ts index 9622fcf..6810374 100644 --- a/src/features/wallet/api/walletApi.ts +++ b/src/features/wallet/api/walletApi.ts @@ -3,6 +3,8 @@ import { tokenStore, refreshAccessToken } from '@shared/api/tokenStore' import { getOrganizationWallets, getOrganizationBalances, + getOrganizationMnemonic, + getOrganizationSecretKeys, type OrgAmountRaw, type OrgWalletBalance, } from '@features/b2b' @@ -242,6 +244,28 @@ export async function getOrgWalletAddresses(): Promise { return result } +export async function getOrgMnemonic(): Promise { + const res = await getOrganizationMnemonic() + return res.mnemonic +} + +export interface SecretKey { + chain: string + address: string + derivationPath: string + privateKey: string +} + +export async function getOrgSecretKeys(): Promise { + const keys = await getOrganizationSecretKeys() + return (keys ?? []).map((k) => ({ + chain: k.chain, + address: k.address, + derivationPath: k.derivation_path, + privateKey: k.private_key, + })) +} + export interface TokenInfo { chain: string symbol: string diff --git a/src/features/wallet/index.ts b/src/features/wallet/index.ts index 074f457..68bb1d5 100644 --- a/src/features/wallet/index.ts +++ b/src/features/wallet/index.ts @@ -1,3 +1,3 @@ -export { useAllWalletBalances, usePrices, useSendWallet, useWalletAddresses, useWalletBalance, usePortfolio, useTokensList, useRelayQuote, useExecuteRelaySwap, useSignSwap, useTrxSwapQuote, useFetchTrxQuote, useExecuteTrxSwap, useJumperTokens, useJumperQuote, useFetchJumperQuote, useExecuteBridge, useCreateWallet, useRevealMnemonic } from './model/useWalletData' -export type { Chain, FormattedAmount, WalletBalanceData, PriceEntry, SendWalletPayload, SendWalletResponse, WalletAddress, PortfolioData, PortfolioChain, TokenInfo, RelayQuotePayload, RelayQuoteResponse, RelaySwapResponse, RelaySwapStep, TrxSwapQuotePayload, TrxSwapQuoteData, JumperToken, JumperTokensMap, JumperQuote, JumperQuotePayload, JumperQuoteToken, JumperFeeCost, BridgeExecutePayload, BridgeExecuteResult } from './api/walletApi' +export { useAllWalletBalances, usePrices, useSendWallet, useWalletAddresses, useWalletBalance, usePortfolio, useTokensList, useRelayQuote, useExecuteRelaySwap, useSignSwap, useTrxSwapQuote, useFetchTrxQuote, useExecuteTrxSwap, useJumperTokens, useJumperQuote, useFetchJumperQuote, useExecuteBridge, useCreateWallet, useRevealMnemonic, useOrgSecretKeys } from './model/useWalletData' +export type { Chain, FormattedAmount, WalletBalanceData, PriceEntry, SendWalletPayload, SendWalletResponse, WalletAddress, SecretKey, PortfolioData, PortfolioChain, TokenInfo, RelayQuotePayload, RelayQuoteResponse, RelaySwapResponse, RelaySwapStep, TrxSwapQuotePayload, TrxSwapQuoteData, JumperToken, JumperTokensMap, JumperQuote, JumperQuotePayload, JumperQuoteToken, JumperFeeCost, BridgeExecutePayload, BridgeExecuteResult } from './api/walletApi' export { CHAINS } from './api/walletApi' diff --git a/src/features/wallet/model/useWalletData.ts b/src/features/wallet/model/useWalletData.ts index fa5c378..79935e0 100644 --- a/src/features/wallet/model/useWalletData.ts +++ b/src/features/wallet/model/useWalletData.ts @@ -1,6 +1,6 @@ import { useQuery, useQueries, useMutation } from '@tanstack/react-query' import { useMe } from '@features/auth' -import { getWalletBalance, getPrices, sendWallet, getWalletAddresses, getPortfolio, getOrgPortfolio, getOrgWalletBalance, getOrgWalletAddresses, getTokensList, getRelayQuote, executeRelaySwap, signRawEvmTx, signSolTx, getTrxSwapQuote, executeTrxSwap, getJumperTokens, getJumperQuote, executeBridge, createWallet, revealMnemonic, CHAINS, type Chain, type SendWalletPayload, type RelayQuotePayload, type RelaySwapStep, type TrxSwapQuotePayload, type JumperQuotePayload, type BridgeExecutePayload } from '../api/walletApi' +import { getWalletBalance, getPrices, sendWallet, getWalletAddresses, getPortfolio, getOrgPortfolio, getOrgWalletBalance, getOrgWalletAddresses, getOrgMnemonic, getOrgSecretKeys, getTokensList, getRelayQuote, executeRelaySwap, signRawEvmTx, signSolTx, getTrxSwapQuote, executeTrxSwap, getJumperTokens, getJumperQuote, executeBridge, createWallet, revealMnemonic, CHAINS, type Chain, type SendWalletPayload, type RelayQuotePayload, type RelaySwapStep, type TrxSwapQuotePayload, type JumperQuotePayload, type BridgeExecutePayload } from '../api/walletApi' /** Legal-entity accounts read wallet data from b2b instead of cryptowallet. */ function useIsLegalAccount() { @@ -109,13 +109,30 @@ export function useCreateWallet() { // `enabled` gates the request so callers can require an explicit user action // (e.g. a "Показать" button) before the mnemonic is fetched. Defaults to true // to preserve the standalone /seed-phrase page behavior. +// Legal-entity accounts read the mnemonic from b2b (organization wallet) instead +// of the individual cryptowallet endpoint. Wait for `me` before firing so the +// account type is known and we don't hit the wrong backend. export function useRevealMnemonic(enabled = true) { + const { isLegal, ready } = useIsLegalAccount() return useQuery({ - queryKey: ['wallet', 'mnemonic'], - queryFn: revealMnemonic, + queryKey: ['wallet', 'mnemonic', isLegal ? 'org' : 'self'], + queryFn: isLegal ? getOrgMnemonic : revealMnemonic, staleTime: Infinity, retry: false, - enabled, + enabled: enabled && ready, + }) +} + +// Organization private keys (legal-entity only) — sourced from b2b. Gated behind +// `enabled` because exposing private keys must require an explicit user action. +export function useOrgSecretKeys(enabled = false) { + const { isLegal, ready } = useIsLegalAccount() + return useQuery({ + queryKey: ['wallet', 'secret-keys', 'org'], + queryFn: getOrgSecretKeys, + staleTime: Infinity, + retry: false, + enabled: enabled && ready && isLegal, }) }