From 8840c94a92b30254a6193a7e6fa985afba33e4ab Mon Sep 17 00:00:00 2001 From: ronaldsg Date: Wed, 23 Oct 2024 09:53:54 -0500 Subject: [PATCH] Add btc account select on top bar --- src/common/components/layouts/Top.vue | 166 ++++++++++++++++++++++++-- 1 file changed, 157 insertions(+), 9 deletions(-) diff --git a/src/common/components/layouts/Top.vue b/src/common/components/layouts/Top.vue index f9b8adb9..17382ff7 100644 --- a/src/common/components/layouts/Top.vue +++ b/src/common/components/layouts/Top.vue @@ -7,6 +7,100 @@

PowPeg

+
+ + {{ connectedBtcWallet }} | {{ selectedBtcAccountBalance }} + {{ selectedBtcAccountBalance.toBTCString() }} {{ environmentContext.getBtcTicker() }} + + +
+
+ + + + + + + + + + + + + +
+ Loading balances... + +
+
('web3Session', constants.SESSION_GET_CHECKSUMMED_ACCOUNT); + const connectedBtcWallet = useGetter('pegInTx', constants.WALLET_NAME); + const selectedBtcAccountBalance = useGetter('pegInTx', constants.PEGIN_TX_GET_SELECTED_BALANCE); + const stateSelectedAccount = useStateAttribute('pegInTx', 'selectedAccount'); const truncatedAccount = computed(() => truncateString(account.value)); const balance = useStateAttribute('web3Session', 'balance'); + const loadingBalance = useStateAttribute('pegInTx', 'loadingBalance'); + const balances = useStateAttribute('pegInTx', 'balances'); const environmentContext = EnvironmentContextProviderService.getEnvironmentContext(); const accountBalance = computed(() => { @@ -68,6 +165,34 @@ export default { }); const clearSession = useAction('web3Session', constants.WEB3_SESSION_CLEAR_ACCOUNT); + + const balancesPerAccountType = computed(() => ([ + { + title: balances.value.legacy.toBTCTrimmedString(), + value: constants.BITCOIN_LEGACY_ADDRESS, + appendText: 'Legacy', + appendColor: 'pink', + }, + { + title: balances.value.segwit.toBTCTrimmedString(), + value: constants.BITCOIN_SEGWIT_ADDRESS, + appendText: 'Segwit', + appendColor: 'orange', + }, + { + title: balances.value.nativeSegwit.toBTCTrimmedString(), + value: constants.BITCOIN_NATIVE_SEGWIT_ADDRESS, + appendText: 'Native Segwit', + appendColor: 'teal', + }, + ])); + + const selectedAccountTypeBadge = computed(() => { + const selected = balancesPerAccountType.value + .find(({ value }) => value === selectedAccountType.value); + return { color: selected?.appendColor, text: selected?.appendText }; + }); + function disconnectWallet() { clearSession(); router.push({ name: 'Home' }); @@ -77,10 +202,24 @@ export default { navigator.clipboard.writeText(account.value); } + function goHome() { + if (route.name !== 'Home') router.push({ name: 'Home' }); + } + + function getLogoSrc() { + return vuetifyTheme.global.current.value.dark ? require('@/assets/logo-rootstock-white.svg') : require('@/assets/logo-rootstock-black.svg'); + } + + if (stateSelectedAccount.value) { + selectedAccountType.value = stateSelectedAccount.value; + } + watch(themeLight, (enabledLight) => { vuetifyTheme.global.name.value = enabledLight ? 'light' : 'dark'; }); + const tooltipText = 'Listed amounts represent the balance using addresses from your first account including change.'; + return { goHome, getLogoSrc, @@ -93,6 +232,15 @@ export default { accountBalance, balance, environmentContext, + connectedBtcWallet, + selectedBtcAccountBalance, + loadingBalance, + balancesPerAccountType, + selectedAccountType, + mdiBitcoin, + mdiInformation, + selectedAccountTypeBadge, + tooltipText, }; }, };