Skip to content

Commit 994e526

Browse files
authored
feat(namadillo): fixing errors when extension is connected and user doesn't have an account (#1125)
1 parent a47e2f7 commit 994e526

File tree

6 files changed

+30
-8
lines changed

6 files changed

+30
-8
lines changed

apps/namadillo/src/App/AccountOverview/AccountOverview.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
applicationFeaturesAtom,
99
namadaExtensionConnectedAtom,
1010
} from "atoms/settings";
11+
import { useUserHasAccount } from "hooks/useUserHasAccount";
1112
import { useAtomValue } from "jotai";
1213
import { twMerge } from "tailwind-merge";
1314
import { AccountBalanceContainer } from "./AccountBalanceContainer";
@@ -16,24 +17,25 @@ import { NavigationFooter } from "./NavigationFooter";
1617

1718
export const AccountOverview = (): JSX.Element => {
1819
const isConnected = useAtomValue(namadaExtensionConnectedAtom);
20+
const hasAccount = useUserHasAccount();
1921
const { claimRewardsEnabled, maspEnabled } = useAtomValue(
2022
applicationFeaturesAtom
2123
);
2224

23-
const showSidebar = isConnected;
25+
const showSidebar = isConnected && hasAccount !== undefined;
2426

2527
return (
2628
<PageWithSidebar>
2729
<div className={twMerge("flex w-full", !showSidebar && "col-span-2")}>
28-
{!isConnected && (
30+
{(!isConnected || hasAccount === false) && (
2931
<section className="flex rounded-sm items-center w-full bg-black">
3032
<div className="w-[420px] mx-auto">
3133
<Intro />
3234
</div>
3335
</section>
3436
)}
3537

36-
{isConnected && !claimRewardsEnabled && (
38+
{isConnected && hasAccount && !claimRewardsEnabled && (
3739
<section className="flex items-center bg-black rounded-sm w-full">
3840
<Stack gap={5} className="my-auto min-w-[365px] mx-auto py-12">
3941
<AccountBalanceContainer />
@@ -42,7 +44,7 @@ export const AccountOverview = (): JSX.Element => {
4244
</section>
4345
)}
4446

45-
{isConnected && claimRewardsEnabled && (
47+
{isConnected && hasAccount && claimRewardsEnabled && (
4648
<section className="flex flex-col w-full rounded-sm min-h-full gap-2">
4749
<div className="grid grid-cols-[1.25fr_1fr] gap-2">
4850
<Panel className="pl-4 pr-6 py-5">

apps/namadillo/src/App/Governance/GovernanceOverview.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
atomsAreLoaded,
99
useNotifyOnAtomError,
1010
} from "atoms/utils";
11+
import { useUserHasAccount } from "hooks/useUserHasAccount";
1112
import { useAtomValue } from "jotai";
1213
import { AllProposalsTable } from "./AllProposalsTable";
1314
import { LiveGovernanceProposals } from "./LiveGovernanceProposals";
@@ -19,10 +20,11 @@ export const GovernanceOverview: React.FC = () => {
1920
const isConnected = useAtomValue(namadaExtensionConnectedAtom);
2021
const allProposals = useAtomValue(allProposalsAtom);
2122
const votedProposals = useAtomValue(votedProposalsAtom);
23+
const hasAccount = useUserHasAccount();
2224

2325
// TODO: is there a better way than this to show that votedProposalIdsAtom
2426
// is dependent on isConnected?
25-
const extensionAtoms = isConnected ? [votedProposals] : [];
27+
const extensionAtoms = isConnected && hasAccount ? [votedProposals] : [];
2628
const activeAtoms = [allProposals, ...extensionAtoms];
2729

2830
const liveProposals =
@@ -44,6 +46,9 @@ export const GovernanceOverview: React.FC = () => {
4446
{!isConnected && (
4547
<ConnectBanner text="To vote please connect your account" />
4648
)}
49+
{isConnected && hasAccount === false && (
50+
<ConnectBanner text="To vote please create or import an account using Namada keychain" />
51+
)}
4752
<ProposalListPanel
4853
title="Live Proposals"
4954
errorText="Unable to load live governance proposals"

apps/namadillo/src/App/Staking/AllValidatorsTable.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { namadaExtensionConnectedAtom } from "atoms/settings";
99
import { atomsAreLoading, atomsAreNotInitialized } from "atoms/utils";
1010
import { allValidatorsAtom } from "atoms/validators";
1111
import BigNumber from "bignumber.js";
12+
import { useUserHasAccount } from "hooks/useUserHasAccount";
1213
import { useValidatorFilter } from "hooks/useValidatorFilter";
1314
import { useValidatorTableSorting } from "hooks/useValidatorTableSorting";
1415
import { useAtomValue } from "jotai";
@@ -33,6 +34,7 @@ export const AllValidatorsTable = ({
3334
const isConnected = useAtomValue(namadaExtensionConnectedAtom);
3435
const navigate = useNavigate();
3536
const [searchTerm, setSearchTerm] = useState("");
37+
const hasAccount = useUserHasAccount();
3638

3739
const filteredValidators = useValidatorFilter({
3840
validators: validators.isSuccess ? validators.data : [],
@@ -117,7 +119,7 @@ export const AllValidatorsTable = ({
117119
onChange={(value: string) => setSearchTerm(value)}
118120
placeholder="Search Validator"
119121
/>
120-
{isConnected && (
122+
{isConnected && hasAccount && (
121123
<ActionButton
122124
size="sm"
123125
backgroundColor="cyan"

apps/namadillo/src/App/Staking/StakingOverview.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import { ValidatorDiversification } from "App/Sidebars/ValidatorDiversification"
55
import { YourStakingDistribution } from "App/Sidebars/YourStakingDistribution";
66
import { namadaExtensionConnectedAtom } from "atoms/settings";
77
import { myValidatorsAtom } from "atoms/validators";
8+
import { useUserHasAccount } from "hooks/useUserHasAccount";
89
import { useAtomValue } from "jotai";
910
import { AllValidatorsTable } from "./AllValidatorsTable";
1011
import { MyValidatorsTable } from "./MyValidatorsTable";
1112
import { StakingSummary } from "./StakingSummary";
1213
import { UnbondingAmountsTable } from "./UnbondingAmountsTable";
1314

1415
export const StakingOverview = (): JSX.Element => {
16+
const hasAccount = useUserHasAccount();
1517
const isConnected = useAtomValue(namadaExtensionConnectedAtom);
1618
const myValidators = useAtomValue(myValidatorsAtom);
1719
const hasStaking = myValidators.data?.some((v) => v.stakedAmount?.gt(0));
@@ -26,7 +28,10 @@ export const StakingOverview = (): JSX.Element => {
2628
{!isConnected && (
2729
<ConnectBanner text="To stake please connect your account" />
2830
)}
29-
{isConnected && <StakingSummary />}
31+
{isConnected && hasAccount === false && (
32+
<ConnectBanner text="To stake please create or import an account using Namada keychain" />
33+
)}
34+
{isConnected && hasAccount && <StakingSummary />}
3035
{hasStaking && (
3136
<Panel title="My Validators" className="relative grid">
3237
<MyValidatorsTable />
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defaultAccountAtom } from "atoms/accounts";
2+
import { useAtomValue } from "jotai";
3+
4+
export const useUserHasAccount = (): boolean | undefined => {
5+
const account = useAtomValue(defaultAccountAtom);
6+
if (account.isPending) return undefined;
7+
return Boolean(account.data);
8+
};

apps/namadillo/src/theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export const colors = {
33
balance: "#ffffff",
44
unbond: "#DD1599",
55
shielded: "#ffff00",
6-
empty: "2F2F2F",
6+
empty: "#2F2F2F",
77
};
88

99
export const keyframes = {

0 commit comments

Comments
 (0)