-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wallet-ext: account selector in tokens view (#7628)
* under `wallet-multi-accounts` feature flag * replaces `...` to `…` for ellipsis hook * adds `address` to query key hash for the `useRecentTransactions` to load transactions for the current active address * changes the way we clear objects from store and now we do it from home component until we move it to query When only one account is available or `wallet-multi-accounts` is disabled https://user-images.githubusercontent.com/10210143/216132976-46070a62-85e8-4555-92eb-fb7d8102e61b.mov For multi-accounts https://user-images.githubusercontent.com/10210143/216133460-7cff027c-9c24-4037-8aeb-be4fa3acaf53.mov https://user-images.githubusercontent.com/10210143/216133536-c87ba39b-c8f4-43ab-8154-b4735f8184a9.mov closes: APPS-296
- Loading branch information
1 parent
b4d69b2
commit bbbdbec
Showing
20 changed files
with
248 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useAccounts } from '../hooks/useAccounts'; | ||
import { AccountListItem, type AccountItemProps } from './AccountListItem'; | ||
|
||
export type AccountListProps = { | ||
onAccountSelected: AccountItemProps['onAccountSelected']; | ||
}; | ||
|
||
export function AccountList({ onAccountSelected }: AccountListProps) { | ||
const allAccounts = useAccounts(); | ||
return ( | ||
<div className="flex flex-col items-stretch"> | ||
{allAccounts.map(({ address }) => ( | ||
<AccountListItem | ||
address={address} | ||
key={address} | ||
onAccountSelected={onAccountSelected} | ||
/> | ||
))} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Check12, Copy12 } from '@mysten/icons'; | ||
|
||
import { useMiddleEllipsis } from '../hooks'; | ||
import { useAccounts } from '../hooks/useAccounts'; | ||
import { useActiveAddress } from '../hooks/useActiveAddress'; | ||
import { useCopyToClipboard } from '../hooks/useCopyToClipboard'; | ||
import { Text } from '../shared/text'; | ||
|
||
import type { SuiAddress } from '@mysten/sui.js/src'; | ||
|
||
export type AccountItemProps = { | ||
address: SuiAddress; | ||
onAccountSelected: (address: SuiAddress) => void; | ||
}; | ||
|
||
export function AccountListItem({ | ||
address, | ||
onAccountSelected, | ||
}: AccountItemProps) { | ||
const account = useAccounts([address])[0]; | ||
const activeAddress = useActiveAddress(); | ||
const addressShort = useMiddleEllipsis(address); | ||
const copy = useCopyToClipboard(address, { | ||
copySuccessMessage: 'Address Copied', | ||
}); | ||
if (!account) { | ||
return null; | ||
} | ||
return ( | ||
<div | ||
className="flex p-2.5 items-start gap-2.5 rounded-md hover:bg-sui/10 cursor-pointer focus-visible:ring-1 group transition-colors" | ||
onClick={() => { | ||
onAccountSelected(address); | ||
}} | ||
> | ||
<div className="flex-1"> | ||
<Text color="steel-darker" variant="bodySmall" mono> | ||
{addressShort} | ||
</Text> | ||
</div> | ||
{activeAddress === address ? ( | ||
<Check12 className="text-success" /> | ||
) : null} | ||
<Copy12 | ||
className="text-gray-60 group-hover:text-steel transition-colors hover:!text-hero-dark" | ||
onClick={copy} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useFeature } from '@growthbook/growthbook-react'; | ||
import { Popover, Transition } from '@headlessui/react'; | ||
import { ChevronDown12, Copy12 } from '@mysten/icons'; | ||
|
||
import { useMiddleEllipsis } from '../hooks'; | ||
import { useAccounts } from '../hooks/useAccounts'; | ||
import { useActiveAddress } from '../hooks/useActiveAddress'; | ||
import { useBackgroundClient } from '../hooks/useBackgroundClient'; | ||
import { useCopyToClipboard } from '../hooks/useCopyToClipboard'; | ||
import { ButtonConnectedTo } from '../shared/ButtonConnectedTo'; | ||
import { Text } from '../shared/text'; | ||
import { AccountList } from './AccountList'; | ||
import { FEATURES } from '_src/shared/experimentation/features'; | ||
|
||
export function AccountSelector() { | ||
const allAccounts = useAccounts(); | ||
const activeAddress = useActiveAddress(); | ||
const multiAccountsEnabled = useFeature(FEATURES.WALLET_MULTI_ACCOUNTS).on; | ||
const activeAddressShort = useMiddleEllipsis(activeAddress); | ||
const copyToAddress = useCopyToClipboard(activeAddressShort, { | ||
copySuccessMessage: 'Address copied', | ||
}); | ||
const backgroundClient = useBackgroundClient(); | ||
if (!allAccounts.length) { | ||
return null; | ||
} | ||
const buttonText = ( | ||
<Text mono variant="bodySmall"> | ||
{activeAddressShort} | ||
</Text> | ||
); | ||
if (!multiAccountsEnabled || allAccounts.length === 1) { | ||
return ( | ||
<ButtonConnectedTo | ||
text={buttonText} | ||
onClick={copyToAddress} | ||
iconAfter={<Copy12 />} | ||
bgOnHover="grey" | ||
/> | ||
); | ||
} | ||
return ( | ||
<Popover className="relative z-10"> | ||
{({ close }) => ( | ||
<> | ||
<Popover.Button | ||
as={ButtonConnectedTo} | ||
text={buttonText} | ||
iconAfter={<ChevronDown12 />} | ||
bgOnHover="grey" | ||
/> | ||
<Transition | ||
enter="transition duration-200 ease-out" | ||
enterFrom="transform scale-95 opacity-0" | ||
enterTo="transform scale-100 opacity-100" | ||
leave="transition duration-200 ease-out" | ||
leaveFrom="transform scale-100 opacity-100" | ||
leaveTo="transform scale-75 opacity-0" | ||
> | ||
<Popover.Panel className="absolute left-1/2 -translate-x-1/2 w-50 drop-shadow-accountModal mt-2 z-0 rounded-md bg-white"> | ||
<div className="absolute w-3 h-3 bg-white -top-1 left-1/2 -translate-x-1/2 rotate-45" /> | ||
<div className="relative px-1.25 my-1.25 max-h-80 overflow-y-auto max-w-full z-10"> | ||
<AccountList | ||
onAccountSelected={async ( | ||
selectedAddress | ||
) => { | ||
if (selectedAddress !== activeAddress) { | ||
await backgroundClient.selectAccount( | ||
selectedAddress | ||
); | ||
} | ||
close(); | ||
}} | ||
/> | ||
</div> | ||
</Popover.Panel> | ||
</Transition> | ||
</> | ||
)} | ||
</Popover> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { thunkExtras } from '../redux/store/thunk-extras'; | ||
|
||
export function useBackgroundClient() { | ||
return thunkExtras.background; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
bbbdbec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
explorer – ./apps/explorer
explorer-topaz.vercel.app
explorer.sui.io
explorer-mysten-labs.vercel.app
explorer-git-main-mysten-labs.vercel.app
bbbdbec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
frenemies – ./dapps/frenemies
frenemies-git-main-mysten-labs.vercel.app
frenemies.vercel.app
frenemies-mysten-labs.vercel.app
bbbdbec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
wallet-adapter – ./sdk/wallet-adapter/example