@xylabs/sdk-react 2.9.32 → 2.9.35

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.
Files changed (87) hide show
  1. package/dist/cjs5/components/EthAccount/EthAccount.stories.d.ts +3 -1
  2. package/dist/cjs5/components/EthAccount/EthAccountProps.d.ts +1 -0
  3. package/dist/cjs5/components/LinkEx/LinkToEx.d.ts +4 -2
  4. package/dist/cjs5/components/LinkEx/index.d.ts +1 -2
  5. package/dist/cjs5/hooks/index.d.ts +2 -0
  6. package/dist/cjs5/hooks/useInterval.d.ts +2 -0
  7. package/dist/cjs5/hooks/useTimeout.d.ts +2 -0
  8. package/dist/cjs5/index.js +42 -4
  9. package/dist/cjs5/index.js.map +1 -1
  10. package/dist/components/BasePage/BasePage.stories.js +2 -1
  11. package/dist/components/BasePage/BasePage.stories.js.map +1 -1
  12. package/dist/components/EthAccount/EthAccount.js +2 -2
  13. package/dist/components/EthAccount/EthAccount.js.map +1 -1
  14. package/dist/components/EthAccount/EthAccount.stories.d.ts +3 -1
  15. package/dist/components/EthAccount/EthAccount.stories.js +18 -1
  16. package/dist/components/EthAccount/EthAccount.stories.js.map +1 -1
  17. package/dist/components/EthAccount/EthAccountProps.d.ts +1 -0
  18. package/dist/components/LinkEx/LinkToEx.d.ts +4 -2
  19. package/dist/components/LinkEx/LinkToEx.js +10 -3
  20. package/dist/components/LinkEx/LinkToEx.js.map +1 -1
  21. package/dist/components/LinkEx/index.d.ts +1 -2
  22. package/dist/components/LinkEx/index.js +1 -2
  23. package/dist/components/LinkEx/index.js.map +1 -1
  24. package/dist/esm2015/components/EthAccount/EthAccount.stories.d.ts +3 -1
  25. package/dist/esm2015/components/EthAccount/EthAccountProps.d.ts +1 -0
  26. package/dist/esm2015/components/LinkEx/LinkToEx.d.ts +4 -2
  27. package/dist/esm2015/components/LinkEx/index.d.ts +1 -2
  28. package/dist/esm2015/hooks/index.d.ts +2 -0
  29. package/dist/esm2015/hooks/useInterval.d.ts +2 -0
  30. package/dist/esm2015/hooks/useTimeout.d.ts +2 -0
  31. package/dist/esm2015/index.js +40 -5
  32. package/dist/esm2015/index.js.map +1 -1
  33. package/dist/esm2017/components/EthAccount/EthAccount.stories.d.ts +3 -1
  34. package/dist/esm2017/components/EthAccount/EthAccountProps.d.ts +1 -0
  35. package/dist/esm2017/components/LinkEx/LinkToEx.d.ts +4 -2
  36. package/dist/esm2017/components/LinkEx/index.d.ts +1 -2
  37. package/dist/esm2017/hooks/index.d.ts +2 -0
  38. package/dist/esm2017/hooks/useInterval.d.ts +2 -0
  39. package/dist/esm2017/hooks/useTimeout.d.ts +2 -0
  40. package/dist/esm2017/index.js +40 -5
  41. package/dist/esm2017/index.js.map +1 -1
  42. package/dist/esm5/components/EthAccount/EthAccount.stories.d.ts +3 -1
  43. package/dist/esm5/components/EthAccount/EthAccountProps.d.ts +1 -0
  44. package/dist/esm5/components/LinkEx/LinkToEx.d.ts +4 -2
  45. package/dist/esm5/components/LinkEx/index.d.ts +1 -2
  46. package/dist/esm5/hooks/index.d.ts +2 -0
  47. package/dist/esm5/hooks/useInterval.d.ts +2 -0
  48. package/dist/esm5/hooks/useTimeout.d.ts +2 -0
  49. package/dist/esm5/index.js +40 -5
  50. package/dist/esm5/index.js.map +1 -1
  51. package/dist/hooks/index.d.ts +2 -0
  52. package/dist/hooks/index.js +2 -0
  53. package/dist/hooks/index.js.map +1 -1
  54. package/dist/hooks/useInterval.d.ts +2 -0
  55. package/dist/hooks/useInterval.js +15 -0
  56. package/dist/hooks/useInterval.js.map +1 -0
  57. package/dist/hooks/useTimeout.d.ts +2 -0
  58. package/dist/hooks/useTimeout.js +15 -0
  59. package/dist/hooks/useTimeout.js.map +1 -0
  60. package/dist/node/components/EthAccount/EthAccount.stories.d.ts +3 -1
  61. package/dist/node/components/EthAccount/EthAccountProps.d.ts +1 -0
  62. package/dist/node/components/LinkEx/LinkToEx.d.ts +4 -2
  63. package/dist/node/components/LinkEx/index.d.ts +1 -2
  64. package/dist/node/hooks/index.d.ts +2 -0
  65. package/dist/node/hooks/useInterval.d.ts +2 -0
  66. package/dist/node/hooks/useTimeout.d.ts +2 -0
  67. package/dist/node/index.js +42 -4
  68. package/dist/node/index.js.map +1 -1
  69. package/dist/node-esm/components/EthAccount/EthAccount.stories.d.ts +3 -1
  70. package/dist/node-esm/components/EthAccount/EthAccountProps.d.ts +1 -0
  71. package/dist/node-esm/components/LinkEx/LinkToEx.d.ts +4 -2
  72. package/dist/node-esm/components/LinkEx/index.d.ts +1 -2
  73. package/dist/node-esm/hooks/index.d.ts +2 -0
  74. package/dist/node-esm/hooks/useInterval.d.ts +2 -0
  75. package/dist/node-esm/hooks/useTimeout.d.ts +2 -0
  76. package/dist/node-esm/index.js +40 -5
  77. package/dist/node-esm/index.js.map +1 -1
  78. package/package.json +11 -11
  79. package/src/components/BasePage/BasePage.stories.tsx +6 -1
  80. package/src/components/EthAccount/EthAccount.stories.tsx +20 -1
  81. package/src/components/EthAccount/EthAccount.tsx +2 -1
  82. package/src/components/EthAccount/EthAccountProps.tsx +1 -0
  83. package/src/components/LinkEx/LinkToEx.tsx +11 -4
  84. package/src/components/LinkEx/index.ts +1 -3
  85. package/src/hooks/index.ts +2 -0
  86. package/src/hooks/useInterval.ts +19 -0
  87. package/src/hooks/useTimeout.ts +19 -0
package/package.json CHANGED
@@ -22,19 +22,19 @@
22
22
  },
23
23
  "description": "Common React library for all XY Labs projects that use React",
24
24
  "devDependencies": {
25
- "@babel/core": "^7.17.4",
26
- "@emotion/react": "^11.7.1",
27
- "@emotion/styled": "^11.6.0",
25
+ "@babel/core": "^7.17.5",
26
+ "@emotion/react": "^11.8.1",
27
+ "@emotion/styled": "^11.8.1",
28
28
  "@ethersproject/abstract-signer": "^5.5.0",
29
29
  "@ethersproject/providers": "^5.5.3",
30
30
  "@mui/icons-material": "^5.4.2",
31
- "@mui/material": "^5.4.2",
31
+ "@mui/material": "^5.4.3",
32
32
  "@mui/styles": "^5.4.2",
33
33
  "@rollup/plugin-image": "^2.1.1",
34
34
  "@rollup/plugin-json": "^4.1.0",
35
- "@rollup/plugin-replace": "^3.1.0",
35
+ "@rollup/plugin-replace": "^4.0.0",
36
36
  "@rollup/plugin-strip": "^2.1.0",
37
- "@rollup/plugin-typescript": "^8.3.0",
37
+ "@rollup/plugin-typescript": "^8.3.1",
38
38
  "@storybook/addon-actions": "^6.4.19",
39
39
  "@storybook/addon-docs": "^6.4.19",
40
40
  "@storybook/addon-essentials": "^6.4.19",
@@ -45,14 +45,14 @@
45
45
  "@types/bn.js": "^5.1.0",
46
46
  "@types/lodash": "^4.14.178",
47
47
  "@types/md5": "^2.3.2",
48
- "@types/node": "^17.0.18",
48
+ "@types/node": "^17.0.21",
49
49
  "@types/numeral": "^2.0.2",
50
50
  "@types/react": "^17.0.39",
51
51
  "@types/react-dom": "^17.0.11",
52
52
  "@xylabs/eslint-config-react": "^2.1.2",
53
53
  "@xylabs/pixel": "^1.3.7",
54
54
  "@xylabs/rollup-config": "^1.1.7",
55
- "@xylabs/ts-scripts": "^1.0.43",
55
+ "@xylabs/ts-scripts": "^1.0.44",
56
56
  "@xylabs/tsconfig": "^1.0.12",
57
57
  "babel-loader": "^8.2.3",
58
58
  "copyfiles": "^2.4.1",
@@ -66,12 +66,12 @@
66
66
  "react-router-dom": "^6.2.1",
67
67
  "rimraf": "^3.0.2",
68
68
  "rollbar": "^2.24.0",
69
- "rollup": "^2.67.2",
69
+ "rollup": "^2.68.0",
70
70
  "rollup-plugin-svg": "^2.0.0",
71
71
  "ts-node": "^10.5.0",
72
72
  "tslib": "^2.3.1",
73
73
  "typescript": "^4.5.5",
74
- "webpack": "^5.69.0"
74
+ "webpack": "^5.69.1"
75
75
  },
76
76
  "esm5": "dist/esm5/index.js",
77
77
  "exports": {
@@ -125,6 +125,6 @@
125
125
  },
126
126
  "sideEffects": false,
127
127
  "types": "dist/index.d.ts",
128
- "version": "2.9.32",
128
+ "version": "2.9.35",
129
129
  "packageManager": "yarn@3.1.1"
130
130
  }
@@ -1,4 +1,5 @@
1
1
  import { ComponentMeta, ComponentStory } from '@storybook/react'
2
+ import { BrowserRouter } from 'react-router-dom'
2
3
 
3
4
  import { BasePage } from './BasePage'
4
5
 
@@ -13,7 +14,11 @@ const StorybookEntry = {
13
14
  title: 'Components/BasePage',
14
15
  } as ComponentMeta<typeof BasePage>
15
16
 
16
- const Template: ComponentStory<typeof BasePage> = (args) => <BasePage {...args}></BasePage>
17
+ const Template: ComponentStory<typeof BasePage> = (args) => (
18
+ <BrowserRouter>
19
+ <BasePage {...args}></BasePage>
20
+ </BrowserRouter>
21
+ )
17
22
 
18
23
  const AppBar = () => <div>AppBar</div>
19
24
  const FilterBar = () => <div>FilterBar</div>
@@ -38,6 +38,25 @@ LongEmpty.args = {
38
38
  toEtherScan: true,
39
39
  }
40
40
 
41
+ const Medium = Template.bind({})
42
+ Medium.args = {
43
+ address: EthAddress.fromString('0x6792b02f88b32c4fe8e31cfa41ae5af44865f930'),
44
+ addressLength: 'short',
45
+ icon: true,
46
+ shortenedLength: 8,
47
+ title: 'Sample EthAccount',
48
+ toEtherScan: true,
49
+ }
50
+
51
+ const MediumEmpty = Template.bind({})
52
+ MediumEmpty.args = {
53
+ addressLength: 'short',
54
+ icon: true,
55
+ shortenedLength: 8,
56
+ title: 'Sample EthAccount',
57
+ toEtherScan: true,
58
+ }
59
+
41
60
  const Short = Template.bind({})
42
61
  Short.args = {
43
62
  address: EthAddress.fromString('0x6792b02f88b32c4fe8e31cfa41ae5af44865f930'),
@@ -72,7 +91,7 @@ AutoEmpty.args = {
72
91
  toEtherScan: true,
73
92
  }
74
93
 
75
- export { Auto, AutoEmpty, Long, LongEmpty, Short, ShortEmpty }
94
+ export { Auto, AutoEmpty, Long, LongEmpty, Medium, MediumEmpty, Short, ShortEmpty }
76
95
 
77
96
  // eslint-disable-next-line import/no-default-export
78
97
  export default StorybookEntry
@@ -14,6 +14,7 @@ const EthAccount: React.FC<EthAccountProps> = ({
14
14
  icon = false,
15
15
  iconSize = 16,
16
16
  iconOnly = false,
17
+ shortenedLength,
17
18
  addressLength = 'auto',
18
19
  fontFamily = '"Source Code Pro",monospace',
19
20
  toEtherScan,
@@ -40,7 +41,7 @@ const EthAccount: React.FC<EthAccountProps> = ({
40
41
  addressLength === 'long'
41
42
  ? addressToDisplay.toString()
42
43
  : addressLength === 'short'
43
- ? addressToDisplay.toShortString()
44
+ ? addressToDisplay.toShortString(shortenedLength)
44
45
  : large
45
46
  ? addressToDisplay.toString()
46
47
  : addressToDisplay.toShortString()
@@ -6,6 +6,7 @@ import { ButtonExProps } from '../ButtonEx'
6
6
  interface EthAccountProps extends ButtonExProps {
7
7
  address?: EthAddress | null
8
8
  addressLength?: 'auto' | 'short' | 'long'
9
+ shortenedLength?: number
9
10
  full?: boolean
10
11
  icon?: boolean
11
12
  iconSize?: number
@@ -3,11 +3,18 @@ import React from 'react'
3
3
  import { Link as RouterLink, To } from 'react-router-dom'
4
4
 
5
5
  interface Props extends LinkProps {
6
- to: To
6
+ to?: To
7
7
  }
8
8
 
9
- const LinkToEx: React.FC<Props> = ({ to, ...props }) => {
10
- return <Link component={RouterLink} to={to} {...props} />
9
+ const LinkEx: React.FC<Props> = ({ to, ...props }) => {
10
+ if (to) {
11
+ return <Link component={RouterLink} to={to} {...props} />
12
+ } else {
13
+ return <Link {...props} />
14
+ }
11
15
  }
12
16
 
13
- export { LinkToEx }
17
+ /** @deprecated use LinkEx instead */
18
+ const LinkToEx = LinkEx
19
+
20
+ export { LinkEx, LinkToEx }
@@ -1,3 +1 @@
1
- import { LinkToEx } from './LinkToEx'
2
-
3
- export { LinkToEx }
1
+ export * from './LinkToEx'
@@ -1,9 +1,11 @@
1
1
  export * from './useBreakpoint'
2
+ export * from './useInterval'
2
3
  export * from './useLocalStorage'
3
4
  export * from './useMediaQuery'
4
5
  export * from './useMounted'
5
6
  export * from './useNavigateToEthAddress'
6
7
  export * from './useSpacing'
8
+ export * from './useTimeout'
7
9
  export * from './useUserEvents'
8
10
  export * from './useWebP'
9
11
  export * from './useWindowSize'
@@ -0,0 +1,19 @@
1
+ import { useEffect, useRef } from 'react'
2
+
3
+ export const useInterval = (callback: () => void, delay: number) => {
4
+ const intervalRef = useRef<number>(-1)
5
+ const savedCallback = useRef(callback)
6
+
7
+ useEffect(() => {
8
+ savedCallback.current = callback
9
+ }, [callback])
10
+
11
+ useEffect(() => {
12
+ const tick = () => savedCallback.current()
13
+ intervalRef.current = window.setInterval(tick, delay)
14
+
15
+ return () => window.clearInterval(intervalRef.current)
16
+ }, [delay])
17
+
18
+ return intervalRef
19
+ }
@@ -0,0 +1,19 @@
1
+ import { useEffect, useRef } from 'react'
2
+
3
+ export const useTimeout = (callback: () => void, delay: number) => {
4
+ const timeoutRef = useRef<number>(-1)
5
+ const savedCallback = useRef(callback)
6
+
7
+ useEffect(() => {
8
+ savedCallback.current = callback
9
+ }, [callback])
10
+
11
+ useEffect(() => {
12
+ const tick = () => savedCallback.current()
13
+ timeoutRef.current = window.setTimeout(tick, delay)
14
+
15
+ return () => window.clearTimeout(timeoutRef.current)
16
+ }, [delay])
17
+
18
+ return timeoutRef
19
+ }