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

fix: use signed stacks account in transaction #4923

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 4 additions & 5 deletions src/app/common/hooks/account/use-account-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ import {
useCurrentAccountNames,
useGetAccountNamesByAddressQuery,
} from '@app/query/stacks/bns/bns.hooks';
import { useCurrentAccountIndex } from '@app/store/accounts/account';
import { useCurrentStacksAccount } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';

export function useCurrentAccountDisplayName() {
const account = useCurrentStacksAccount();
const { data: names = [] } = useCurrentAccountNames();
const index = useCurrentAccountIndex();

return useMemo(() => {
if (isUndefined(index) && (!account || typeof account?.index !== 'number')) return 'Account';
if (isUndefined(account?.index) && (!account || typeof account?.index !== 'number'))
return 'Account';
if (names[0]) return parseIfValidPunycode(names[0]);
return getAutogeneratedAccountDisplayName(index);
}, [account, names, index]);
return getAutogeneratedAccountDisplayName(account?.index);
}, [account, names]);
}

export function useAccountDisplayName({ address, index }: { index: number; address: string }) {
Expand Down
36 changes: 17 additions & 19 deletions src/app/features/current-account/current-account-avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@ import { CircleProps } from 'leather-styles/jsx';
import { useCurrentAccountDisplayName } from '@app/common/hooks/account/use-account-names';
import { useDrawers } from '@app/common/hooks/use-drawers';
import { AccountAvatar } from '@app/components/account/account-avatar';
import { useCurrentAccountIndex } from '@app/store/accounts/account';
import { useStacksAccounts } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';
import { StacksAccount } from '@app/store/accounts/blockchain/stacks/stacks-account.models';

export const CurrentAccountAvatar = memo((props: CircleProps) => {
const accountIndex = useCurrentAccountIndex();
const accounts = useStacksAccounts();
const currentAccount = accounts[accountIndex] as StacksAccount | undefined;
const name = useCurrentAccountDisplayName();
const { setIsShowingSwitchAccountsState } = useDrawers();
if (!currentAccount) return null;
return (
<AccountAvatar
index={currentAccount.index}
name={name}
onClick={() => setIsShowingSwitchAccountsState(true)}
publicKey={currentAccount.stxPublicKey}
{...props}
/>
);
});
export const CurrentAccountAvatar = memo(
(props: CircleProps & { stacksAccount: StacksAccount | undefined }) => {
const { stacksAccount } = props;
const name = useCurrentAccountDisplayName();
const { setIsShowingSwitchAccountsState } = useDrawers();
if (!stacksAccount) return null;
return (
<AccountAvatar
index={stacksAccount.index}
name={name}
onClick={() => setIsShowingSwitchAccountsState(true)}
publicKey={stacksAccount.stxPublicKey}
{...props}
/>
);
}
);
7 changes: 4 additions & 3 deletions src/app/features/current-account/popup-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface PopupHeaderProps {
displayAddresssBalanceOf?: 'all' | 'stx';
}
function PopupHeaderSuspense({ displayAddresssBalanceOf = 'stx' }: PopupHeaderProps) {
const account = useCurrentStacksAccount();
const stacksAccount = useCurrentStacksAccount();
const isBitcoinEnabled = useConfigBitcoinEnabled();
return (
<PopupHeaderLayout>
Expand All @@ -39,6 +39,7 @@ function PopupHeaderSuspense({ displayAddresssBalanceOf = 'stx' }: PopupHeaderPr
fontSize="16px"
fontWeight={500}
size="32px"
stacksAccount={stacksAccount}
/>
}
>
Expand All @@ -49,8 +50,8 @@ function PopupHeaderSuspense({ displayAddresssBalanceOf = 'stx' }: PopupHeaderPr

<HStack alignItems="center" justifyContent="right">
<NetworkModeBadge />
{account && displayAddresssBalanceOf === 'stx' && (
<StxBalance address={account.address} />
{stacksAccount && displayAddresssBalanceOf === 'stx' && (
<StxBalance address={stacksAccount.address} />
)}
{isBitcoinEnabled && displayAddresssBalanceOf === 'all' && <BtcBalance />}
</HStack>
Expand Down
28 changes: 0 additions & 28 deletions src/app/pages/home/components/account-area.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/pages/home/components/home.layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Stack } from 'leather-styles/jsx';

import { AccountInfoCard } from './account-info-card';

type HomeLayoutProps = Record<'currentAccount' | 'children', React.ReactNode>;
type HomeLayoutProps = Record<'children', React.ReactNode>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a HasChildren helper type we could replace this with

export function HomeLayout({ children }: HomeLayoutProps) {
return (
<Stack alignItems="center" width="100%" mx={['', 'space.04']}>
Expand Down
3 changes: 1 addition & 2 deletions src/app/pages/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { InAppMessages } from '@app/features/hiro-messages/in-app-messages';
import { homePageModalRoutes } from '@app/routes/app-routes';
import { ModalBackgroundWrapper } from '@app/routes/components/modal-background-wrapper';

import { CurrentAccount } from './components/account-area';
import { HomeTabs } from './components/home-tabs';
import { HomeLayout } from './components/home.layout';

Expand All @@ -34,7 +33,7 @@ export function Home() {
});

return (
<HomeLayout currentAccount={<CurrentAccount />}>
<HomeLayout>
<FeedbackButton />
<HomeTabs>
<ModalBackgroundWrapper>
Expand Down
Loading