-
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 5153b22
Showing
13 changed files
with
113 additions
and
279 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
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
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 was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
src/app/features/current-account/current-account-displayer.tsx
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,47 @@ | ||
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 CurrentAccountDisplayerProps { | ||
onSelectAccount(): void; | ||
} | ||
export function CurrentAccountDisplayer({ onSelectAccount }: CurrentAccountDisplayerProps) { | ||
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,41 @@ | ||
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 { useOnMount } from '@app/common/hooks/use-on-mount'; | ||
import { useSwitchAccountSheet } from '@app/common/switch-account/use-switch-account-sheet-context'; | ||
import { openInNewTab } from '@app/common/utils/open-in-new-tab'; | ||
import { CurrentAccountDisplayer } from '@app/features/current-account/current-account-displayer'; | ||
import { useOnOriginTabClose } from '@app/routes/hooks/use-on-tab-closed'; | ||
import { useCurrentAccountIndex } from '@app/store/accounts/account'; | ||
|
||
import { ConnectAccountLayout } from '../../components/connect-account/connect-account.layout'; | ||
|
||
export function LegacyAccountAuth() { | ||
const { url } = useAppDetails(); | ||
const accountIndex = useCurrentAccountIndex(); | ||
const finishSignIn = useFinishAuthRequest(); | ||
const { toggleSwitchAccount } = useSwitchAccountSheet(); | ||
|
||
useOnOriginTabClose(() => closeWindow()); | ||
|
||
// const cancelAuthentication = useCancelAuthRequest(); | ||
|
||
// const handleUnmount = async () => cancelAuthentication(); | ||
// useOnMount(() => window.addEventListener('beforeunload', handleUnmount)); | ||
|
||
if (!url) throw new Error('No app details found'); | ||
|
||
return ( | ||
<ConnectAccountLayout | ||
requester={url.origin} | ||
onUserApprovesGetAddresses={async () => finishSignIn(accountIndex)} | ||
// Here we should refocus the tab that initiated the request, however | ||
// because the old auth code doesn't have the tab id and should be | ||
// eventually removed, we just open in a new tab | ||
onClickRequestedByLink={() => openInNewTab(url.origin)} | ||
switchAccount={<CurrentAccountDisplayer onSelectAccount={toggleSwitchAccount} />} | ||
/> | ||
); | ||
} |
Oops, something went wrong.