@xyo-network/react-chain-transfer-plugin 1.12.7

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 (48) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +46 -0
  3. package/dist/browser/index.d.ts +2 -0
  4. package/dist/browser/index.d.ts.map +1 -0
  5. package/dist/browser/index.mjs +252 -0
  6. package/dist/browser/index.mjs.map +1 -0
  7. package/dist/browser/transfer/Plugin.d.ts +4 -0
  8. package/dist/browser/transfer/Plugin.d.ts.map +1 -0
  9. package/dist/browser/transfer/box/Details.d.ts +11 -0
  10. package/dist/browser/transfer/box/Details.d.ts.map +1 -0
  11. package/dist/browser/transfer/box/Details.stories.d.ts +8 -0
  12. package/dist/browser/transfer/box/Details.stories.d.ts.map +1 -0
  13. package/dist/browser/transfer/box/index.d.ts +2 -0
  14. package/dist/browser/transfer/box/index.d.ts.map +1 -0
  15. package/dist/browser/transfer/card/ListItem.d.ts +11 -0
  16. package/dist/browser/transfer/card/ListItem.d.ts.map +1 -0
  17. package/dist/browser/transfer/card/TransferRenderCard.d.ts +11 -0
  18. package/dist/browser/transfer/card/TransferRenderCard.d.ts.map +1 -0
  19. package/dist/browser/transfer/card/TransferRenderCard.stories.d.ts +8 -0
  20. package/dist/browser/transfer/card/TransferRenderCard.stories.d.ts.map +1 -0
  21. package/dist/browser/transfer/card/TransferRenderCardHelper.d.ts +22 -0
  22. package/dist/browser/transfer/card/TransferRenderCardHelper.d.ts.map +1 -0
  23. package/dist/browser/transfer/card/TransferRenderTotalTypography.d.ts +8 -0
  24. package/dist/browser/transfer/card/TransferRenderTotalTypography.d.ts.map +1 -0
  25. package/dist/browser/transfer/card/index.d.ts +2 -0
  26. package/dist/browser/transfer/card/index.d.ts.map +1 -0
  27. package/dist/browser/transfer/index.d.ts +4 -0
  28. package/dist/browser/transfer/index.d.ts.map +1 -0
  29. package/dist/browser/transfer/lib/TransferRenderOptions.d.ts +5 -0
  30. package/dist/browser/transfer/lib/TransferRenderOptions.d.ts.map +1 -0
  31. package/dist/browser/transfer/lib/index.d.ts +2 -0
  32. package/dist/browser/transfer/lib/index.d.ts.map +1 -0
  33. package/package.json +83 -0
  34. package/src/gloabl.d.ts +1 -0
  35. package/src/index.ts +1 -0
  36. package/src/transfer/Plugin.ts +17 -0
  37. package/src/transfer/box/Details.stories.tsx +52 -0
  38. package/src/transfer/box/Details.tsx +28 -0
  39. package/src/transfer/box/index.ts +1 -0
  40. package/src/transfer/card/ListItem.tsx +57 -0
  41. package/src/transfer/card/TransferRenderCard.stories.tsx +52 -0
  42. package/src/transfer/card/TransferRenderCard.tsx +71 -0
  43. package/src/transfer/card/TransferRenderCardHelper.tsx +97 -0
  44. package/src/transfer/card/TransferRenderTotalTypography.tsx +38 -0
  45. package/src/transfer/card/index.ts +1 -0
  46. package/src/transfer/index.ts +3 -0
  47. package/src/transfer/lib/TransferRenderOptions.ts +5 -0
  48. package/src/transfer/lib/index.ts +1 -0
package/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # @xyo-network/react-chain-payload-render
2
+
3
+ [![logo][]](https://xyo.network)
4
+
5
+ [![npm-badge][]][npm-link]
6
+ [![npm-downloads-badge][]][npm-link]
7
+ [![jsdelivr-badge][]][jsdelivr-link]
8
+ [![npm-license-badge][]](LICENSE)
9
+ [![socket-badge][]][socket-link]
10
+
11
+ XYO Layer One API
12
+
13
+ ## Reference
14
+
15
+ **@xyo-network/react-chain-payload-render**
16
+
17
+ ***
18
+
19
+ ## Maintainers
20
+
21
+ - [Arie Trouw](https://github.com/arietrouw) ([arietrouw.com](https://arietrouw.com))
22
+ - [Matt Jones](https://github.com/jonesmac)
23
+ - [Joel Carter](https://github.com/JoelBCarter)
24
+ - [Jordan Trouw](https://github.com/jordantrouw)
25
+
26
+ ## License
27
+
28
+ > See the [LICENSE](LICENSE) file for license details
29
+
30
+ ## Credits
31
+
32
+ [Made with 🔥 and ❄️ by XYO](https://xyo.network)
33
+
34
+ [logo]: https://cdn.xy.company/img/brand/XYO_full_colored.png
35
+
36
+ [npm-badge]: https://img.shields.io/npm/v/@xyo-network/react-chain-provider.svg
37
+ [npm-link]: https://www.npmjs.com/package/@xyo-network/react-chain-provider
38
+
39
+ [npm-downloads-badge]: https://img.shields.io/npm/dw/@xyo-network/react-chain-provider
40
+ [npm-license-badge]: https://img.shields.io/npm/l/@xyo-network/react-chain-provider
41
+
42
+ [jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/@xyo-network/react-chain-provider/badge
43
+ [jsdelivr-link]: https://www.jsdelivr.com/package/npm/@xyo-network/react-chain-provider
44
+
45
+ [socket-badge]: https://socket.dev/api/badge/npm/package/@xyo-network/react-chain-provider
46
+ [socket-link]: https://socket.dev/npm/package/@xyo-network/react-chain-provider
@@ -0,0 +1,2 @@
1
+ export * from './transfer/index.ts';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"}
@@ -0,0 +1,252 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/transfer/box/Details.tsx
5
+ import { FlexCol } from "@xylabs/react-flexbox";
6
+ import React5 from "react";
7
+
8
+ // src/transfer/card/TransferRenderCard.tsx
9
+ import { Card, CardContent, CardHeader, List, useMediaQuery, useTheme as useTheme3 } from "@mui/material";
10
+ import { asAddress as asAddress2, asHex } from "@xylabs/hex";
11
+ import { BlockiesAvatar as BlockiesAvatar2 } from "@xyo-network/react-chain-blockies";
12
+ import { useEvent } from "@xyo-network/react-event";
13
+ import { asTransfer } from "@xyo-network/xl1-protocol";
14
+ import React4, { useMemo } from "react";
15
+
16
+ // src/transfer/card/ListItem.tsx
17
+ import { ListItem, ListItemAvatar, ListItemText, Stack, Typography, useTheme } from "@mui/material";
18
+ import { asAddress, hexToBigInt } from "@xylabs/hex";
19
+ import { isDefined } from "@xylabs/typeof";
20
+ import { BlockiesAvatar } from "@xyo-network/react-chain-blockies";
21
+ import { NetworkIcon } from "@xyo-network/react-chain-network";
22
+ import { MainNetworkIconString } from "@xyo-network/xl1-network-model";
23
+ import React from "react";
24
+ var TransferRenderListItem = /* @__PURE__ */ __name(({ address, amount, sx, transferCardHelper, ...props }) => {
25
+ const theme = useTheme();
26
+ return /* @__PURE__ */ React.createElement(ListItem, {
27
+ sx: {
28
+ px: 0,
29
+ ...sx
30
+ },
31
+ ...props
32
+ }, /* @__PURE__ */ React.createElement(ListItemAvatar, {
33
+ sx: {
34
+ minWidth: 30,
35
+ mr: theme.spacing(2)
36
+ }
37
+ }, /* @__PURE__ */ React.createElement(BlockiesAvatar, {
38
+ title: address,
39
+ sx: {
40
+ width: 30,
41
+ height: 30
42
+ },
43
+ blockiesOptions: {
44
+ seed: address
45
+ }
46
+ })), /* @__PURE__ */ React.createElement(ListItemText, {
47
+ sx: {
48
+ borderBottom: `1px solid ${theme.vars.palette.divider}`
49
+ }
50
+ }, /* @__PURE__ */ React.createElement(Stack, {
51
+ direction: "row",
52
+ gap: 2,
53
+ justifyContent: "space-between",
54
+ width: "100%"
55
+ }, /* @__PURE__ */ React.createElement(Typography, {
56
+ component: "span",
57
+ fontFamily: "monospace",
58
+ variant: "caption"
59
+ }, transferCardHelper.addressComponent(asAddress(address), "To")), /* @__PURE__ */ React.createElement(Typography, {
60
+ component: "span",
61
+ fontFamily: "monospace",
62
+ variant: "caption",
63
+ title: isDefined(amount) ? hexToBigInt(amount).toString() : "",
64
+ sx: {
65
+ display: "inline-flex",
66
+ alignItems: "center",
67
+ gap: theme.spacing(0.25)
68
+ }
69
+ }, transferCardHelper.formatAmountToXl1(amount), /* @__PURE__ */ React.createElement(NetworkIcon, {
70
+ icon: MainNetworkIconString,
71
+ style: {
72
+ width: 16,
73
+ height: 16,
74
+ display: "inline-flex",
75
+ alignItems: "end"
76
+ }
77
+ }), "(XL1)"))));
78
+ }, "TransferRenderListItem");
79
+
80
+ // src/transfer/card/TransferRenderCardHelper.tsx
81
+ import { Link } from "@mui/material";
82
+ import { ellipsize } from "@xylabs/eth-address";
83
+ import { hexToBigInt as hexToBigInt2, isHex } from "@xylabs/hex";
84
+ import { isDefined as isDefined2, isUndefined } from "@xylabs/typeof";
85
+ import { XL1Places } from "@xyo-network/xl1-protocol";
86
+ import { XL1Amount } from "@xyo-network/xl1-wrappers";
87
+ import React2 from "react";
88
+ var TransferCardHelper = class {
89
+ static {
90
+ __name(this, "TransferCardHelper");
91
+ }
92
+ _dispatch;
93
+ _isMedium;
94
+ _options;
95
+ _payload;
96
+ constructor(isMedium, payload, dispatch, options) {
97
+ this._isMedium = isMedium;
98
+ this._options = options;
99
+ this._payload = payload;
100
+ this._dispatch = dispatch;
101
+ }
102
+ get dispatch() {
103
+ return this._dispatch;
104
+ }
105
+ get isMedium() {
106
+ return this._isMedium;
107
+ }
108
+ get linkedAddresses() {
109
+ return this.options?.links?.has("address");
110
+ }
111
+ get options() {
112
+ return this._options;
113
+ }
114
+ get payload() {
115
+ return this._payload;
116
+ }
117
+ addressComponent(address, prefix) {
118
+ const resolvedPrefix = isDefined2(prefix) ? `${prefix}: ` : "";
119
+ const text = `${this.formatAddress(address) ?? "Unknown"}`;
120
+ if (this.options?.links?.has("address")) {
121
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, resolvedPrefix, " ", /* @__PURE__ */ React2.createElement(Link, {
122
+ onClick: /* @__PURE__ */ __name(() => {
123
+ this.dispatch?.("address", "click", this.payload?.from);
124
+ }, "onClick"),
125
+ sx: {
126
+ cursor: "pointer"
127
+ }
128
+ }, text));
129
+ }
130
+ return `${resolvedPrefix}${text}`;
131
+ }
132
+ formatAddress(address) {
133
+ return address ? this.isMedium ? address : ellipsize(address, 5) : "";
134
+ }
135
+ formatAmountToXl1(amount) {
136
+ if (isUndefined(amount)) return "";
137
+ const amountBigInt = isHex(amount) ? hexToBigInt2(amount) : amount;
138
+ const xl1Amount = XL1Amount.fromAtto(amountBigInt);
139
+ return amountBigInt < 1000000000000n && amountBigInt > 0n ? "<0.00001" : xl1Amount.toString(Number(XL1Places.xl1), {
140
+ locale: navigator.language
141
+ });
142
+ }
143
+ totalTransferred() {
144
+ if (isUndefined(this.payload?.transfers)) return "0";
145
+ let total = 0n;
146
+ for (const [, amount] of Object.entries(this.payload.transfers)) {
147
+ if (isDefined2(amount)) {
148
+ total += hexToBigInt2(amount);
149
+ }
150
+ }
151
+ return this.formatAmountToXl1(total);
152
+ }
153
+ };
154
+
155
+ // src/transfer/card/TransferRenderTotalTypography.tsx
156
+ import { Typography as Typography2, useTheme as useTheme2 } from "@mui/material";
157
+ import { NetworkIcon as NetworkIcon2 } from "@xyo-network/react-chain-network";
158
+ import { MainNetworkIconString as MainNetworkIconString2 } from "@xyo-network/xl1-network-model";
159
+ import React3 from "react";
160
+ var TransferRenderTotalTypography = /* @__PURE__ */ __name(({ transferRenderHelper, sx, ...props }) => {
161
+ const theme = useTheme2();
162
+ return /* @__PURE__ */ React3.createElement(Typography2, {
163
+ sx: {
164
+ display: "inline-flex",
165
+ gap: theme.spacing(0.25),
166
+ fontFamily: "monospace",
167
+ ...sx
168
+ },
169
+ variant: "caption",
170
+ ...props
171
+ }, "Total:", " ", /* @__PURE__ */ React3.createElement("strong", null, transferRenderHelper?.totalTransferred()), /* @__PURE__ */ React3.createElement(NetworkIcon2, {
172
+ icon: MainNetworkIconString2,
173
+ style: {
174
+ width: 16,
175
+ height: 16,
176
+ display: "inline-flex",
177
+ alignItems: "end"
178
+ }
179
+ }), "(XL1)");
180
+ }, "TransferRenderTotalTypography");
181
+
182
+ // src/transfer/card/TransferRenderCard.tsx
183
+ var TransferRenderCard = /* @__PURE__ */ __name(({ options, payload, ...props }) => {
184
+ const theme = useTheme3();
185
+ const isMedium = useMediaQuery((theme2) => theme2.breakpoints.up("sm"));
186
+ const [ref, dispatch] = useEvent();
187
+ const transfer = asTransfer(payload);
188
+ const { from, transfers } = transfer ?? {};
189
+ const transferCardHelper = useMemo(() => new TransferCardHelper(isMedium, asTransfer(payload), dispatch, options), [
190
+ isMedium,
191
+ payload,
192
+ dispatch,
193
+ options
194
+ ]);
195
+ return /* @__PURE__ */ React4.createElement(Card, {
196
+ ref,
197
+ ...props
198
+ }, /* @__PURE__ */ React4.createElement(CardHeader, {
199
+ title: transferCardHelper.addressComponent(from, "From"),
200
+ slotProps: {
201
+ title: {
202
+ title: from,
203
+ variant: "body1",
204
+ fontFamily: "monospace"
205
+ }
206
+ },
207
+ avatar: /* @__PURE__ */ React4.createElement(BlockiesAvatar2, {
208
+ sx: {
209
+ width: 30,
210
+ height: 30
211
+ },
212
+ title: from,
213
+ blockiesOptions: {
214
+ seed: from
215
+ }
216
+ })
217
+ }), /* @__PURE__ */ React4.createElement(CardContent, {
218
+ sx: {
219
+ "&:last-child": {
220
+ pb: theme.spacing(0)
221
+ }
222
+ }
223
+ }, /* @__PURE__ */ React4.createElement(List, null, Object.entries(transfers ?? {}).map(([address, amount], index) => /* @__PURE__ */ React4.createElement(TransferRenderListItem, {
224
+ // eslint-disable-next-line @eslint-react/no-array-index-key
225
+ key: index,
226
+ address: asAddress2(address),
227
+ amount: asHex(amount),
228
+ transferCardHelper
229
+ }))), /* @__PURE__ */ React4.createElement(TransferRenderTotalTypography, {
230
+ transferRenderHelper: transferCardHelper,
231
+ sx: {
232
+ // pt matches bottom padding of the ListItem
233
+ width: "100%",
234
+ justifyContent: "end",
235
+ pt: 0.6666666667,
236
+ pb: theme.spacing(2)
237
+ }
238
+ })));
239
+ }, "TransferRenderCard");
240
+
241
+ // src/transfer/box/Details.tsx
242
+ var TransferRenderBoxDetails = /* @__PURE__ */ __name(({ options, payload, ...props }) => {
243
+ return /* @__PURE__ */ React5.createElement(FlexCol, props, /* @__PURE__ */ React5.createElement(TransferRenderCard, {
244
+ options,
245
+ payload
246
+ }));
247
+ }, "TransferRenderBoxDetails");
248
+ export {
249
+ TransferRenderBoxDetails,
250
+ TransferRenderCard
251
+ };
252
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/transfer/box/Details.tsx","../../src/transfer/card/TransferRenderCard.tsx","../../src/transfer/card/ListItem.tsx","../../src/transfer/card/TransferRenderCardHelper.tsx","../../src/transfer/card/TransferRenderTotalTypography.tsx"],"sourcesContent":["import type { FlexBoxProps } from '@xylabs/react-flexbox'\nimport { FlexCol } from '@xylabs/react-flexbox'\nimport type { Payload } from '@xyo-network/payload-model'\nimport type { PayloadDetailsRenderProps } from '@xyo-network/react-payload-plugin'\nimport React from 'react'\n\nimport { TransferRenderCard } from '../card/index.ts'\nimport type { TransferRenderOptions } from '../lib/index.ts'\n\nexport interface TransferRenderBoxDetailsProps extends PayloadDetailsRenderProps, FlexBoxProps {\n options?: TransferRenderOptions\n payload?: Payload\n}\n\nexport const TransferRenderBoxDetails: React.FC<TransferRenderBoxDetailsProps> = ({\n options,\n payload,\n ...props\n}) => {\n return (\n <FlexCol {...props}>\n <TransferRenderCard\n options={options}\n payload={payload}\n />\n </FlexCol>\n )\n}\n","import type { CardProps } from '@mui/material'\nimport {\n Card, CardContent, CardHeader, List, useMediaQuery, useTheme,\n} from '@mui/material'\nimport { asAddress, asHex } from '@xylabs/hex'\nimport type { Payload } from '@xyo-network/payload-model'\nimport { BlockiesAvatar } from '@xyo-network/react-chain-blockies'\nimport { useEvent } from '@xyo-network/react-event'\nimport type { PayloadDetailsRenderProps } from '@xyo-network/react-payload-plugin'\nimport { asTransfer } from '@xyo-network/xl1-protocol'\nimport React, { useMemo } from 'react'\n\nimport type { TransferRenderOptions } from '../lib/index.ts'\nimport { TransferRenderListItem } from './ListItem.tsx'\nimport { TransferCardHelper } from './TransferRenderCardHelper.tsx'\nimport { TransferRenderTotalTypography } from './TransferRenderTotalTypography.tsx'\n\nexport interface TransferRenderCardProps extends PayloadDetailsRenderProps, CardProps {\n options?: TransferRenderOptions\n payload?: Payload\n}\n\nexport const TransferRenderCard: React.FC<TransferRenderCardProps> = ({\n options, payload, ...props\n}) => {\n const theme = useTheme()\n const isMedium = useMediaQuery(theme => theme.breakpoints.up('sm'))\n const [ref, dispatch] = useEvent<HTMLDivElement>()\n const transfer = asTransfer(payload)\n const { from, transfers } = transfer ?? {}\n\n const transferCardHelper = useMemo(\n () =>\n new TransferCardHelper(isMedium, asTransfer(payload), dispatch, options),\n [isMedium, payload, dispatch, options],\n )\n\n return (\n <Card ref={ref} {...props}>\n <CardHeader\n title={transferCardHelper.addressComponent(from, 'From')}\n slotProps={{\n title: {\n title: from, variant: 'body1', fontFamily: 'monospace',\n },\n }}\n avatar={<BlockiesAvatar sx={{ width: 30, height: 30 }} title={from} blockiesOptions={{ seed: from }} />}\n />\n <CardContent sx={{ '&:last-child': { pb: theme.spacing(0) } }}>\n <List>\n {Object.entries(transfers ?? {}).map(([address, amount], index) => (\n <TransferRenderListItem\n // eslint-disable-next-line @eslint-react/no-array-index-key\n key={index}\n address={asAddress(address)}\n amount={asHex(amount)}\n transferCardHelper={transferCardHelper}\n />\n ))}\n </List>\n <TransferRenderTotalTypography\n transferRenderHelper={transferCardHelper}\n sx={{\n // pt matches bottom padding of the ListItem\n width: '100%', justifyContent: 'end', pt: 0.666_666_666_7, pb: theme.spacing(2),\n }}\n />\n </CardContent>\n </Card>\n )\n}\n","import {\n ListItem, ListItemAvatar, type ListItemProps, ListItemText, Stack, Typography,\n useTheme,\n} from '@mui/material'\nimport type { Address, Hex } from '@xylabs/hex'\nimport { asAddress, hexToBigInt } from '@xylabs/hex'\nimport { isDefined } from '@xylabs/typeof'\nimport { BlockiesAvatar } from '@xyo-network/react-chain-blockies'\nimport { NetworkIcon } from '@xyo-network/react-chain-network'\nimport { MainNetworkIconString } from '@xyo-network/xl1-network-model'\nimport React from 'react'\n\nimport type { TransferCardHelper } from './TransferRenderCardHelper.tsx'\n\nexport interface TransferRenderListItem extends ListItemProps {\n address?: Address\n amount?: Hex\n transferCardHelper: TransferCardHelper\n}\n\nexport const TransferRenderListItem: React.FC<TransferRenderListItem> = ({\n address, amount, sx, transferCardHelper, ...props\n}) => {\n const theme = useTheme()\n return (\n <ListItem sx={{ px: 0, ...sx }} {...props}>\n <ListItemAvatar sx={{ minWidth: 30, mr: theme.spacing(2) }}>\n <BlockiesAvatar title={address} sx={{ width: 30, height: 30 }} blockiesOptions={{ seed: address }} />\n </ListItemAvatar>\n <ListItemText sx={{ borderBottom: `1px solid ${theme.vars.palette.divider}` }}>\n <Stack direction=\"row\" gap={2} justifyContent=\"space-between\" width=\"100%\">\n <Typography component=\"span\" fontFamily=\"monospace\" variant=\"caption\">\n {transferCardHelper.addressComponent(asAddress(address), 'To')}\n </Typography>\n <Typography\n component=\"span\"\n fontFamily=\"monospace\"\n variant=\"caption\"\n title={isDefined(amount) ? hexToBigInt(amount).toString() : ''}\n sx={{\n display: 'inline-flex', alignItems: 'center', gap: theme.spacing(0.25),\n }}\n >\n {transferCardHelper.formatAmountToXl1(amount)}\n <NetworkIcon\n icon={MainNetworkIconString}\n style={{\n width: 16, height: 16, display: 'inline-flex', alignItems: 'end',\n }}\n />\n (XL1)\n </Typography>\n </Stack>\n </ListItemText>\n </ListItem>\n )\n}\n","import { Link } from '@mui/material'\nimport { ellipsize } from '@xylabs/eth-address'\nimport type { Address, Hex } from '@xylabs/hex'\nimport { hexToBigInt, isHex } from '@xylabs/hex'\nimport { isDefined, isUndefined } from '@xylabs/typeof'\nimport type { EventDispatch } from '@xyo-network/react-event'\nimport {\n type AttoXL1, type Transfer, XL1Places,\n} from '@xyo-network/xl1-protocol'\nimport { XL1Amount } from '@xyo-network/xl1-wrappers'\nimport type { ReactNode } from 'react'\nimport React from 'react'\n\nimport type { TransferRenderOptions } from '../lib/index.ts'\n\nexport class TransferCardHelper {\n private _dispatch: EventDispatch | undefined\n private _isMedium: boolean\n private _options: TransferRenderOptions | undefined\n private _payload: Transfer | undefined\n\n constructor(\n isMedium: boolean,\n payload?: Transfer,\n dispatch?: EventDispatch,\n options?: TransferRenderOptions,\n ) {\n this._isMedium = isMedium\n this._options = options\n this._payload = payload\n this._dispatch = dispatch\n }\n\n get dispatch() {\n return this._dispatch\n }\n\n get isMedium() {\n return this._isMedium\n }\n\n get linkedAddresses() {\n return this.options?.links?.has('address')\n }\n\n get options() {\n return this._options\n }\n\n get payload() {\n return this._payload\n }\n\n addressComponent(address?: Address, prefix?: string): ReactNode {\n const resolvedPrefix = isDefined(prefix) ? `${prefix}: ` : ''\n const text = `${this.formatAddress(address) ?? 'Unknown'}`\n if (this.options?.links?.has('address')) {\n return (\n <>\n {resolvedPrefix}\n {' '}\n <Link\n onClick={() => {\n this.dispatch?.('address', 'click', this.payload?.from)\n }}\n sx={{ cursor: 'pointer' }}\n >\n {text}\n </Link>\n </>\n )\n }\n return `${resolvedPrefix}${text}`\n }\n\n formatAddress(address?: Address): string {\n return (address ? (this.isMedium ? address : ellipsize(address, 5)) : '')\n }\n\n formatAmountToXl1(amount?: Hex | bigint): string {\n if (isUndefined(amount)) return ''\n const amountBigInt = isHex(amount) ? hexToBigInt(amount) : amount\n const xl1Amount = XL1Amount.fromAtto(amountBigInt as AttoXL1)\n return amountBigInt < 1_000_000_000_000n && amountBigInt > 0n ? '<0.00001' : xl1Amount.toString(Number(XL1Places.xl1), { locale: navigator.language })\n }\n\n totalTransferred() {\n if (isUndefined(this.payload?.transfers)) return '0'\n let total = 0n\n for (const [, amount] of Object.entries(this.payload.transfers)) {\n if (isDefined(amount)) {\n total += hexToBigInt(amount)\n }\n }\n return this.formatAmountToXl1(total)\n }\n}\n","import type { TypographyProps } from '@mui/material'\nimport { Typography, useTheme } from '@mui/material'\nimport { NetworkIcon } from '@xyo-network/react-chain-network'\nimport { MainNetworkIconString } from '@xyo-network/xl1-network-model'\nimport React from 'react'\n\nimport type { TransferCardHelper } from './TransferRenderCardHelper.tsx'\n\nexport interface TransferRenderTotalTypographyProps extends TypographyProps {\n transferRenderHelper: TransferCardHelper\n}\n\nexport const TransferRenderTotalTypography: React.FC<TransferRenderTotalTypographyProps> = ({\n transferRenderHelper, sx, ...props\n}) => {\n const theme = useTheme()\n\n return (\n <Typography\n sx={{\n display: 'inline-flex', gap: theme.spacing(0.25), fontFamily: 'monospace', ...sx,\n }}\n variant=\"caption\"\n {...props}\n >\n Total:\n {' '}\n <strong>{transferRenderHelper?.totalTransferred()}</strong>\n <NetworkIcon\n icon={MainNetworkIconString}\n style={{\n width: 16, height: 16, display: 'inline-flex', alignItems: 'end',\n }}\n />\n (XL1)\n </Typography>\n )\n}\n"],"mappings":"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","names":["FlexCol","React","Card","CardContent","CardHeader","List","useMediaQuery","useTheme","asAddress","asHex","BlockiesAvatar","useEvent","asTransfer","React","useMemo","ListItem","ListItemAvatar","ListItemText","Stack","Typography","useTheme","asAddress","hexToBigInt","isDefined","BlockiesAvatar","NetworkIcon","MainNetworkIconString","React","TransferRenderListItem","address","amount","sx","transferCardHelper","props","theme","useTheme","ListItem","px","ListItemAvatar","minWidth","mr","spacing","BlockiesAvatar","title","width","height","blockiesOptions","seed","ListItemText","borderBottom","vars","palette","divider","Stack","direction","gap","justifyContent","Typography","component","fontFamily","variant","addressComponent","asAddress","isDefined","hexToBigInt","toString","display","alignItems","formatAmountToXl1","NetworkIcon","icon","MainNetworkIconString","style","Link","ellipsize","hexToBigInt","isHex","isDefined","isUndefined","XL1Places","XL1Amount","React","TransferCardHelper","_dispatch","_isMedium","_options","_payload","isMedium","payload","dispatch","options","linkedAddresses","links","has","addressComponent","address","prefix","resolvedPrefix","isDefined","text","formatAddress","React","Link","onClick","from","sx","cursor","ellipsize","formatAmountToXl1","amount","isUndefined","amountBigInt","isHex","hexToBigInt","xl1Amount","XL1Amount","fromAtto","toString","Number","XL1Places","xl1","locale","navigator","language","totalTransferred","transfers","total","Object","entries","Typography","useTheme","NetworkIcon","MainNetworkIconString","React","TransferRenderTotalTypography","transferRenderHelper","sx","props","theme","useTheme","React","Typography","display","gap","spacing","fontFamily","variant","strong","totalTransferred","NetworkIcon","icon","MainNetworkIconString","style","width","height","alignItems","TransferRenderCard","options","payload","props","theme","useTheme","isMedium","useMediaQuery","breakpoints","up","ref","dispatch","useEvent","transfer","asTransfer","from","transfers","transferCardHelper","useMemo","TransferCardHelper","React","Card","CardHeader","title","addressComponent","slotProps","variant","fontFamily","avatar","BlockiesAvatar","sx","width","height","blockiesOptions","seed","CardContent","pb","spacing","List","Object","entries","map","address","amount","index","TransferRenderListItem","key","asAddress","asHex","TransferRenderTotalTypography","transferRenderHelper","justifyContent","pt","TransferRenderBoxDetails","options","payload","props","React","FlexCol","TransferRenderCard"]}
@@ -0,0 +1,4 @@
1
+ import type { PayloadRenderPlugin } from '@xyo-network/react-payload-plugin';
2
+ export declare const TransferRenderPlugin: PayloadRenderPlugin;
3
+ export default TransferRenderPlugin;
4
+ //# sourceMappingURL=Plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../../src/transfer/Plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AAO5E,eAAO,MAAM,oBAAoB,EAAE,mBAMlC,CAAA;AAED,eAAe,oBAAoB,CAAA"}
@@ -0,0 +1,11 @@
1
+ import type { FlexBoxProps } from '@xylabs/react-flexbox';
2
+ import type { Payload } from '@xyo-network/payload-model';
3
+ import type { PayloadDetailsRenderProps } from '@xyo-network/react-payload-plugin';
4
+ import React from 'react';
5
+ import type { TransferRenderOptions } from '../lib/index.ts';
6
+ export interface TransferRenderBoxDetailsProps extends PayloadDetailsRenderProps, FlexBoxProps {
7
+ options?: TransferRenderOptions;
8
+ payload?: Payload;
9
+ }
10
+ export declare const TransferRenderBoxDetails: React.FC<TransferRenderBoxDetailsProps>;
11
+ //# sourceMappingURL=Details.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Details.d.ts","sourceRoot":"","sources":["../../../../src/transfer/box/Details.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAEzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAA;AAClF,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAE5D,MAAM,WAAW,6BAA8B,SAAQ,yBAAyB,EAAE,YAAY;IAC5F,OAAO,CAAC,EAAE,qBAAqB,CAAA;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,eAAO,MAAM,wBAAwB,EAAE,KAAK,CAAC,EAAE,CAAC,6BAA6B,CAa5E,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { Meta } from '@storybook/react-vite';
2
+ declare const _default: Meta;
3
+ export default _default;
4
+ declare const Default: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react-vite").ReactRenderer, import("./Details.tsx").TransferRenderBoxDetailsProps>;
5
+ declare const WithValue: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react-vite").ReactRenderer, import("./Details.tsx").TransferRenderBoxDetailsProps>;
6
+ declare const WithOptions: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react-vite").ReactRenderer, import("./Details.tsx").TransferRenderBoxDetailsProps>;
7
+ export { Default, WithOptions, WithValue, };
8
+ //# sourceMappingURL=Details.stories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Details.stories.d.ts","sourceRoot":"","sources":["../../../../src/transfer/box/Details.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAW,MAAM,uBAAuB,CAAA;wBA2BrD,IAAI;AAHT,wBAGS;AAaT,QAAA,MAAM,OAAO,yJAAoB,CAAA;AAGjC,QAAA,MAAM,SAAS,yJAAoB,CAAA;AAGnC,QAAA,MAAM,WAAW,yJAAoB,CAAA;AAGrC,OAAO,EACL,OAAO,EAAE,WAAW,EAAE,SAAS,GAChC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './Details.tsx';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/transfer/box/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { type ListItemProps } from '@mui/material';
2
+ import type { Address, Hex } from '@xylabs/hex';
3
+ import React from 'react';
4
+ import type { TransferCardHelper } from './TransferRenderCardHelper.tsx';
5
+ export interface TransferRenderListItem extends ListItemProps {
6
+ address?: Address;
7
+ amount?: Hex;
8
+ transferCardHelper: TransferCardHelper;
9
+ }
10
+ export declare const TransferRenderListItem: React.FC<TransferRenderListItem>;
11
+ //# sourceMappingURL=ListItem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ListItem.d.ts","sourceRoot":"","sources":["../../../../src/transfer/card/ListItem.tsx"],"names":[],"mappings":"AAAA,OAAO,EACqB,KAAK,aAAa,EAE7C,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAM/C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAExE,MAAM,WAAW,sBAAuB,SAAQ,aAAa;IAC3D,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ,kBAAkB,EAAE,kBAAkB,CAAA;CACvC;AAED,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAoCnE,CAAA"}
@@ -0,0 +1,11 @@
1
+ import type { CardProps } from '@mui/material';
2
+ import type { Payload } from '@xyo-network/payload-model';
3
+ import type { PayloadDetailsRenderProps } from '@xyo-network/react-payload-plugin';
4
+ import React from 'react';
5
+ import type { TransferRenderOptions } from '../lib/index.ts';
6
+ export interface TransferRenderCardProps extends PayloadDetailsRenderProps, CardProps {
7
+ options?: TransferRenderOptions;
8
+ payload?: Payload;
9
+ }
10
+ export declare const TransferRenderCard: React.FC<TransferRenderCardProps>;
11
+ //# sourceMappingURL=TransferRenderCard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransferRenderCard.d.ts","sourceRoot":"","sources":["../../../../src/transfer/card/TransferRenderCard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAK9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAGzD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAA;AAElF,OAAO,KAAkB,MAAM,OAAO,CAAA;AAEtC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAK5D,MAAM,WAAW,uBAAwB,SAAQ,yBAAyB,EAAE,SAAS;IACnF,OAAO,CAAC,EAAE,qBAAqB,CAAA;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CAgDhE,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { Meta } from '@storybook/react-vite';
2
+ declare const _default: Meta;
3
+ export default _default;
4
+ declare const Default: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react-vite").ReactRenderer, import("./TransferRenderCard.tsx").TransferRenderCardProps>;
5
+ declare const WithValue: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react-vite").ReactRenderer, import("./TransferRenderCard.tsx").TransferRenderCardProps>;
6
+ declare const WithOptions: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react-vite").ReactRenderer, import("./TransferRenderCard.tsx").TransferRenderCardProps>;
7
+ export { Default, WithOptions, WithValue, };
8
+ //# sourceMappingURL=TransferRenderCard.stories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransferRenderCard.stories.d.ts","sourceRoot":"","sources":["../../../../src/transfer/card/TransferRenderCard.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAW,MAAM,uBAAuB,CAAA;wBA2BrD,IAAI;AAHT,wBAGS;AAaT,QAAA,MAAM,OAAO,8JAAoB,CAAA;AAGjC,QAAA,MAAM,SAAS,8JAAoB,CAAA;AAGnC,QAAA,MAAM,WAAW,8JAAoB,CAAA;AAGrC,OAAO,EACL,OAAO,EAAE,WAAW,EAAE,SAAS,GAChC,CAAA"}
@@ -0,0 +1,22 @@
1
+ import type { Address, Hex } from '@xylabs/hex';
2
+ import type { EventDispatch } from '@xyo-network/react-event';
3
+ import { type Transfer } from '@xyo-network/xl1-protocol';
4
+ import type { ReactNode } from 'react';
5
+ import type { TransferRenderOptions } from '../lib/index.ts';
6
+ export declare class TransferCardHelper {
7
+ private _dispatch;
8
+ private _isMedium;
9
+ private _options;
10
+ private _payload;
11
+ constructor(isMedium: boolean, payload?: Transfer, dispatch?: EventDispatch, options?: TransferRenderOptions);
12
+ get dispatch(): EventDispatch | undefined;
13
+ get isMedium(): boolean;
14
+ get linkedAddresses(): boolean | undefined;
15
+ get options(): TransferRenderOptions | undefined;
16
+ get payload(): Transfer | undefined;
17
+ addressComponent(address?: Address, prefix?: string): ReactNode;
18
+ formatAddress(address?: Address): string;
19
+ formatAmountToXl1(amount?: Hex | bigint): string;
20
+ totalTransferred(): string;
21
+ }
22
+ //# sourceMappingURL=TransferRenderCardHelper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransferRenderCardHelper.d.ts","sourceRoot":"","sources":["../../../../src/transfer/card/TransferRenderCardHelper.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAG/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EACS,KAAK,QAAQ,EAC5B,MAAM,2BAA2B,CAAA;AAElC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGtC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAE5D,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,SAAS,CAA2B;IAC5C,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAmC;IACnD,OAAO,CAAC,QAAQ,CAAsB;gBAGpC,QAAQ,EAAE,OAAO,EACjB,OAAO,CAAC,EAAE,QAAQ,EAClB,QAAQ,CAAC,EAAE,aAAa,EACxB,OAAO,CAAC,EAAE,qBAAqB;IAQjC,IAAI,QAAQ,8BAEX;IAED,IAAI,QAAQ,YAEX;IAED,IAAI,eAAe,wBAElB;IAED,IAAI,OAAO,sCAEV;IAED,IAAI,OAAO,yBAEV;IAED,gBAAgB,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS;IAsB/D,aAAa,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM;IAIxC,iBAAiB,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,MAAM,GAAG,MAAM;IAOhD,gBAAgB;CAUjB"}
@@ -0,0 +1,8 @@
1
+ import type { TypographyProps } from '@mui/material';
2
+ import React from 'react';
3
+ import type { TransferCardHelper } from './TransferRenderCardHelper.tsx';
4
+ export interface TransferRenderTotalTypographyProps extends TypographyProps {
5
+ transferRenderHelper: TransferCardHelper;
6
+ }
7
+ export declare const TransferRenderTotalTypography: React.FC<TransferRenderTotalTypographyProps>;
8
+ //# sourceMappingURL=TransferRenderTotalTypography.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransferRenderTotalTypography.d.ts","sourceRoot":"","sources":["../../../../src/transfer/card/TransferRenderTotalTypography.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAIpD,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAExE,MAAM,WAAW,kCAAmC,SAAQ,eAAe;IACzE,oBAAoB,EAAE,kBAAkB,CAAA;CACzC;AAED,eAAO,MAAM,6BAA6B,EAAE,KAAK,CAAC,EAAE,CAAC,kCAAkC,CAyBtF,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './TransferRenderCard.tsx';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/transfer/card/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from './box/index.ts';
2
+ export * from './card/index.ts';
3
+ export { default } from './Plugin.ts';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transfer/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA"}
@@ -0,0 +1,5 @@
1
+ export type LinkableFields = 'address';
2
+ export type TransferRenderOptions = {
3
+ links: Set<LinkableFields>;
4
+ };
5
+ //# sourceMappingURL=TransferRenderOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransferRenderOptions.d.ts","sourceRoot":"","sources":["../../../../src/transfer/lib/TransferRenderOptions.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,SAAS,CAAA;AAEtC,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,GAAG,CAAC,cAAc,CAAC,CAAA;CAC3B,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './TransferRenderOptions.ts';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/transfer/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA"}
package/package.json ADDED
@@ -0,0 +1,83 @@
1
+ {
2
+ "$schema": "http://json.schemastore.org/package.json",
3
+ "name": "@xyo-network/react-chain-transfer-plugin",
4
+ "version": "1.12.7",
5
+ "description": "XYO Layer One API",
6
+ "homepage": "https://xylabs.com",
7
+ "bugs": {
8
+ "url": "git+https://github.com/xylabs/xyo-chain/issues",
9
+ "email": "support@xylabs.com"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/xylabs/xyo-chain.git"
14
+ },
15
+ "license": "LGPL-3.0-only",
16
+ "author": {
17
+ "name": "XY Labs Development Team",
18
+ "email": "support@xylabs.com",
19
+ "url": "https://xylabs.com"
20
+ },
21
+ "sideEffects": false,
22
+ "type": "module",
23
+ "exports": {
24
+ ".": {
25
+ "browser": {
26
+ "types": "./dist/browser/index.d.ts",
27
+ "source": "./src/index.ts",
28
+ "default": "./dist/browser/index.mjs"
29
+ },
30
+ "types": "./dist/browser/index.d.ts",
31
+ "source": "./src/index.ts",
32
+ "default": "./dist/browser/index.mjs"
33
+ },
34
+ "./package.json": "./package.json"
35
+ },
36
+ "module": "./dist/browser/index.mjs",
37
+ "source": "./src/index.ts",
38
+ "types": "./dist/browser/index.d.ts",
39
+ "files": [
40
+ "dist",
41
+ "src"
42
+ ],
43
+ "dependencies": {
44
+ "@xylabs/hex": "~5.0.10",
45
+ "@xyo-network/react-event": "~7.0.1",
46
+ "@xyo-network/xl1-protocol": "~1.10.15"
47
+ },
48
+ "devDependencies": {
49
+ "@emotion/react": "~11.14.0",
50
+ "@emotion/styled": "~11.14.1",
51
+ "@mui/material": "~7.3.1",
52
+ "@storybook/react-vite": "~9.1.2",
53
+ "@types/react": "~19.1.10",
54
+ "@xylabs/eth-address": "~5.0.10",
55
+ "@xylabs/react-flexbox": "~7.0.4",
56
+ "@xylabs/ts-scripts-yarn3": "~7.1.7",
57
+ "@xylabs/tsconfig": "~7.1.7",
58
+ "@xylabs/tsconfig-dom": "~7.1.7",
59
+ "@xylabs/tsconfig-react": "~7.1.7",
60
+ "@xylabs/typeof": "~5.0.10",
61
+ "@xyo-network/payload-model": "~5.0.7",
62
+ "@xyo-network/react-chain-blockies": "~1.12.7",
63
+ "@xyo-network/react-chain-network": "~1.12.7",
64
+ "@xyo-network/react-payload-plugin": "~7.0.1",
65
+ "@xyo-network/xl1-network-model": "~1.12.7",
66
+ "@xyo-network/xl1-wrappers": "~1.12.7",
67
+ "typescript": "~5.9.2"
68
+ },
69
+ "peerDependencies": {
70
+ "react": "~19.1.1"
71
+ },
72
+ "packageManager": "yarn@4.6.0",
73
+ "engines": {
74
+ "node": ">=22"
75
+ },
76
+ "volta": {
77
+ "node": "22.5.1",
78
+ "yarn": "4.6.0"
79
+ },
80
+ "publishConfig": {
81
+ "access": "public"
82
+ }
83
+ }
@@ -0,0 +1 @@
1
+ import '@mui/material/themeCssVarsAugmentation'
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './transfer/index.ts'
@@ -0,0 +1,17 @@
1
+ import type { Payload } from '@xyo-network/payload-model'
2
+ import type { PayloadRenderPlugin } from '@xyo-network/react-payload-plugin'
3
+ import { createPayloadRenderPlugin } from '@xyo-network/react-payload-plugin'
4
+ import { TransferSchema } from '@xyo-network/xl1-protocol'
5
+
6
+ import { TransferRenderBoxDetails } from './box/index.ts'
7
+ import { TransferRenderCard } from './card/index.ts'
8
+
9
+ export const TransferRenderPlugin: PayloadRenderPlugin = {
10
+ ...createPayloadRenderPlugin({
11
+ canRender: (payload?: Payload) => payload?.schema === TransferSchema,
12
+ components: { box: { detailsBox: TransferRenderBoxDetails, detailsCard: TransferRenderCard } },
13
+ name: 'Transfer',
14
+ }),
15
+ }
16
+
17
+ export default TransferRenderPlugin
@@ -0,0 +1,52 @@
1
+ import type { Meta, StoryFn } from '@storybook/react-vite'
2
+ import {
3
+ type Address,
4
+ type Hex,
5
+ ZERO_ADDRESS,
6
+ } from '@xylabs/hex'
7
+ import { useEvent } from '@xyo-network/react-event'
8
+ import { type Transfer, TransferSchema } from '@xyo-network/xl1-protocol'
9
+ import React from 'react'
10
+
11
+ import { TransferRenderBoxDetails } from './Details.tsx'
12
+
13
+ const transfer: Transfer = {
14
+ schema: TransferSchema,
15
+ epoch: 1_755_723_852_247,
16
+ from: ZERO_ADDRESS,
17
+ transfers: {
18
+ '1111111111111111111111111111111111111111': '1b1ae4d6e2ef500000',
19
+ '1111111111111111111111111111111111111112': '5150ae84a8cdf00000',
20
+ '1111111111111111111111111111111111111113': '989680',
21
+ '1111111111111111111111111111111111111114': '1b1ae4d6e2ef500000',
22
+ } as Record<Address, Hex>,
23
+ }
24
+
25
+ export default {
26
+ title: 'Payloads/Transfer/Box/Details',
27
+ component: TransferRenderBoxDetails,
28
+ } as Meta
29
+
30
+ const Template: StoryFn<typeof TransferRenderBoxDetails> = (args) => {
31
+ const [ref] = useEvent<HTMLDivElement>((noun, verb, data) => {
32
+ alert(`${noun} ${verb} ${data}`)
33
+ })
34
+ return (
35
+ <span ref={ref}>
36
+ <TransferRenderBoxDetails {...args} />
37
+ </span>
38
+ )
39
+ }
40
+
41
+ const Default = Template.bind({})
42
+ Default.args = {}
43
+
44
+ const WithValue = Template.bind({})
45
+ WithValue.args = { payload: transfer }
46
+
47
+ const WithOptions = Template.bind({})
48
+ WithOptions.args = { payload: transfer, options: { links: new Set(['address']) } }
49
+
50
+ export {
51
+ Default, WithOptions, WithValue,
52
+ }
@@ -0,0 +1,28 @@
1
+ import type { FlexBoxProps } from '@xylabs/react-flexbox'
2
+ import { FlexCol } from '@xylabs/react-flexbox'
3
+ import type { Payload } from '@xyo-network/payload-model'
4
+ import type { PayloadDetailsRenderProps } from '@xyo-network/react-payload-plugin'
5
+ import React from 'react'
6
+
7
+ import { TransferRenderCard } from '../card/index.ts'
8
+ import type { TransferRenderOptions } from '../lib/index.ts'
9
+
10
+ export interface TransferRenderBoxDetailsProps extends PayloadDetailsRenderProps, FlexBoxProps {
11
+ options?: TransferRenderOptions
12
+ payload?: Payload
13
+ }
14
+
15
+ export const TransferRenderBoxDetails: React.FC<TransferRenderBoxDetailsProps> = ({
16
+ options,
17
+ payload,
18
+ ...props
19
+ }) => {
20
+ return (
21
+ <FlexCol {...props}>
22
+ <TransferRenderCard
23
+ options={options}
24
+ payload={payload}
25
+ />
26
+ </FlexCol>
27
+ )
28
+ }
@@ -0,0 +1 @@
1
+ export * from './Details.tsx'
@@ -0,0 +1,57 @@
1
+ import {
2
+ ListItem, ListItemAvatar, type ListItemProps, ListItemText, Stack, Typography,
3
+ useTheme,
4
+ } from '@mui/material'
5
+ import type { Address, Hex } from '@xylabs/hex'
6
+ import { asAddress, hexToBigInt } from '@xylabs/hex'
7
+ import { isDefined } from '@xylabs/typeof'
8
+ import { BlockiesAvatar } from '@xyo-network/react-chain-blockies'
9
+ import { NetworkIcon } from '@xyo-network/react-chain-network'
10
+ import { MainNetworkIconString } from '@xyo-network/xl1-network-model'
11
+ import React from 'react'
12
+
13
+ import type { TransferCardHelper } from './TransferRenderCardHelper.tsx'
14
+
15
+ export interface TransferRenderListItem extends ListItemProps {
16
+ address?: Address
17
+ amount?: Hex
18
+ transferCardHelper: TransferCardHelper
19
+ }
20
+
21
+ export const TransferRenderListItem: React.FC<TransferRenderListItem> = ({
22
+ address, amount, sx, transferCardHelper, ...props
23
+ }) => {
24
+ const theme = useTheme()
25
+ return (
26
+ <ListItem sx={{ px: 0, ...sx }} {...props}>
27
+ <ListItemAvatar sx={{ minWidth: 30, mr: theme.spacing(2) }}>
28
+ <BlockiesAvatar title={address} sx={{ width: 30, height: 30 }} blockiesOptions={{ seed: address }} />
29
+ </ListItemAvatar>
30
+ <ListItemText sx={{ borderBottom: `1px solid ${theme.vars.palette.divider}` }}>
31
+ <Stack direction="row" gap={2} justifyContent="space-between" width="100%">
32
+ <Typography component="span" fontFamily="monospace" variant="caption">
33
+ {transferCardHelper.addressComponent(asAddress(address), 'To')}
34
+ </Typography>
35
+ <Typography
36
+ component="span"
37
+ fontFamily="monospace"
38
+ variant="caption"
39
+ title={isDefined(amount) ? hexToBigInt(amount).toString() : ''}
40
+ sx={{
41
+ display: 'inline-flex', alignItems: 'center', gap: theme.spacing(0.25),
42
+ }}
43
+ >
44
+ {transferCardHelper.formatAmountToXl1(amount)}
45
+ <NetworkIcon
46
+ icon={MainNetworkIconString}
47
+ style={{
48
+ width: 16, height: 16, display: 'inline-flex', alignItems: 'end',
49
+ }}
50
+ />
51
+ (XL1)
52
+ </Typography>
53
+ </Stack>
54
+ </ListItemText>
55
+ </ListItem>
56
+ )
57
+ }
@@ -0,0 +1,52 @@
1
+ import type { Meta, StoryFn } from '@storybook/react-vite'
2
+ import {
3
+ type Address,
4
+ type Hex,
5
+ ZERO_ADDRESS,
6
+ } from '@xylabs/hex'
7
+ import { useEvent } from '@xyo-network/react-event'
8
+ import { type Transfer, TransferSchema } from '@xyo-network/xl1-protocol'
9
+ import React from 'react'
10
+
11
+ import { TransferRenderCard } from './TransferRenderCard.tsx'
12
+
13
+ const transfer: Transfer = {
14
+ schema: TransferSchema,
15
+ epoch: 1_755_723_852_247,
16
+ from: ZERO_ADDRESS,
17
+ transfers: {
18
+ '1111111111111111111111111111111111111111': '1b1ae4d6e2ef500000',
19
+ '1111111111111111111111111111111111111112': '5150ae84a8cdf00000',
20
+ '1111111111111111111111111111111111111113': '989680',
21
+ '1111111111111111111111111111111111111114': '1b1ae4d6e2ef500000',
22
+ } as Record<Address, Hex>,
23
+ }
24
+
25
+ export default {
26
+ title: 'Payloads/Transfer/Card',
27
+ component: TransferRenderCard,
28
+ } as Meta
29
+
30
+ const Template: StoryFn<typeof TransferRenderCard> = (args) => {
31
+ const [ref] = useEvent<HTMLDivElement>((noun, verb, data) => {
32
+ alert(`${noun} ${verb} ${data}`)
33
+ })
34
+ return (
35
+ <span ref={ref}>
36
+ <TransferRenderCard {...args} />
37
+ </span>
38
+ )
39
+ }
40
+
41
+ const Default = Template.bind({})
42
+ Default.args = {}
43
+
44
+ const WithValue = Template.bind({})
45
+ WithValue.args = { payload: transfer }
46
+
47
+ const WithOptions = Template.bind({})
48
+ WithOptions.args = { payload: transfer, options: { links: new Set(['address']) } }
49
+
50
+ export {
51
+ Default, WithOptions, WithValue,
52
+ }
@@ -0,0 +1,71 @@
1
+ import type { CardProps } from '@mui/material'
2
+ import {
3
+ Card, CardContent, CardHeader, List, useMediaQuery, useTheme,
4
+ } from '@mui/material'
5
+ import { asAddress, asHex } from '@xylabs/hex'
6
+ import type { Payload } from '@xyo-network/payload-model'
7
+ import { BlockiesAvatar } from '@xyo-network/react-chain-blockies'
8
+ import { useEvent } from '@xyo-network/react-event'
9
+ import type { PayloadDetailsRenderProps } from '@xyo-network/react-payload-plugin'
10
+ import { asTransfer } from '@xyo-network/xl1-protocol'
11
+ import React, { useMemo } from 'react'
12
+
13
+ import type { TransferRenderOptions } from '../lib/index.ts'
14
+ import { TransferRenderListItem } from './ListItem.tsx'
15
+ import { TransferCardHelper } from './TransferRenderCardHelper.tsx'
16
+ import { TransferRenderTotalTypography } from './TransferRenderTotalTypography.tsx'
17
+
18
+ export interface TransferRenderCardProps extends PayloadDetailsRenderProps, CardProps {
19
+ options?: TransferRenderOptions
20
+ payload?: Payload
21
+ }
22
+
23
+ export const TransferRenderCard: React.FC<TransferRenderCardProps> = ({
24
+ options, payload, ...props
25
+ }) => {
26
+ const theme = useTheme()
27
+ const isMedium = useMediaQuery(theme => theme.breakpoints.up('sm'))
28
+ const [ref, dispatch] = useEvent<HTMLDivElement>()
29
+ const transfer = asTransfer(payload)
30
+ const { from, transfers } = transfer ?? {}
31
+
32
+ const transferCardHelper = useMemo(
33
+ () =>
34
+ new TransferCardHelper(isMedium, asTransfer(payload), dispatch, options),
35
+ [isMedium, payload, dispatch, options],
36
+ )
37
+
38
+ return (
39
+ <Card ref={ref} {...props}>
40
+ <CardHeader
41
+ title={transferCardHelper.addressComponent(from, 'From')}
42
+ slotProps={{
43
+ title: {
44
+ title: from, variant: 'body1', fontFamily: 'monospace',
45
+ },
46
+ }}
47
+ avatar={<BlockiesAvatar sx={{ width: 30, height: 30 }} title={from} blockiesOptions={{ seed: from }} />}
48
+ />
49
+ <CardContent sx={{ '&:last-child': { pb: theme.spacing(0) } }}>
50
+ <List>
51
+ {Object.entries(transfers ?? {}).map(([address, amount], index) => (
52
+ <TransferRenderListItem
53
+ // eslint-disable-next-line @eslint-react/no-array-index-key
54
+ key={index}
55
+ address={asAddress(address)}
56
+ amount={asHex(amount)}
57
+ transferCardHelper={transferCardHelper}
58
+ />
59
+ ))}
60
+ </List>
61
+ <TransferRenderTotalTypography
62
+ transferRenderHelper={transferCardHelper}
63
+ sx={{
64
+ // pt matches bottom padding of the ListItem
65
+ width: '100%', justifyContent: 'end', pt: 0.666_666_666_7, pb: theme.spacing(2),
66
+ }}
67
+ />
68
+ </CardContent>
69
+ </Card>
70
+ )
71
+ }
@@ -0,0 +1,97 @@
1
+ import { Link } from '@mui/material'
2
+ import { ellipsize } from '@xylabs/eth-address'
3
+ import type { Address, Hex } from '@xylabs/hex'
4
+ import { hexToBigInt, isHex } from '@xylabs/hex'
5
+ import { isDefined, isUndefined } from '@xylabs/typeof'
6
+ import type { EventDispatch } from '@xyo-network/react-event'
7
+ import {
8
+ type AttoXL1, type Transfer, XL1Places,
9
+ } from '@xyo-network/xl1-protocol'
10
+ import { XL1Amount } from '@xyo-network/xl1-wrappers'
11
+ import type { ReactNode } from 'react'
12
+ import React from 'react'
13
+
14
+ import type { TransferRenderOptions } from '../lib/index.ts'
15
+
16
+ export class TransferCardHelper {
17
+ private _dispatch: EventDispatch | undefined
18
+ private _isMedium: boolean
19
+ private _options: TransferRenderOptions | undefined
20
+ private _payload: Transfer | undefined
21
+
22
+ constructor(
23
+ isMedium: boolean,
24
+ payload?: Transfer,
25
+ dispatch?: EventDispatch,
26
+ options?: TransferRenderOptions,
27
+ ) {
28
+ this._isMedium = isMedium
29
+ this._options = options
30
+ this._payload = payload
31
+ this._dispatch = dispatch
32
+ }
33
+
34
+ get dispatch() {
35
+ return this._dispatch
36
+ }
37
+
38
+ get isMedium() {
39
+ return this._isMedium
40
+ }
41
+
42
+ get linkedAddresses() {
43
+ return this.options?.links?.has('address')
44
+ }
45
+
46
+ get options() {
47
+ return this._options
48
+ }
49
+
50
+ get payload() {
51
+ return this._payload
52
+ }
53
+
54
+ addressComponent(address?: Address, prefix?: string): ReactNode {
55
+ const resolvedPrefix = isDefined(prefix) ? `${prefix}: ` : ''
56
+ const text = `${this.formatAddress(address) ?? 'Unknown'}`
57
+ if (this.options?.links?.has('address')) {
58
+ return (
59
+ <>
60
+ {resolvedPrefix}
61
+ {' '}
62
+ <Link
63
+ onClick={() => {
64
+ this.dispatch?.('address', 'click', this.payload?.from)
65
+ }}
66
+ sx={{ cursor: 'pointer' }}
67
+ >
68
+ {text}
69
+ </Link>
70
+ </>
71
+ )
72
+ }
73
+ return `${resolvedPrefix}${text}`
74
+ }
75
+
76
+ formatAddress(address?: Address): string {
77
+ return (address ? (this.isMedium ? address : ellipsize(address, 5)) : '')
78
+ }
79
+
80
+ formatAmountToXl1(amount?: Hex | bigint): string {
81
+ if (isUndefined(amount)) return ''
82
+ const amountBigInt = isHex(amount) ? hexToBigInt(amount) : amount
83
+ const xl1Amount = XL1Amount.fromAtto(amountBigInt as AttoXL1)
84
+ return amountBigInt < 1_000_000_000_000n && amountBigInt > 0n ? '<0.00001' : xl1Amount.toString(Number(XL1Places.xl1), { locale: navigator.language })
85
+ }
86
+
87
+ totalTransferred() {
88
+ if (isUndefined(this.payload?.transfers)) return '0'
89
+ let total = 0n
90
+ for (const [, amount] of Object.entries(this.payload.transfers)) {
91
+ if (isDefined(amount)) {
92
+ total += hexToBigInt(amount)
93
+ }
94
+ }
95
+ return this.formatAmountToXl1(total)
96
+ }
97
+ }
@@ -0,0 +1,38 @@
1
+ import type { TypographyProps } from '@mui/material'
2
+ import { Typography, useTheme } from '@mui/material'
3
+ import { NetworkIcon } from '@xyo-network/react-chain-network'
4
+ import { MainNetworkIconString } from '@xyo-network/xl1-network-model'
5
+ import React from 'react'
6
+
7
+ import type { TransferCardHelper } from './TransferRenderCardHelper.tsx'
8
+
9
+ export interface TransferRenderTotalTypographyProps extends TypographyProps {
10
+ transferRenderHelper: TransferCardHelper
11
+ }
12
+
13
+ export const TransferRenderTotalTypography: React.FC<TransferRenderTotalTypographyProps> = ({
14
+ transferRenderHelper, sx, ...props
15
+ }) => {
16
+ const theme = useTheme()
17
+
18
+ return (
19
+ <Typography
20
+ sx={{
21
+ display: 'inline-flex', gap: theme.spacing(0.25), fontFamily: 'monospace', ...sx,
22
+ }}
23
+ variant="caption"
24
+ {...props}
25
+ >
26
+ Total:
27
+ {' '}
28
+ <strong>{transferRenderHelper?.totalTransferred()}</strong>
29
+ <NetworkIcon
30
+ icon={MainNetworkIconString}
31
+ style={{
32
+ width: 16, height: 16, display: 'inline-flex', alignItems: 'end',
33
+ }}
34
+ />
35
+ (XL1)
36
+ </Typography>
37
+ )
38
+ }
@@ -0,0 +1 @@
1
+ export * from './TransferRenderCard.tsx'
@@ -0,0 +1,3 @@
1
+ export * from './box/index.ts'
2
+ export * from './card/index.ts'
3
+ export { default } from './Plugin.ts'
@@ -0,0 +1,5 @@
1
+ export type LinkableFields = 'address'
2
+
3
+ export type TransferRenderOptions = {
4
+ links: Set<LinkableFields>
5
+ }
@@ -0,0 +1 @@
1
+ export * from './TransferRenderOptions.ts'