Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: moved wallet connection feature from staking to global accessible component (#498) #762

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ed3d40b
update: rearranged TopNavBar
quiet-node Oct 11, 2023
881bf19
update: added WalletChoser component to TopNavBar component
quiet-node Oct 11, 2023
045b9c4
feat: added connecting wallet logic to Navbar
quiet-node Oct 11, 2023
2136fe3
update: added accountID to wallet section after connected
quiet-node Oct 11, 2023
12c2634
update: added new logoURL field to WalletDriver class
quiet-node Oct 12, 2023
6e99383
update: added new wallet icon to connect wallet button
quiet-node Oct 12, 2023
b445c3c
style: smaller connect wallet button
quiet-node Oct 12, 2023
c09a7d7
dapp-feat: added new WalletInfo component
quiet-node Oct 13, 2023
cd6bb06
test: fixed unit test to match with new UI
quiet-node Oct 13, 2023
8315974
update(style+test): restyled connect wallet button and fix correspond…
quiet-node Oct 13, 2023
334f3bb
style: thinner network selector's border
quiet-node Oct 13, 2023
e9a4038
update: removed connect button in Stake component and fix corresponde…
quiet-node Oct 13, 2023
86fc6c0
update: added guard conditions to router-link
quiet-node Oct 16, 2023
c289115
update: used copyable component for copyable content in WalletInfo co…
quiet-node Oct 16, 2023
13b6314
update: re-order wallet logo urls
quiet-node Oct 24, 2023
d2f3de4
feat: integrated change wallet account feature to WalletInfo component
quiet-node Oct 24, 2023
e9e5e16
test: fixed unit tests
quiet-node Oct 31, 2023
b06aaa2
update: reworked grid width layout
quiet-node Nov 1, 2023
b99b7fe
update: removed Disconnect button in Staking.vue component
quiet-node Nov 2, 2023
234943f
Restore styling of network selector.
svienot Nov 21, 2023
1eefc34
Fix responsiveness of TopNavBar.vue
svienot Nov 21, 2023
58e6346
Remove focus ring for network drop-down-menu.
svienot Nov 22, 2023
eeffea2
Fix padding of left navigation item in TopNavBar.vue
svienot Nov 22, 2023
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
14 changes: 6 additions & 8 deletions src/assets/styles/explorer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,12 @@ body {
//

#drop-down-menu .o-sel {
height: 44.5px;
height: 40px;
font-weight: bold;
color: $h-highlight-color;
border-color: $h-highlight-color;
background-color: $h-page-background-color;
border-width: 0.5px;
border-top-width: 0;
padding-top: 20px;
padding-bottom: 7px;
}
#drop-down-menu .o-sel-arrow {
background-position: calc(100% - 7px) calc(100% - 10px);
}
#mobile-drop-down-menu .o-sel {
height: 44.5px;
Expand All @@ -293,6 +287,10 @@ body {
#mobile-drop-down-menu .o-sel-arrow {
background-position: calc(100% - 13px) calc(100% - 16px);
}
#drop-down-menu .h-is-navbar-item:focus
{
outline: none;
}
.button.h-is-navbar-item {
padding-top: 28px;
padding-bottom: 16px;
Expand Down Expand Up @@ -334,7 +332,7 @@ body {
padding-right: 0.4em;
}
.button.h-is-navbar-item.is-ghost.is-first {
padding-left: 2em;
padding-left: 0;
}
.button.h-is-navbar-item.is-ghost.is-last {
padding-right: 0;
Expand Down
4 changes: 2 additions & 2 deletions src/components/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
<form data-cy="searchBar" id="searchBar" class="control is-flex" action="" v-on:submit.prevent="performSearch">
<input
class="input has-text-white h-is-navbar-item"
style="z-index: 1;"
style="z-index: 1; height: 40px"
type="text"
placeholder="Search accounts, transactions, tokens, contracts and topics"
v-model="searchedId"
v-bind:disabled="searchInputDisabled"
ref="search-input"
/>
<button class="button is-dark" type="submit" value="searchBar" style="border-color: white; border-left: none; height: 35px; z-index: 0; outline: none">
<button class="button is-dark" type="submit" value="searchBar" style="border-color: white; border-left: none; height: 40px; z-index: 0; outline: none">
<i v-bind:class="searchButtonIconStyle"/>
</button>
</form>
Expand Down
260 changes: 224 additions & 36 deletions src/components/TopNavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,29 @@
</div>

<div v-else class="is-flex is-justify-content-space-between is-align-items-flex-end">
<div class="is-inline-flex is-align-items-center is-flex-grow-0 is-flex-shrink-0 mr-3">
<WalletChooser v-model:show-dialog="showWalletChooser" v-on:choose-wallet="handleChooseWallet"/>

<ProgressDialog v-model:show-dialog="showProgressDialog"
:mode="progressDialogMode"
:main-message="progressMainMessage"
:extra-message="progressExtraMessage"
:extra-transaction-id="progressExtraTransactionId"
:show-spinner="showProgressSpinner"
>
<template v-slot:dialogTitle>
<span class="h-is-primary-title">{{ progressDialogTitle }}</span>
</template>
</ProgressDialog>

<div class="is-inline-flex is-align-items-center is-flex-grow-0 is-flex-shrink-0 mr-3">
<router-link :to="routeManager.makeRouteToMainDashboard()">
<img id="product-logo" alt="Product Logo" class="image" src="@/assets/branding/brand-product-logo.png">
</router-link>
<AxiosStatus/>
</div>

<div class="is-flex-grow-0 is-flex-shrink-0 is-flex is-flex-direction-column ml-4">
<div class="is-flex mb-3 is-align-items-baseline">

<div id="drop-down-menu">
<o-field>
<o-select v-model="selectedNetwork" class="h-is-navbar-item" style="outline: none">
<option v-for="network in networkEntries" :key="network.name" :value="network.name">
{{ network.displayName }}
</option>
</o-select>
</o-field>
</div>

<div class="is-flex-grow-1 px-2"/>

<div class="is-flex mb-3 is-align-items-baseline is-justify-content-space-between">
<router-link :to="routeManager.makeRouteToMainDashboard()"
id="dashboard-menu-item"
class="button is-ghost is-first h-is-navbar-item h-is-dense"
Expand Down Expand Up @@ -103,7 +105,55 @@
class="button is-ghost is-last h-is-navbar-item h-is-dense"
:class="{ 'is-rimmed': isBlocksRoute}">Blocks</router-link>
</div>
<SearchBar style="margin-top: 4px"/>

<div id="navbar-grid">
<div id="search-bar">
<SearchBar/>
</div>

<div id="drop-down-menu">
<o-field>
<o-select v-model="selectedNetwork" class="h-is-navbar-item">
<option v-for="network in networkEntries" :key="network.name" :value="network.name">
{{ network.displayName }}
</option>
</o-select>
</o-field>
</div>

<div id="connect-button">
<button v-if="!connected" :disabled="connecting" id="connectWalletButton" class="button is-white is-small" @click="chooseWallet" style="outline: none; height: 40px; width: 100%; font-size: 0.8rem;">
{{ connecting ? "Connecting..." : "CONNECT WALLET..." }}
</button>

<div v-else @click="showWalletInfo = !showWalletInfo" id="walletInfoBanner" class="is-flex is-align-items-center" style="outline: none; height: 40px; width: 100%; font-size: 0.9rem; border: 0.5px solid white; display: flex; justify-content: space-between; cursor: pointer;">
<figure style="width: 50px; height: 100%; display: flex; align-items: center; margin-left: 0.15rem;">
<img :src="walletIconURL ?? undefined" alt="wallet logo" style="object-fit: contain; aspect-ratio: 3/2;display: flex; height: 90%;">
</figure>

<p>
{{ accountId }}
</p>

<div class="is-flex is-align-items-center" style="width: 30px; justify-content: center;">
<i v-if="!showWalletInfo" class="fas fa-solid fa-angle-down is-flex is-align-items-center"/>
<i v-else class="fas fa-solid fa-angle-up is-flex is-align-items-center"/>
</div>

</div>
</div>

<WalletInfo
:connected="connected"
:accountIds="accountIds"
:showWalletInfo="showWalletInfo"
:accountId="accountId || undefined"
:walletIconURL="walletIconURL || undefined"
@wallet-disconnect="disconnectFromWallet"
@change-account="handleChangeAccount"
/>

</div>
</div>

</div>
Expand All @@ -116,15 +166,20 @@

<script lang="ts">

import {defineComponent, inject, ref} from "vue";
import {routeManager} from "@/router";
import {routeManager, walletManager} from "@/router";
import SearchBar from "@/components/SearchBar.vue";
import AxiosStatus from "@/components/AxiosStatus.vue";
import {networkRegistry} from "@/schemas/NetworkRegistry";
import WalletChooser from "@/components/staking/WalletChooser.vue";
import { WalletDriver } from '@/utils/wallet/WalletDriver';
import { WalletDriverError } from '@/utils/wallet/WalletDriverError';
import ProgressDialog, { Mode } from './staking/ProgressDialog.vue';
import {defineComponent, inject, ref} from "vue";
import WalletInfo from '@/components/wallet/WalletInfo.vue'

export default defineComponent({
name: "TopNavBar",
components: {AxiosStatus, SearchBar},
components: {AxiosStatus, SearchBar, WalletChooser, ProgressDialog, WalletInfo},

setup() {
const isSmallScreen = inject('isSmallScreen', true)
Expand All @@ -137,27 +192,109 @@ export default defineComponent({

const isMobileMenuOpen = ref(false)

const showWalletChooser = ref(false)
const chooseWallet = () => {
showWalletChooser.value = true
}

const connecting = ref(false)
const walletIconURL = ref("")
const showWalletInfo = ref(false)
const showProgressDialog = ref(false)
const showProgressSpinner = ref(false)
const progressDialogMode = ref(Mode.Busy)
const progressDialogTitle = ref<string|null>(null)
const progressMainMessage = ref<string|null>(null)
const progressExtraMessage = ref<string|null>(null)
const progressExtraTransactionId = ref<string|null>(null)


//
// handleChooseWallet
//
const handleChooseWallet = (wallet: WalletDriver) => {
walletManager.setActiveDriver(wallet)
connecting.value = true
walletManager
.connect()
.catch((reason) => {
console.warn("Failed to connect wallet - reason:" + reason.toString())
showProgressDialog.value = true
progressDialogMode.value = Mode.Error
progressDialogTitle.value = "Could not connect wallet"
showProgressSpinner.value = false
progressExtraTransactionId.value = null
if (reason instanceof WalletDriverError) {
progressMainMessage.value = reason.message
progressExtraMessage.value = reason.extra
} else {
progressMainMessage.value = "Unexpected error"
progressExtraMessage.value = JSON.stringify(reason)
}
})
.finally(() => connecting.value = false)
walletIconURL.value = walletManager.getActiveDriver().iconURL || ""
}

//
// handleChangeAccount
//
const handleChangeAccount = (chosenAccountId: string) => {
walletManager.changeAccount(chosenAccountId)
}

//
// disconnectFromWallet
//
const disconnectFromWallet = () => {
walletManager
.disconnect()
.finally(() => {
connecting.value = false;
showWalletInfo.value = false;
})
}


return {
isSmallScreen,
isMediumScreen,
isTouchDevice,
buildTime,
connecting,
productName,
routeManager,
chooseWallet,
walletIconURL,
isSmallScreen,
isTouchDevice,
isMediumScreen,
showWalletInfo,
isStakingEnabled,
isMobileMenuOpen,
networkEntries: networkRegistry.entries,
selectedNetwork: routeManager.selectedNetwork,
showWalletChooser,
handleChooseWallet,
showProgressDialog,
progressDialogMode,
progressMainMessage,
showProgressSpinner,
progressDialogTitle,
handleChangeAccount,
progressExtraMessage,
disconnectFromWallet,
progressExtraTransactionId,
name: routeManager.currentRoute,
isDashboardRoute: routeManager.isDashboardRoute,
isTransactionRoute: routeManager.isTransactionRoute,
accountId: walletManager.accountId,
connected: walletManager.connected,
accountIds: walletManager.accountIds,
isNodeRoute: routeManager.isNodeRoute,
isTokenRoute: routeManager.isTokenRoute,
isTopicRoute: routeManager.isTopicRoute,
isContractRoute: routeManager.isContractRoute,
isAccountRoute: routeManager.isAccountRoute,
isNodeRoute: routeManager.isNodeRoute,
isStakingRoute: routeManager.isStakingRoute,
networkEntries: networkRegistry.entries,
isBlocksRoute: routeManager.isBlocksRoute,
routeManager,
isStakingRoute: routeManager.isStakingRoute,
isAccountRoute: routeManager.isAccountRoute,
isContractRoute: routeManager.isContractRoute,
selectedNetwork: routeManager.selectedNetwork,
isDashboardRoute: routeManager.isDashboardRoute,
isTransactionRoute: routeManager.isTransactionRoute,
}
},
})
Expand All @@ -170,16 +307,67 @@ export default defineComponent({

<style>

@media (min-width: 1240px) {
@media (min-width: 1450px) {
#product-logo {
max-width: 242px;
}
#navbar-grid {
position:relative;
display:grid;
column-gap:1.2rem;
grid-template-columns:repeat(20, minmax(0, 35px));
}
#search-bar {
grid-column: span 13;
}
#drop-down-menu {
grid-column: span 3;
}
#connect-button {
grid-column: span 4;
}
}

@media (max-width: 1239px) {
#product-logo {
max-width: 220px;
}
@media (max-width: 1449px) {
#product-logo {
max-width: 220px;
}
#navbar-grid {
position:relative;
display:grid;
column-gap:1.2rem;
grid-template-columns:repeat(20, minmax(0, 25px));
}
#search-bar {
grid-column: span 12;
}
#drop-down-menu {
grid-column: span 4;
}
#connect-button {
grid-column: span 4;
}
}

@media (max-width: 1249px) {
#product-logo {
max-width: 200px;
}
#navbar-grid {
position:relative;
display:grid;
column-gap:1.2rem;
grid-template-columns:repeat(20, minmax(0, 18px));
}
#search-bar {
grid-column: span 10;
}
#drop-down-menu {
grid-column: span 5;
}
#connect-button {
grid-column: span 5;
}
}

</style>
3 changes: 1 addition & 2 deletions src/components/staking/WalletChooser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<div v-for="d in drivers" :key="d.name">
<a :id="d.name" @click="chosenWallet=d" @dblclick="handleConnect">
<figure :class="{'selected':isSelected(d)}" class="h-chooser-figure my-4 mr-6">
<img :src="d.iconURL ?? undefined" alt="wallet logo" class="h-chooser-img">
<img :src="d.logoURL ?? undefined" alt="wallet logo" class="h-chooser-img">
</figure>
</a>
</div>
Expand All @@ -51,7 +51,6 @@
<button id="connectButton" :disabled="!chosenWallet" class="button is-info is-small ml-4" @click="handleConnect">CONNECT
</button>
</div>

</div>
</div>
</div>
Expand Down
Loading