diff --git a/crates/webz-wallet/src/bindgen/wallet.rs b/crates/webz-wallet/src/bindgen/wallet.rs index 322389e..f9a45e3 100644 --- a/crates/webz-wallet/src/bindgen/wallet.rs +++ b/crates/webz-wallet/src/bindgen/wallet.rs @@ -18,6 +18,7 @@ use zcash_client_backend::proto::service::{ compact_tx_streamer_client::CompactTxStreamerClient, ChainSpec, }; use zcash_client_memory::MemoryWalletDb; +use zcash_keys::encoding::AddressCodec; use zcash_keys::keys::UnifiedFullViewingKey; use zcash_primitives::transaction::TxId; @@ -369,6 +370,21 @@ impl WebWallet { } } + /// Get the current unified address for a given account and extracts the transparent component. This is returned as a string in canonical encoding + /// + /// # Arguments + /// + /// * `account_id` - The ID of the account to get the address for + /// + pub async fn get_current_address_transparent(&self, account_id: u32) -> Result { + let db = self.inner.db.read().await; + if let Some(address) = db.get_current_address(account_id.into())? { + Ok(address.transparent().unwrap().encode(&self.inner.network)) + } else { + Err(Error::AccountNotFound(account_id)) + } + } + /////////////////////////////////////////////////////////////////////////////////////// // lightwalletd gRPC methods /////////////////////////////////////////////////////////////////////////////////////// diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index a1e9d30..7f67b59 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/template-snap-monorepo.git" }, "source": { - "shasum": "H66kPf5KzVuH2Wh122uNoA/nMaSXORtaHfgw8z8u71o=", + "shasum": "SA1fH7ay1ietGUsIELeD6rgpMuXu/rusR65jSdjCBrk=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/web-wallet/src/hooks/useWebzjsActions.ts b/packages/web-wallet/src/hooks/useWebzjsActions.ts index 0d741f1..21e1ca8 100644 --- a/packages/web-wallet/src/hooks/useWebzjsActions.ts +++ b/packages/web-wallet/src/hooks/useWebzjsActions.ts @@ -7,7 +7,9 @@ interface WebzjsActions { ufvk: string, birthdayHeight: number, ) => Promise; - getAccountData: () => Promise<{ unifiedAddress: string } | undefined>; + getAccountData: () => Promise< + { unifiedAddress: string; transparentAddress: string } | undefined + >; triggerRescan: () => Promise; flushDbToStore: () => Promise; syncStateWithWallet: () => Promise; @@ -18,17 +20,17 @@ export function useWebZjsActions(): WebzjsActions { const getAccountData = useCallback(async () => { try { - if (state.activeAccount !== undefined) { - return { - unifiedAddress: await state.webWallet!.get_current_address( - state.activeAccount, - ), - }; - } else { - return { - unifiedAddress: await state.webWallet!.get_current_address(0), - }; - } + const accountIndex = state.activeAccount ?? 0; + + const unifiedAddress = + await state.webWallet!.get_current_address(accountIndex); + const transparentAddress = + await state.webWallet!.get_current_address_transparent(accountIndex); + + return { + unifiedAddress, + transparentAddress, + }; } catch (error) { dispatch({ type: 'set-error', diff --git a/packages/web-wallet/src/pages/Receive/Receive.tsx b/packages/web-wallet/src/pages/Receive/Receive.tsx index 991c89b..0b28ca5 100644 --- a/packages/web-wallet/src/pages/Receive/Receive.tsx +++ b/packages/web-wallet/src/pages/Receive/Receive.tsx @@ -13,7 +13,13 @@ enum AddressType { function Receive(): React.JSX.Element { const [loading, setLoading] = useState(true); const [activeTab, setActiveTab] = useState(AddressType.UNIFIED); - const [unifiedAddress, setUnifiedAddress] = useState(''); + const [addresses, setAddresses] = useState<{ + unifiedAddress: string; + transparentAddress: string; + }>({ + unifiedAddress: '', + transparentAddress: '', + }); const [error, setError] = useState(null); const { getAccountData } = useWebZjsActions(); @@ -21,10 +27,15 @@ function Receive(): React.JSX.Element { const fetchData = async () => { try { const data = await getAccountData(); - if (data) setUnifiedAddress(data.unifiedAddress); - setLoading(false); + if (data) + setAddresses({ + unifiedAddress: data.unifiedAddress, + transparentAddress: data.transparentAddress, + }); } catch (err) { setError('Failed to fetch account data'); + } finally { + setLoading(false); } }; @@ -34,11 +45,9 @@ function Receive(): React.JSX.Element { const tabs = { [AddressType.UNIFIED]: { label: 'Unified Address', - component: , }, [AddressType.TRANSPARENT]: { label: 'Transparent Address', - component:
TODO: Transparent address
, }, }; @@ -54,14 +63,19 @@ function Receive(): React.JSX.Element { {Object.keys(tabs).map((tab) => ( setActiveTab(tab as AddressType)} /> ))} - {/* Tabs content */} - {tabs[activeTab].component} + {activeTab === AddressType.UNIFIED && ( + + )} + {activeTab === AddressType.TRANSPARENT && ( + + )} )} {error &&
{error}
} diff --git a/packages/web-wallet/src/pages/Receive/Tab.tsx b/packages/web-wallet/src/pages/Receive/Tab.tsx index 6daaca5..bc3fbb4 100644 --- a/packages/web-wallet/src/pages/Receive/Tab.tsx +++ b/packages/web-wallet/src/pages/Receive/Tab.tsx @@ -3,15 +3,16 @@ import { CircleDashedSvg, CircleSvg } from '../../assets'; import cn from 'classnames'; interface TabProps { + tabName: string; label: string; isActive: boolean; - onClick: () => void; + onClick: (key: string) => void; } -const Tab: React.FC = ({ label, isActive, onClick }) => { +const Tab: React.FC = ({ tabName, label, isActive, onClick }) => { return (
onClick(tabName)} className={cn( 'px-4 py-2 justify-center items-center gap-1.5 flex rounded-3xl cursor-pointer', {