forked from leather-io/extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rework onboarding ledger flow, closes leather-io#4281
- Loading branch information
1 parent
ceaf228
commit 47aa2e2
Showing
74 changed files
with
1,188 additions
and
286 deletions.
There are no files selected for viewing
Binary file not shown.
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,29 +1,32 @@ | ||
import { useMemo } from 'react'; | ||
|
||
import { isUndefined } from '@shared/utils'; | ||
|
||
import { parseIfValidPunycode } from '@app/common/utils'; | ||
import { getAutogeneratedAccountDisplayName } from '@app/common/utils/get-account-display-name'; | ||
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'; | ||
import { StacksAccount } from '@app/store/accounts/blockchain/stacks/stacks-account.models'; | ||
|
||
export function useCurrentAccountDisplayName() { | ||
const account = useCurrentStacksAccount(); | ||
const { data: names = [] } = useCurrentAccountNames(); | ||
const index = useCurrentAccountIndex(); | ||
|
||
return useMemo(() => { | ||
if (!account || typeof account?.index !== 'number') return 'Account'; | ||
if (isUndefined(index) && (!account || typeof account?.index !== 'number')) return 'Account'; | ||
if (names[0]) return parseIfValidPunycode(names[0]); | ||
return getAutogeneratedAccountDisplayName(account.index); | ||
}, [account, names]); | ||
return getAutogeneratedAccountDisplayName(index); | ||
}, [account, names, index]); | ||
} | ||
|
||
export function useAccountDisplayName(account: StacksAccount): string { | ||
const { data: names = [] } = useGetAccountNamesByAddressQuery(account.address); | ||
export function useAccountDisplayName({ address, index }: { index: number; address: string }) { | ||
const { data: names = [] } = useGetAccountNamesByAddressQuery(address); | ||
return useMemo(() => { | ||
if (names[0]) return parseIfValidPunycode(names[0]); | ||
return getAutogeneratedAccountDisplayName(account.index); | ||
}, [account, names]); | ||
return getAutogeneratedAccountDisplayName(index); | ||
}, [names, index]); | ||
} |
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,31 @@ | ||
import { P2Ret } from '@scure/btc-signer'; | ||
|
||
import { useConfigBitcoinEnabled } from '@app/query/common/remote-config/remote-config.query'; | ||
import { useCurrentAccountIndex } from '@app/store/accounts/account'; | ||
import { Signer } from '@app/store/accounts/blockchain/bitcoin/bitcoin-signer'; | ||
import { useNativeSegwitSigner } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks'; | ||
|
||
interface BitcoinAccountLoaderBaseProps { | ||
children(account: Signer<P2Ret>): React.ReactNode; | ||
} | ||
interface BtcAccountLoaderCurrentProps extends BitcoinAccountLoaderBaseProps { | ||
current: true; | ||
} | ||
interface BtcAccountLoaderIndexProps extends BitcoinAccountLoaderBaseProps { | ||
index: number; | ||
} | ||
|
||
type BtcAccountLoaderProps = BtcAccountLoaderCurrentProps | BtcAccountLoaderIndexProps; | ||
|
||
export function BitcoinNativeSegwitAccountLoader({ children, ...props }: BtcAccountLoaderProps) { | ||
const isBitcoinEnabled = useConfigBitcoinEnabled(); | ||
|
||
const currentAccountIndex = useCurrentAccountIndex(); | ||
|
||
const properIndex = 'current' in props ? currentAccountIndex : props.index; | ||
|
||
const signer = useNativeSegwitSigner(properIndex); | ||
|
||
if (!signer || !isBitcoinEnabled) return null; | ||
return children(signer(0)); | ||
} |
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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import React from 'react'; | ||
|
||
import { BoxProps, Text, color } from '@stacks/ui'; | ||
import { styled } from 'leather-styles/jsx'; | ||
|
||
interface ExternalLinkProps extends BoxProps { | ||
const StyledA = styled('a'); | ||
|
||
interface ExternalLinkProps extends React.ComponentProps<typeof StyledA> { | ||
href: string; | ||
children: React.ReactNode; | ||
} | ||
export function ExternalLink(props: ExternalLinkProps) { | ||
|
||
export function ExternalLink({ href, children, ...rest }: ExternalLinkProps) { | ||
return ( | ||
<Text as="a" color={color('accent')} target="_blank" {...props}> | ||
{props.children} | ||
</Text> | ||
<styled.a target="_blank" cursor="pointer" href={href} {...rest}> | ||
{children} | ||
</styled.a> | ||
); | ||
} |
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 BtcLedgerIcon() { | ||
return ( | ||
<svg width="25" height="24" viewBox="0 0 25 24" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path | ||
d="M20.2075 9.5429C20.5457 7.31003 18.8248 6.10969 16.4717 5.30895L17.235 2.28424L15.3714 1.8254L14.6283 4.77039C14.1383 4.64978 13.6351 4.53599 13.1351 4.42325L13.8835 1.45884L12.021 1L11.2571 4.02365C10.8516 3.9324 10.4535 3.84222 10.0671 3.7473L10.0692 3.73786L7.49906 3.10386L7.00329 5.07034C7.00329 5.07034 8.38603 5.3834 8.35683 5.40281C9.11164 5.58896 9.24804 6.08242 9.22522 6.47361L8.35576 9.91941C8.40778 9.93252 8.47521 9.9514 8.54952 9.98077C8.48741 9.96556 8.42106 9.94877 8.35259 9.93252L7.13386 14.7596C7.0415 14.9861 6.80742 15.3259 6.27981 15.1969C6.29838 15.2236 4.9252 14.8629 4.9252 14.8629L4 16.9704L6.42524 17.5677C6.87642 17.6794 7.31857 17.7963 7.75383 17.9064L6.98259 20.9658L8.84411 21.4246L9.60793 18.3978C10.1164 18.5341 10.6101 18.66 11.0931 18.7785L10.332 21.7912L12.1956 22.25L12.9669 19.1965C16.1448 19.7906 18.5344 19.5509 19.5403 16.7114C20.3509 14.425 19.5 13.1062 17.8279 12.2461C19.0456 11.9687 19.9628 11.1774 20.2075 9.5429ZM15.9494 15.4418C15.3735 17.7282 11.4769 16.4922 10.2136 16.1822L11.237 12.1292C12.5003 12.4407 16.5514 13.0574 15.9494 15.4418ZM16.5259 9.50986C16.0004 11.5896 12.7572 10.5329 11.7051 10.2739L12.633 6.59791C13.685 6.85696 17.0731 7.34044 16.5259 9.50986Z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
); | ||
} |
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,17 @@ | ||
export function LedgerIcon(props: React.SVGProps<SVGSVGElement>) { | ||
return ( | ||
<svg | ||
width="15" | ||
height="15" | ||
viewBox="0 0 15 15" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
{...props} | ||
> | ||
<path | ||
d="M0 10V14.0612L6 14L6 13H1V10H0ZM14 10L14 13H9V14L15 14.061L15 10H14ZM6 4V10H10L10 9H7V4H6ZM0 0V4H1L1 1H6L6 0H0ZM9 0L9 1H14L14 4H15L15 0H9Z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
); | ||
} |
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,14 @@ | ||
export function StxLedgerIcon() { | ||
return ( | ||
<svg width="25" height="24" viewBox="0 0 25 24" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path | ||
d="M16.2091 14.89L20.2452 21H17.2301L12.492 13.8212L7.75399 21H4.75483L8.79093 14.906H3V12.5928H22V14.89H16.2091Z" | ||
fill="currentColor" | ||
/> | ||
<path | ||
d="M22 8.03023V10.3434V10.3594H3V8.03023H8.67926L4.69102 2H7.70613L12.492 9.27456L17.2939 2H20.309L16.3207 8.03023H22Z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
); | ||
} |
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.