-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add a new wallet option `render` to support customize the content of each option. * feat: Remove particleAuth (not completed, temporarily put on hold) * feat: Add `isDisabled` option to wallet * fix: Fix typos * fix: Update wallet option styles
- Loading branch information
Showing
29 changed files
with
383 additions
and
588 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,5 @@ | ||
--- | ||
"@node-real/walletkit": patch | ||
--- | ||
|
||
Add a new wallet option `render` to support customize the content of each option. |
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,5 @@ | ||
--- | ||
"@node-real/walletkit": patch | ||
--- | ||
|
||
feat: Add `isDisabled` option to wallet. |
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
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,45 @@ | ||
import { Connector } from 'wagmi'; | ||
import { useClickWallet } from './useClickWallet'; | ||
import { useWalletConfig } from './useWalletConfig'; | ||
import { useWalletLogos } from './useWalletLogos'; | ||
import { WalletRenderProps } from '@/wallets'; | ||
import { useMemo } from 'react'; | ||
import { useTheme } from '@/components/ThemeProvider/context'; | ||
|
||
export function useWalletRender(connector: Connector, layout: WalletRenderProps['layout']) { | ||
const onClickWallet = useClickWallet(); | ||
const { colorMode } = useTheme(); | ||
|
||
const wallet = useWalletConfig(connector); | ||
const logos = useWalletLogos(wallet.logos); | ||
|
||
const renderOptions = useMemo(() => { | ||
return { | ||
layout, | ||
colorMode, | ||
wallet: { | ||
id: wallet.id, | ||
name: wallet.name, | ||
logo: layout === 'grid' ? logos.default : logos.transparent, | ||
isDisabled: wallet.isDisabled, | ||
}, | ||
onClick(e: React.MouseEvent<Element, MouseEvent>) { | ||
onClickWallet(connector, e); | ||
}, | ||
}; | ||
}, [ | ||
colorMode, | ||
connector, | ||
layout, | ||
logos.default, | ||
logos.transparent, | ||
onClickWallet, | ||
wallet.id, | ||
wallet.name, | ||
]); | ||
|
||
return { | ||
...renderOptions, | ||
element: wallet.render?.(renderOptions), | ||
}; | ||
} |
32 changes: 18 additions & 14 deletions
32
packages/walletkit/src/pages/Connectors/GridLayout/WalletOption/index.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
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
32 changes: 20 additions & 12 deletions
32
packages/walletkit/src/pages/Connectors/ListLayout/WalletOption/index.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 |
---|---|---|
@@ -1,32 +1,40 @@ | ||
import { Box } from '@/base/components/Box'; | ||
import { Text } from '@/base/components/Text'; | ||
import { Button } from '@/base/components/Button'; | ||
import { useClickWallet } from '@/hooks/useClickWallet'; | ||
import { useWalletConfig } from '@/hooks/useWalletConfig'; | ||
import { useWalletLogos } from '@/hooks/useWalletLogos'; | ||
import { cx } from '@/index'; | ||
import { Connector } from 'wagmi'; | ||
import { clsWalletOption, clsWalletOptionName, clsWalletOptionIcon } from './styles.css'; | ||
import { | ||
clsWalletOption, | ||
clsWalletOptionName, | ||
clsWalletOptionIcon, | ||
clsWalletOptionDisabled, | ||
} from './styles.css'; | ||
import { useWalletRender } from '@/hooks/useWalletRender'; | ||
|
||
export interface WalletOptionProps { | ||
connector: Connector; | ||
} | ||
|
||
export function WalletOption(props: WalletOptionProps) { | ||
const { connector } = props; | ||
const renderOptions = useWalletRender(props.connector, 'list'); | ||
|
||
const onClickWallet = useClickWallet(); | ||
if (renderOptions.element) { | ||
return <>{renderOptions.element}</>; | ||
} | ||
|
||
const wallet = useWalletConfig(connector); | ||
const logos = useWalletLogos(wallet.logos); | ||
const { logo, name, isDisabled } = renderOptions.wallet; | ||
|
||
return ( | ||
<Button | ||
className={cx('wk-wallet-option', clsWalletOption)} | ||
onClick={(e) => onClickWallet(connector, e)} | ||
className={cx( | ||
'wk-wallet-option', | ||
clsWalletOption, | ||
isDisabled ? clsWalletOptionDisabled : undefined, | ||
)} | ||
onClick={isDisabled ? undefined : renderOptions.onClick} | ||
> | ||
<Text className={cx('wk-wallet-option-name', clsWalletOptionName)}>{wallet.name}</Text> | ||
<Box className={cx('wk-wallet-option-logo', clsWalletOptionIcon)}>{logos.transparent}</Box> | ||
<Text className={cx('wk-wallet-option-name', clsWalletOptionName)}>{name}</Text> | ||
<Box className={cx('wk-wallet-option-logo', clsWalletOptionIcon)}>{logo}</Box> | ||
</Button> | ||
); | ||
} |
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.