@xyo-network/react-wallet 2.26.37 → 2.26.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/docs.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "fileName": "index.ts",
11
11
  "line": 1,
12
12
  "character": 0,
13
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/eeec410/packages/wallet/src/index.ts#L1"
13
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/blob/0cea94b/packages/wallet/src/index.ts#L1"
14
14
  }
15
15
  ]
16
16
  }
package/package.json CHANGED
@@ -21,8 +21,8 @@
21
21
  "@xylabs/react-shared": "^2.14.10",
22
22
  "@xylabs/sdk-js": "^2.6.2",
23
23
  "@xyo-network/account": "^2.22.15",
24
- "@xyo-network/react-network": "^2.26.37",
25
- "@xyo-network/react-shared": "^2.26.37",
24
+ "@xyo-network/react-network": "^2.26.40",
25
+ "@xyo-network/react-shared": "^2.26.40",
26
26
  "@xyo-network/wallet": "^2.22.15",
27
27
  "react": "^18.2.0",
28
28
  "react-dom": "^18.2.0",
@@ -86,5 +86,5 @@
86
86
  },
87
87
  "sideEffects": false,
88
88
  "types": "dist/esm/index.d.ts",
89
- "version": "2.26.37"
89
+ "version": "2.26.40"
90
90
  }
@@ -0,0 +1,31 @@
1
+ import { ComponentMeta, ComponentStory } from '@storybook/react'
2
+ import { BrowserRouter } from 'react-router-dom'
3
+
4
+ import { WalletAccountDetails } from './WalletAccountDetails'
5
+
6
+ const StorybookEntry = {
7
+ argTypes: {},
8
+ component: WalletAccountDetails,
9
+ parameters: {
10
+ docs: {
11
+ page: null,
12
+ },
13
+ },
14
+ title: 'wallet/WalletAccountDetails',
15
+ } as ComponentMeta<typeof WalletAccountDetails>
16
+
17
+ const Template: ComponentStory<typeof WalletAccountDetails> = (args) => {
18
+ return (
19
+ <BrowserRouter>
20
+ <WalletAccountDetails {...args}></WalletAccountDetails>
21
+ </BrowserRouter>
22
+ )
23
+ }
24
+
25
+ const Default = Template.bind({})
26
+ Default.args = {}
27
+
28
+ export { Default }
29
+
30
+ // eslint-disable-next-line import/no-default-export
31
+ export default StorybookEntry
@@ -0,0 +1,31 @@
1
+ import { EthAccountButton } from '@xylabs/react-crypto'
2
+ import { FlexBoxProps, FlexCol, FlexRow } from '@xylabs/react-flexbox'
3
+ import { NumberStatus } from '@xylabs/react-number-status'
4
+ import { EthAddress } from '@xylabs/sdk-js'
5
+ import { XyoAccount } from '@xyo-network/account'
6
+ import { useNetwork } from '@xyo-network/react-network'
7
+
8
+ import { useAccount } from '../../contexts'
9
+
10
+ export interface WalletAccountDetailsProps extends FlexBoxProps {
11
+ account?: XyoAccount
12
+ exploreUrl?: string
13
+ }
14
+
15
+ export const WalletAccountDetails: React.FC<WalletAccountDetailsProps> = ({ exploreUrl = 'https://explore.xyo.network', account: accountProp, ...props }) => {
16
+ const { account = accountProp } = useAccount()
17
+ const { network } = useNetwork()
18
+ const exploreAddressUrl = `${exploreUrl}/recent?account=${account?.addressValue.hex}&network=${network?.name ?? 'main'}`
19
+
20
+ return (
21
+ <FlexCol {...props}>
22
+ <EthAccountButton address={EthAddress.fromString(account?.addressValue.hex)} />
23
+ <FlexRow gap={1}>
24
+ <NumberStatus rounded title="Tokens" value={0} to={`${exploreAddressUrl}&schema=network.xyo.account.tokens`} target="_blank" />
25
+ <NumberStatus rounded title="NFTs" value={0} to={`${exploreAddressUrl}&schema=network.xyo.account.nfts`} target="_blank" />
26
+ <NumberStatus rounded title="Signatures" value={0} to={`${exploreAddressUrl}&schema=network.xyo.account.signatures`} target="_blank" />
27
+ <NumberStatus rounded title="Signins" value={0} to={`${exploreAddressUrl}&schema=network.xyo.account.signins`} target="_blank" />
28
+ </FlexRow>
29
+ </FlexCol>
30
+ )
31
+ }
@@ -0,0 +1,35 @@
1
+ import { ComponentMeta, ComponentStory } from '@storybook/react'
2
+ import { XyoWalletBase } from '@xyo-network/wallet'
3
+ import { BrowserRouter } from 'react-router-dom'
4
+
5
+ import { WalletProvider } from '../../contexts'
6
+ import { WalletAccountDetails } from './WalletAccountDetails'
7
+
8
+ const StorybookEntry = {
9
+ argTypes: {},
10
+ component: WalletAccountDetails,
11
+ parameters: {
12
+ docs: {
13
+ page: null,
14
+ },
15
+ },
16
+ title: 'wallet/WalletAccountDetailsWithProvider',
17
+ } as ComponentMeta<typeof WalletAccountDetails>
18
+
19
+ const Template: ComponentStory<typeof WalletAccountDetails> = (args) => {
20
+ return (
21
+ <BrowserRouter>
22
+ <WalletProvider defaultWallet={new XyoWalletBase('test me')}>
23
+ <WalletAccountDetails {...args}></WalletAccountDetails>
24
+ </WalletProvider>
25
+ </BrowserRouter>
26
+ )
27
+ }
28
+
29
+ const Default = Template.bind({})
30
+ Default.args = {}
31
+
32
+ export { Default }
33
+
34
+ // eslint-disable-next-line import/no-default-export
35
+ export default StorybookEntry
@@ -0,0 +1 @@
1
+ export * from './WalletAccountDetails'
@@ -0,0 +1,56 @@
1
+ import { MenuItem, SelectProps } from '@mui/material'
2
+ import { SelectEx } from '@xylabs/react-common'
3
+ import { EthAccountBox } from '@xylabs/react-crypto'
4
+ import { FlexRow } from '@xylabs/react-flexbox'
5
+ import { Identicon } from '@xylabs/react-identicon'
6
+ import { EthAddress } from '@xylabs/sdk-js'
7
+
8
+ import { useWallet } from '../../contexts'
9
+
10
+ export interface WalletAccountSelectProps extends SelectProps<number> {
11
+ iconOnly?: boolean
12
+ icons?: boolean
13
+ iconSize?: number
14
+ }
15
+
16
+ const arrayRange = (length: number, start = 0) => {
17
+ return Array.from(Array(length).keys()).map((x) => x + start)
18
+ }
19
+
20
+ export const WalletAccountSelect: React.FC<WalletAccountSelectProps> = ({ size, iconSize = 24, icons, iconOnly, ...props }) => {
21
+ const { wallet, activeAccountIndex = 0, setActiveAccountIndex } = useWallet()
22
+
23
+ return (
24
+ <SelectEx
25
+ renderValue={(selected) => {
26
+ const account = wallet?.getAccount(parseInt(`${selected}`))
27
+ return (
28
+ <FlexRow justifyContent="flex-start" gap={1}>
29
+ {icons ? (
30
+ <FlexRow>
31
+ <Identicon size={iconSize} value={account?.addressValue.hex} />
32
+ </FlexRow>
33
+ ) : null}
34
+ <EthAccountBox alignItems="stretch" iconOnly={iconOnly} address={EthAddress.fromString(account?.addressValue.hex)} />
35
+ </FlexRow>
36
+ )
37
+ }}
38
+ value={activeAccountIndex}
39
+ onChange={(event) => setActiveAccountIndex?.(parseInt(`${event.target.value}`))}
40
+ size={size}
41
+ variant="outlined"
42
+ {...props}
43
+ >
44
+ {wallet
45
+ ? arrayRange(10).map((index) => {
46
+ const account = wallet?.getAccount(index)
47
+ return (
48
+ <MenuItem key={index} value={index}>
49
+ <EthAccountBox iconSize={iconSize} icon={icons} address={EthAddress.fromString(account.addressValue.hex)} />
50
+ </MenuItem>
51
+ )
52
+ })
53
+ : null}
54
+ </SelectEx>
55
+ )
56
+ }
@@ -0,0 +1,21 @@
1
+ import { Paper } from '@mui/material'
2
+ import { FlexBoxProps, FlexCol } from '@xylabs/react-flexbox'
3
+
4
+ import { WalletAccountSelect } from './Select'
5
+
6
+ export interface WalletAccountSelectBarProps extends FlexBoxProps {
7
+ size?: 'small' | 'medium'
8
+ iconOnly?: boolean
9
+ icons?: boolean
10
+ iconSize?: number
11
+ }
12
+
13
+ export const WalletAccountSelectBar: React.FC<WalletAccountSelectBarProps> = ({ iconOnly, icons, iconSize, size = 'small', ...props }) => {
14
+ return (
15
+ <FlexCol alignItems="stretch" {...props}>
16
+ <Paper variant="elevation" elevation={0}>
17
+ <WalletAccountSelect fullWidth iconSize={iconSize} iconOnly={iconOnly} icons={icons} size={size ?? 'small'} />
18
+ </Paper>
19
+ </FlexCol>
20
+ )
21
+ }
@@ -0,0 +1,40 @@
1
+ /* eslint-disable import/no-internal-modules */
2
+ import { ComponentMeta, ComponentStory } from '@storybook/react'
3
+ import { XyoWalletBase } from '@xyo-network/wallet'
4
+
5
+ import { WalletProvider } from '../../contexts'
6
+ import { WalletAccountSelect } from './Select'
7
+
8
+ const StorybookEntry = {
9
+ argTypes: {},
10
+ component: WalletAccountSelect,
11
+ parameters: {
12
+ docs: {
13
+ page: null,
14
+ },
15
+ },
16
+ title: 'wallet/WalletAccountSelect',
17
+ } as ComponentMeta<typeof WalletAccountSelect>
18
+
19
+ const Template: ComponentStory<typeof WalletAccountSelect> = (args) => {
20
+ return <WalletAccountSelect {...args}></WalletAccountSelect>
21
+ }
22
+
23
+ const WithWalletTemplate: ComponentStory<typeof WalletAccountSelect> = (args) => {
24
+ return (
25
+ <WalletProvider defaultWallet={new XyoWalletBase('test me')}>
26
+ <WalletAccountSelect {...args}></WalletAccountSelect>
27
+ </WalletProvider>
28
+ )
29
+ }
30
+
31
+ const Default = Template.bind({})
32
+ Default.args = {}
33
+
34
+ const WithWallet = WithWalletTemplate.bind({})
35
+ WithWallet.args = {}
36
+
37
+ export { Default, WithWallet }
38
+
39
+ // eslint-disable-next-line import/no-default-export
40
+ export default StorybookEntry
@@ -0,0 +1,43 @@
1
+ /* eslint-disable import/no-internal-modules */
2
+ import { ComponentMeta, ComponentStory } from '@storybook/react'
3
+ import { XyoWalletBase } from '@xyo-network/wallet'
4
+
5
+ import { WalletProvider } from '../../contexts'
6
+ import { WalletAccountSelectBar } from './SelectBar'
7
+
8
+ const StorybookEntry = {
9
+ argTypes: {},
10
+ component: WalletAccountSelectBar,
11
+ parameters: {
12
+ docs: {
13
+ page: null,
14
+ },
15
+ },
16
+ title: 'wallet/WalletAccountSelectBar',
17
+ } as ComponentMeta<typeof WalletAccountSelectBar>
18
+
19
+ const Template: ComponentStory<typeof WalletAccountSelectBar> = (args) => {
20
+ return <WalletAccountSelectBar {...args}></WalletAccountSelectBar>
21
+ }
22
+
23
+ const WithWalletTemplate: ComponentStory<typeof WalletAccountSelectBar> = (args) => {
24
+ return (
25
+ <WalletProvider defaultWallet={new XyoWalletBase('test me')}>
26
+ <WalletAccountSelectBar {...args}></WalletAccountSelectBar>
27
+ </WalletProvider>
28
+ )
29
+ }
30
+
31
+ const Default = Template.bind({})
32
+ Default.args = {}
33
+
34
+ const WithWallet = WithWalletTemplate.bind({})
35
+ WithWallet.args = {}
36
+
37
+ const WithWalletIcon = WithWalletTemplate.bind({})
38
+ WithWalletIcon.args = { icons: true }
39
+
40
+ export { Default, WithWallet, WithWalletIcon }
41
+
42
+ // eslint-disable-next-line import/no-default-export
43
+ export default StorybookEntry
@@ -0,0 +1,47 @@
1
+ import { ComponentMeta, ComponentStory } from '@storybook/react'
2
+ import { XyoWalletBase } from '@xyo-network/wallet'
3
+
4
+ import { WalletProvider } from '../../contexts'
5
+ import { WalletAccountSelect } from './Select'
6
+
7
+ const StorybookEntry = {
8
+ argTypes: {},
9
+ component: WalletAccountSelect,
10
+ parameters: {
11
+ docs: {
12
+ page: null,
13
+ },
14
+ },
15
+ title: 'wallet/WalletAccountSelectWithProvider',
16
+ } as ComponentMeta<typeof WalletAccountSelect>
17
+
18
+ const Template: ComponentStory<typeof WalletAccountSelect> = (args) => {
19
+ return (
20
+ <WalletProvider defaultWallet={new XyoWalletBase('test me')}>
21
+ <WalletAccountSelect {...args}></WalletAccountSelect>
22
+ </WalletProvider>
23
+ )
24
+ }
25
+
26
+ const Default = Template.bind({})
27
+ Default.args = {}
28
+
29
+ const DefaultIcons = Template.bind({})
30
+ DefaultIcons.args = { icons: true }
31
+
32
+ const DefaultSmall = Template.bind({})
33
+ DefaultSmall.args = { size: 'small' }
34
+
35
+ const DefaultSmallIcon = Template.bind({})
36
+ DefaultSmallIcon.args = { icons: true, size: 'small' }
37
+
38
+ const IconsOnly = Template.bind({})
39
+ IconsOnly.args = { iconOnly: true, icons: true }
40
+
41
+ const IconsOnlySmall = Template.bind({})
42
+ IconsOnlySmall.args = { iconOnly: true, icons: true, size: 'small' }
43
+
44
+ export { Default, DefaultIcons, DefaultSmall, DefaultSmallIcon, IconsOnly, IconsOnlySmall }
45
+
46
+ // eslint-disable-next-line import/no-default-export
47
+ export default StorybookEntry
@@ -0,0 +1,2 @@
1
+ export * from './Select'
2
+ export * from './SelectBar'
@@ -0,0 +1,2 @@
1
+ export * from './WalletAccountDetails'
2
+ export * from './WalletAccountSelect'
@@ -0,0 +1,5 @@
1
+ import { createContextEx } from '@xyo-network/react-shared'
2
+
3
+ import { AccountContextState } from './State'
4
+
5
+ export const AccountContext = createContextEx<AccountContextState>()
@@ -0,0 +1,15 @@
1
+ import { WithChildren } from '@xylabs/react-shared'
2
+ import { XyoAccount } from '@xyo-network/account'
3
+ import { useState } from 'react'
4
+
5
+ import { AccountContext } from './Context'
6
+
7
+ export interface AccountMemoryProviderProps {
8
+ defaultAccount?: XyoAccount
9
+ }
10
+
11
+ export const AccountMemoryProvider: React.FC<WithChildren<AccountMemoryProviderProps>> = ({ defaultAccount, ...props }) => {
12
+ const [account, setAccount] = useState<XyoAccount | undefined>(defaultAccount)
13
+
14
+ return <AccountContext.Provider value={{ account: account, provided: true, setAccount }} {...props} />
15
+ }
@@ -0,0 +1,8 @@
1
+ import { XyoAccount } from '@xyo-network/account'
2
+ import { ContextExState } from '@xyo-network/react-shared'
3
+ import { Dispatch } from 'react'
4
+
5
+ export interface AccountContextState extends ContextExState {
6
+ account?: XyoAccount
7
+ setAccount?: Dispatch<XyoAccount>
8
+ }
@@ -0,0 +1,4 @@
1
+ export * from './Context'
2
+ export * from './MemoryProvider'
3
+ export * from './State'
4
+ export * from './use'
@@ -0,0 +1,7 @@
1
+ import { useContextEx } from '@xyo-network/react-shared'
2
+
3
+ import { AccountContext } from './Context'
4
+
5
+ export const useAccount = (required = false) => {
6
+ return useContextEx(AccountContext, 'Account', required)
7
+ }
@@ -0,0 +1,5 @@
1
+ import { createContextEx } from '@xyo-network/react-shared'
2
+
3
+ import { WalletContextState } from './State'
4
+
5
+ export const WalletContext = createContextEx<WalletContextState>()
@@ -0,0 +1,38 @@
1
+ import { WithChildren } from '@xylabs/react-shared'
2
+ import { XyoWalletBase } from '@xyo-network/wallet'
3
+ import { useState } from 'react'
4
+
5
+ import { AccountContext } from '../Account'
6
+ import { WalletContext } from './Context'
7
+ import { useWallet } from './use'
8
+
9
+ export interface WalletProviderProps {
10
+ defaultWallet?: XyoWalletBase
11
+ defaultActiveAccountIndex?: number
12
+ }
13
+
14
+ const AccountWalletProvider: React.FC<WithChildren> = (props) => {
15
+ const { wallet, activeAccountIndex = 0 } = useWallet()
16
+
17
+ return <AccountContext.Provider value={{ account: wallet?.getAccount(activeAccountIndex), provided: true }} {...props} />
18
+ }
19
+
20
+ export const WalletProvider: React.FC<WithChildren<WalletProviderProps>> = ({ defaultWallet, defaultActiveAccountIndex = 0, children, ...props }) => {
21
+ const [wallet, setWallet] = useState<XyoWalletBase | undefined>(defaultWallet)
22
+ const [activeAccountIndex, setActiveAccountIndex] = useState(defaultActiveAccountIndex)
23
+
24
+ return (
25
+ <WalletContext.Provider
26
+ value={{
27
+ activeAccountIndex,
28
+ provided: true,
29
+ setActiveAccountIndex,
30
+ setWallet,
31
+ wallet,
32
+ }}
33
+ {...props}
34
+ >
35
+ <AccountWalletProvider>{children}</AccountWalletProvider>
36
+ </WalletContext.Provider>
37
+ )
38
+ }
@@ -0,0 +1,10 @@
1
+ import { ContextExState } from '@xyo-network/react-shared'
2
+ import { XyoWalletBase } from '@xyo-network/wallet'
3
+ import { Dispatch } from 'react'
4
+
5
+ export interface WalletContextState extends ContextExState {
6
+ wallet?: XyoWalletBase
7
+ setWallet?: Dispatch<XyoWalletBase>
8
+ activeAccountIndex?: number
9
+ setActiveAccountIndex?: Dispatch<number>
10
+ }
@@ -0,0 +1,4 @@
1
+ export * from './Context'
2
+ export * from './Provider'
3
+ export * from './State'
4
+ export * from './use'
@@ -0,0 +1,7 @@
1
+ import { useContextEx } from '@xyo-network/react-shared'
2
+
3
+ import { WalletContext } from './Context'
4
+
5
+ export const useWallet = (required = false) => {
6
+ return useContextEx(WalletContext, 'Wallet', required)
7
+ }
@@ -0,0 +1,2 @@
1
+ export * from './Account'
2
+ export * from './Wallet'
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './components'
2
+ export * from './contexts'