-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate legacy auth request to approver ux
- Loading branch information
1 parent
742b38d
commit f17ba48
Showing
6 changed files
with
85 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export function focusTab(tabId: number | null) { | ||
chrome.tabs.update(tabId ?? 0, { active: true }); | ||
} | ||
|
||
export function focusTabAndWindow(tabId: number | null) { | ||
chrome.tabs.update(tabId ?? 0, { active: true }, tab => { | ||
if (!tab) return; | ||
chrome.windows.update(tab.windowId, { focused: true }); | ||
}); | ||
} |
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,48 @@ | ||
import { Box } from 'leather-styles/jsx'; | ||
|
||
import { useAccountDisplayName } from '@app/common/hooks/account/use-account-names'; | ||
import { AccountTotalBalance } from '@app/components/account-total-balance'; | ||
import { AcccountAddresses } from '@app/components/account/account-addresses'; | ||
import { AccountListItemLayout } from '@app/components/account/account-list-item.layout'; | ||
import { AccountNameLayout } from '@app/components/account/account-name'; | ||
import { useCurrentAccountIndex } from '@app/store/accounts/account'; | ||
import { useNativeSegwitSigner } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks'; | ||
import { useStacksAccounts } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks'; | ||
import { AccountAvatarItem } from '@app/ui/components/account/account-avatar/account-avatar-item'; | ||
|
||
interface CurrentAccountCellProps { | ||
onSelectAccount(): void; | ||
} | ||
|
||
export function CurrentAccountCell({ onSelectAccount }: CurrentAccountCellProps) { | ||
const index = useCurrentAccountIndex(); | ||
const stacksAccounts = useStacksAccounts(); | ||
const stxAddress = stacksAccounts[index]?.address || ''; | ||
const { data: name = '' } = useAccountDisplayName({ address: stxAddress, index }); | ||
const bitcoinSigner = useNativeSegwitSigner(index); | ||
const bitcoinAddress = bitcoinSigner?.(0).address || ''; | ||
return ( | ||
<AccountListItemLayout | ||
withChevron | ||
accountAddresses={<AcccountAddresses index={index} />} | ||
accountName={<AccountNameLayout isLoading={false}>{name}</AccountNameLayout>} | ||
avatar={ | ||
<AccountAvatarItem | ||
index={index} | ||
publicKey={stacksAccounts[index]?.stxPublicKey || ''} | ||
name={name} | ||
/> | ||
} | ||
balanceLabel={ | ||
// Hack to center element without adjusting AccountListItemLayout | ||
<Box pos="relative" top={12}> | ||
<AccountTotalBalance stxAddress={stxAddress} btcAddress={bitcoinAddress} /> | ||
</Box> | ||
} | ||
index={index} | ||
isLoading={false} | ||
isSelected={false} | ||
onSelectAccount={() => onSelectAccount()} | ||
/> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,53 +1,39 @@ | ||
import { useEffect } from 'react'; | ||
import { Outlet } from 'react-router-dom'; | ||
|
||
import { Flex, Stack, styled } from 'leather-styles/jsx'; | ||
|
||
import { LeatherLogomarkIcon } from '@leather.io/ui'; | ||
import { noop } from 'rxjs'; | ||
|
||
import { closeWindow } from '@shared/utils'; | ||
|
||
import { useCancelAuthRequest } from '@app/common/authentication/use-cancel-auth-request'; | ||
import { useFinishAuthRequest } from '@app/common/authentication/use-finish-auth-request'; | ||
import { useAppDetails } from '@app/common/hooks/auth/use-app-details'; | ||
import { RequesterFlag } from '@app/components/requester-flag'; | ||
import { ChooseAccountsList } from '@app/pages/choose-account/components/accounts'; | ||
import { useOnMount } from '@app/common/hooks/use-on-mount'; | ||
import { useSwitchAccountSheet } from '@app/common/switch-account/use-switch-account-sheet-context'; | ||
import { CurrentAccountCell } from '@app/features/current-account/current-accout-cell'; | ||
import { useOnOriginTabClose } from '@app/routes/hooks/use-on-tab-closed'; | ||
import { useStacksAccounts } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks'; | ||
import { useCurrentAccountIndex } from '@app/store/accounts/account'; | ||
|
||
import { GetAddressesLayout } from '../rpc-get-addresses/components/get-addresses.layout'; | ||
|
||
export function ChooseAccount() { | ||
const { url } = useAppDetails(); | ||
const accounts = useStacksAccounts(); | ||
const hasConnectedStacksAccounts = accounts.length > 0; | ||
|
||
const cancelAuthentication = useCancelAuthRequest(); | ||
const accountIndex = useCurrentAccountIndex(); | ||
const finishSignIn = useFinishAuthRequest(); | ||
const { toggleSwitchAccount } = useSwitchAccountSheet(); | ||
|
||
useOnOriginTabClose(() => closeWindow()); | ||
|
||
const cancelAuthentication = useCancelAuthRequest(); | ||
|
||
const handleUnmount = async () => cancelAuthentication(); | ||
useOnMount(() => window.addEventListener('beforeunload', handleUnmount)); | ||
|
||
useEffect(() => { | ||
window.addEventListener('beforeunload', handleUnmount); | ||
return () => window.removeEventListener('beforeunload', handleUnmount); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
if (!url) throw new Error('No app details found'); | ||
|
||
return ( | ||
<> | ||
<Flex alignItems="center" flexDirection="column" pt="space.07" width="100%" height="100%"> | ||
<Stack gap="space.05" textAlign="center" alignItems="center"> | ||
{url && <RequesterFlag requester={url.toString()} />} | ||
<LeatherLogomarkIcon height={58} width={248} /> | ||
<Stack gap="space.04"> | ||
<styled.h1 textStyle="heading.05"> | ||
{hasConnectedStacksAccounts | ||
? 'Choose an account to connect' | ||
: 'No connected accounts found'} | ||
</styled.h1> | ||
</Stack> | ||
</Stack> | ||
{hasConnectedStacksAccounts && <ChooseAccountsList />} | ||
</Flex> | ||
<Outlet /> | ||
</> | ||
<GetAddressesLayout | ||
requester={url.origin} | ||
onUserApprovesGetAddresses={async () => await finishSignIn(accountIndex)} | ||
onClickRequestedByLink={noop} | ||
switchAccount={<CurrentAccountCell onSelectAccount={toggleSwitchAccount} />} | ||
/> | ||
); | ||
} |
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