From f111f53e64326468e40a01555ebde12d6a7329f2 Mon Sep 17 00:00:00 2001 From: netbonus <151201453+netbonus@users.noreply.github.com> Date: Wed, 24 Sep 2025 12:53:50 -0400 Subject: [PATCH 1/2] adds wallet based xpub --- src/components/btc-wallet/XpubPage.tsx | 58 +++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/src/components/btc-wallet/XpubPage.tsx b/src/components/btc-wallet/XpubPage.tsx index 093e511..06b01bc 100644 --- a/src/components/btc-wallet/XpubPage.tsx +++ b/src/components/btc-wallet/XpubPage.tsx @@ -5,6 +5,8 @@ import React, { useContext, useEffect, useState } from "react"; import { AppContext } from "../../store/AppContext"; import { useFeature } from "../../hooks/useFeature"; import { PageContent } from "../index"; +import { constants, getBtcPurpose } from "../../util/helpers"; + const { Search, TextArea } = Input; const SEARCH_ID = "xpub-data"; @@ -13,13 +15,14 @@ interface XpubPageProps { } const XpubPage: React.FC = ({ session }) => { - const context = useContext(AppContext); + const { isMobile } = useContext(AppContext); const { SUPPORTS_XPUB } = useFeature(); const [xpub, setXpub] = useState(null); const [windowWidth, setWindowWidth] = useState( document.getElementById("main-content-inner")?.offsetWidth ); const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); useEffect(() => { updateXpubAddress(); @@ -34,17 +37,31 @@ const XpubPage: React.FC = ({ session }) => { const updateXpubAddress = async () => { if (!session) return; + // Get the active BTC purpose (wallet type) + const btcPurpose = getBtcPurpose(); + if (btcPurpose === constants.BTC_PURPOSE_NONE) { + setError("BTC Wallet is hidden. Please enable it in settings to view XPUB."); + return; + } + setLoading(true); + setError(null); + try { + // Use the active wallet's BTC purpose as the derivation path const addresses = await session.client?.getAddresses({ - startPath: [44 + 0x80000000, 0 + 0x80000000, 0 + 0x80000000], - flag: 6, + startPath: [btcPurpose, constants.BTC_COIN, 0 + constants.HARDENED_OFFSET], + flag: 6, // LatticeGetAddressesFlag.secp256k1Xpub }); + if (addresses && addresses.length > 0) { setXpub(addresses[0]); + } else { + setError("No XPUB returned from device"); } } catch (err) { console.error("Error fetching XPUB:", err); + setError("Failed to fetch XPUB from device"); } finally { setLoading(false); } @@ -61,8 +78,22 @@ const XpubPage: React.FC = ({ session }) => { } }; + const getWalletTypeLabel = () => { + const btcPurpose = getBtcPurpose(); + switch (btcPurpose) { + case constants.BTC_PURPOSE_LEGACY: + return "Legacy"; + case constants.BTC_PURPOSE_WRAPPED_SEGWIT: + return "Wrapped SegWit"; + case constants.BTC_PURPOSE_SEGWIT: + return "Native SegWit"; + default: + return "Unknown"; + } + }; + const renderXpubBox = () => { - if (context.isMobile) { + if (isMobile) { return (