From 6db21cc09bb4f693d14bab5b7f50ba28af948ad6 Mon Sep 17 00:00:00 2001 From: gmolki Date: Tue, 13 Aug 2024 15:19:18 +0200 Subject: [PATCH] feat: Show vouchers in Account Picker --- .../AccountPicker/AccountInformation/cmp.tsx | 67 +++++++++++++------ .../AccountInformation/index.tsx | 2 +- .../AccountInformation/types.tsx | 9 +++ .../modules/AccountPicker/cmp.stories.tsx | 39 +++++++++++ src/components/modules/AccountPicker/cmp.tsx | 3 + .../modules/AccountPicker/types.tsx | 3 +- 6 files changed, 100 insertions(+), 23 deletions(-) diff --git a/src/components/modules/AccountPicker/AccountInformation/cmp.tsx b/src/components/modules/AccountPicker/AccountInformation/cmp.tsx index c8f563d..c631d93 100644 --- a/src/components/modules/AccountPicker/AccountInformation/cmp.tsx +++ b/src/components/modules/AccountPicker/AccountInformation/cmp.tsx @@ -9,6 +9,7 @@ import Price from '../../../common/Price' import { formatCurrency } from '../../../../utils' export const AccountInformation = ({ + vouchers, balance, rewards, accountAddress, @@ -62,27 +63,51 @@ export const AccountInformation = ({ )} -
- {accountAddressHref ? ( - <> - - - - ) : ( - displayAddress - )} -
+ {(accountAddressHref || vouchers) && ( + <> + +
+ {vouchers && + vouchers.map((voucher) => ( +
+
+ {voucher.imageAlt} +
+ {voucher.name} +
+
+
+ x{voucher.amount} +
+
+ ))} +
+ {accountAddressHref ? ( + <> + + + ) : ( + displayAddress + )} +
+
+ + )} ) } diff --git a/src/components/modules/AccountPicker/AccountInformation/index.tsx b/src/components/modules/AccountPicker/AccountInformation/index.tsx index ebce272..3cccc4b 100644 --- a/src/components/modules/AccountPicker/AccountInformation/index.tsx +++ b/src/components/modules/AccountPicker/AccountInformation/index.tsx @@ -1,2 +1,2 @@ export { default, default as AccountInformation } from './cmp' -export type { AccountInformationProps } from './types' +export type { Voucher, AccountInformationProps } from './types' diff --git a/src/components/modules/AccountPicker/AccountInformation/types.tsx b/src/components/modules/AccountPicker/AccountInformation/types.tsx index db432ea..19d2615 100644 --- a/src/components/modules/AccountPicker/AccountInformation/types.tsx +++ b/src/components/modules/AccountPicker/AccountInformation/types.tsx @@ -1,3 +1,11 @@ +export type Voucher = { + name: string + image: string + imageAlt: string + // externalUrl: string + amount: number +} + export type AccountInformationProps = { accountAddress?: string accountAddressHref?: string @@ -6,4 +14,5 @@ export type AccountInformationProps = { amount: number days?: number } + vouchers?: Voucher[] } diff --git a/src/components/modules/AccountPicker/cmp.stories.tsx b/src/components/modules/AccountPicker/cmp.stories.tsx index 8572390..63fdf63 100644 --- a/src/components/modules/AccountPicker/cmp.stories.tsx +++ b/src/components/modules/AccountPicker/cmp.stories.tsx @@ -5,6 +5,7 @@ import AccountPicker from './cmp' import { AccountPickerProps, Blockchain } from './types' import { Network } from './NetworkSelector' import { Wallet } from './WalletSelector' +import { Voucher } from './AccountInformation' // More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export export default { @@ -106,6 +107,21 @@ const blockchains: Record = { }, } +const vouchers: Voucher[] = [ + { + name: 'Web3 Voucher', + image: 'https://claim.twentysix.cloud/sbt/cover/web3-hosting.jpg', + imageAlt: 'Web3 Hosting', + amount: 7, + }, + { + name: 'Confidentials Voucher', + image: 'https://claim.twentysix.cloud/sbt/cover/confidential-vm.jpg', + imageAlt: 'Confidential VM', + amount: 3, + }, +] + const handleConnect = async (wallet: Wallet, network: Network) => { alert(`Connect to ${network.name} via ${wallet.name}`) } @@ -181,6 +197,17 @@ LoggedIn.parameters = { ...defaultParams, } +export const LoggedInWithVouchers = Template.bind({}) +LoggedInWithVouchers.args = { + ...defaultArgs, + accountAddress: '0x50622138b35883F2e39Bf0C39eB9fa22214433Df', + accountBalance: Math.random() * 10 ** 8, + accountVouchers: vouchers, +} +LoggedInWithVouchers.parameters = { + ...defaultParams, +} + export const LoggedInOneNetwork = Template.bind({}) LoggedInOneNetwork.args = { ...defaultArgs, @@ -222,6 +249,18 @@ LoggedInMobile.parameters = { ...defaultParams, } +export const LoggedInMobileWithVouchers = Template.bind({}) +LoggedInMobileWithVouchers.args = { + ...defaultArgs, + accountAddress: '0x50622138b35883F2e39Bf0C39eB9fa22214433Df', + accountBalance: Math.random() * 10 ** 8, + accountVouchers: vouchers, + isMobile: true, +} +LoggedInMobileWithVouchers.parameters = { + ...defaultParams, +} + export const LoggedInMobileOneNetwork = Template.bind({}) LoggedInMobileOneNetwork.args = { ...defaultArgs, diff --git a/src/components/modules/AccountPicker/cmp.tsx b/src/components/modules/AccountPicker/cmp.tsx index 4f5e6f8..98bee0e 100644 --- a/src/components/modules/AccountPicker/cmp.tsx +++ b/src/components/modules/AccountPicker/cmp.tsx @@ -13,6 +13,7 @@ import { Portal } from '../../layout/Portal' export const AccountPicker = ({ isMobile = false, + accountVouchers, ...rest }: AccountPickerProps) => { const theme = useTheme() @@ -127,6 +128,7 @@ export const AccountPicker = ({ accountAddress={accountAddress} accountAddressHref={accountAddressHref} balance={accountBalance} + vouchers={accountVouchers} /> @@ -182,6 +184,7 @@ export const AccountPicker = ({ accountAddress={accountAddress} accountAddressHref={accountAddressHref} balance={accountBalance} + vouchers={accountVouchers} /> diff --git a/src/components/modules/AccountPicker/types.tsx b/src/components/modules/AccountPicker/types.tsx index ca8ae0c..379be93 100644 --- a/src/components/modules/AccountPicker/types.tsx +++ b/src/components/modules/AccountPicker/types.tsx @@ -2,7 +2,7 @@ import { RefObject } from 'react' import { Network } from './NetworkSelector' import { Wallet } from './WalletSelector' import { NetworkSelectorProps } from './NetworkSelector/types' -import { AccountInformationProps } from './AccountInformation' +import { AccountInformationProps, Voucher } from './AccountInformation' export type Blockchain = { id: string @@ -18,6 +18,7 @@ export type AccountPickerProps = { isMobile?: boolean accountAddress?: string accountBalance?: number + accountVouchers?: Voucher[] ensName?: string rewards?: AccountInformationProps['rewards'] blockchains: Record