@xyo-network/react-wallet 2.78.0 → 2.78.1

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.
@@ -1,2 +1,802 @@
1
- import{ButtonGroup as De,TableCell as z,TableRow as Ee,Typography as Oe}from"@mui/material";import{ButtonEx as X}from"@xylabs/react-button";import{useState as J}from"react";import{Alert as ye,AlertTitle as Te,Snackbar as Fe}from"@mui/material";import{jsx as K,jsxs as Re}from"react/jsx-runtime";var q=({activeAccountIndex:e,desiredMaximumAccounts:t,setShowSnackBar:o,showSnackBar:r})=>K(Fe,{anchorOrigin:{horizontal:"center",vertical:"top"},autoHideDuration:5e3,onClose:()=>o?.(!1),open:r,children:Re(ye,{severity:"error",onClose:()=>o?.(!1),children:[K(Te,{children:"Maximum Accounts Error"}),"Your currently selected account number (",e===void 0?"":e+1,") cannot be greater than the desired Maximum Accounts (",t,")."]})});import{jsx as v,jsxs as N}from"react/jsx-runtime";var Bo=({activeAccountIndex:e,changeMaxAccounts:t,maxAccounts:o})=>{let[r,a]=J(),[n,s]=J(!1),i=c=>{if(o!==void 0&&e!==void 0)switch(c){case"decrease":{let l=o-1,u=l>0,m=e+1<=l;u&&m&&t?.(l),m||s(!0),a(l);return}case"increase":{t?.(o+1);return}default:console.error(c,"is not a recognized value")}else throw new Error("Max Accounts is unset and needs a default")};return N(Ee,{children:[v(z,{children:"Maximum Accounts"}),v(z,{align:"center",children:v(Oe,{variant:"caption",children:o})}),N(z,{align:"center",children:[N(De,{children:[v(X,{onClick:()=>i("decrease"),variant:"contained",size:"small",children:"-"}),v(X,{onClick:()=>i("increase"),variant:"contained",size:"small",children:"+"})]}),v(q,{desiredMaximumAccounts:r,activeAccountIndex:e,setShowSnackBar:s,showSnackBar:n})]})]})};import{HelpOutline as Me}from"@mui/icons-material";import{Button as He,Dialog as ze,DialogActions as Ne,DialogContent as Ge,DialogTitle as Le,IconButton as $e,Link as _e,List as Ue,ListItem as y,Typography as Ve}from"@mui/material";import{useState as Ye}from"react";import{Fragment as Ke,jsx as x,jsxs as b}from"react/jsx-runtime";var T=e=>{let[t,o]=Ye(!1),r=()=>o(!1);return b(Ke,{children:[x($e,{onClick:()=>o(!0),...e,children:x(Me,{fontSize:"small"})}),b(ze,{open:t,children:[x(Le,{children:"Understanding your Seed Phrase"}),b(Ge,{children:[b(Ve,{children:["Your Seed Phrase should adhere to the"," ",x(_e,{target:"_blank",href:"https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki",children:"bip39 specification"})," ","and is used to generate accounts which identify your data on the XYO Network."]}),b(Ue,{children:[x(y,{children:"Do not share this phrase with anyone."}),x(y,{children:"Do not save it to a public computer."}),x(y,{children:"Do not use a existing phrase from another wallet (i.e. Metamask)."}),x(y,{children:"Do not use before copying it down somewhere safe."})]})]}),x(Ne,{children:x(He,{onClick:r,variant:"outlined",children:"OK"})})]})]})};import{Alert as qe,AlertTitle as Xe,Snackbar as Je}from"@mui/material";import{generateMnemonic as Qe}from"@scure/bip39";import{wordlist as Ze}from"@scure/bip39/wordlists/english";import{useEffect as je,useState as et}from"react";import{Fragment as tt,jsx as Q,jsxs as Z}from"react/jsx-runtime";var No=({changeSeedPhrase:e,children:t,hideDefaultSeedPhraseMessage:o,seedPhrase:r})=>{let[a,n]=et(!1);return je(()=>{if(!r){let s=Qe(Ze,256);e?.(s),n(!0)}},[e,r]),Z(tt,{children:[o?null:Q(Je,{open:a,autoHideDuration:5e3,onClose:()=>n(!1),anchorOrigin:{horizontal:"center",vertical:"top"},children:Z(qe,{severity:"success",children:[Q(Xe,{children:"Default Seed Phrase Generated"}),"Go to application settings to save it."]})}),t]})};import{Button as se,DialogActions as xt}from"@mui/material";import{createContextEx as ot}from"@xyo-network/react-shared";var F=ot();import{generateMnemonic as rt,validateMnemonic as nt}from"@scure/bip39";import{wordlist as te}from"@scure/bip39/wordlists/english";import{useCallback as R,useEffect as G,useMemo as j,useState as ee}from"react";import{jsx as at}from"react/jsx-runtime";var L=e=>e?nt(e,te):null,oe=({children:e,defaultPhrase:t,handleChangeSeedPhrase:o,saveCallback:r,seedPhrase:a,open:n})=>{let[s,i]=ee(),[c,l]=ee(!1);G(()=>{i(t)},[t]),G(()=>{(a||n)&&i?.(a??"")},[a,n,i]);let u=R(()=>{let C=rt(te,256);i?.(C),l?.(!1)},[]),m=R(()=>{l?.(!1)},[]),k=R(()=>{i?.(""),l?.(!1)},[]),p=R(()=>{!c&&a&&a!==s?l?.(!0):(o?.(s??""),r?.())},[o,c,s,r,a]);G(()=>{n||m()},[m,n]);let M=j(()=>L?.(a),[a]),d=j(()=>L?.(s),[s]);return at(F.Provider,{value:{handleCancelOverwrite:m,handleChangeSeedPhrase:o,handleClear:k,handleGenerate:u,handleSave:p,overwriteWarning:c,phrase:s,provided:!0,seedPhrase:a,setOverwriteWarning:l,setPhrase:i,validPhrase:d,validSeedPhrase:M,validate:L},children:e})};import{useContextEx as st}from"@xyo-network/react-shared";var f=()=>st(F,"SeedPhrase",!0);import{createContextEx as lt}from"@xyo-network/react-shared";var w=lt();import{usePromise as it}from"@xylabs/react-promise";import{useEffect as ct,useState as dt}from"react";import{jsx as ut}from"react/jsx-runtime";var nr=({children:e,defaultActiveAccountIndex:t=0,rootWallet:o=null,...r})=>{let[a,n]=dt(t);ct(()=>{t!==void 0&&n(t)},[t]);let[s=null]=it(async()=>await o?.derivePath(a.toString()),[a,o]);return ut(w.Provider,{value:{activeAccount:s,activeAccountIndex:a,provided:!0,rootWallet:o,setActiveAccountIndex:n},...r,children:e})};import{usePromise as mt}from"@xylabs/react-promise";import{useContextEx as pt,useProvided as ft}from"@xyo-network/react-shared";var h=(e=!0)=>pt(w,"Wallet",e),re=()=>ft(w),ne=(e=!0)=>{let{rootWallet:t}=h(e);return[t,void 0]},ht=(e,t=!0)=>{let{rootWallet:o}=h(t),[r]=mt(async()=>await o?.derivePath(e.toString())??o,[o,e]);return[r,void 0]},ae=(e=!0)=>{let{activeAccountIndex:t}=h(e),[o]=ht(t??0,e);return t===void 0&&o===null?[null,void 0]:[o,void 0]};import{jsx as le,jsxs as Pt}from"react/jsx-runtime";var ie=({onClose:e,...t})=>{let{handleSave:o,setPhrase:r}=f();return Pt(xt,{...t,children:[le(se,{variant:"outlined",onClick:n=>{r?.(""),e?.(n,"escapeKeyDown")},children:"Cancel"}),le(se,{variant:"outlined",onClick:o,children:"Save"})]})};import{FormControl as Bt,TextField as It}from"@mui/material";var ce=e=>{switch(e){case!0:return"success";case!1:return"error";default:return}};import{Link as St,Typography as gt}from"@mui/material";import{jsx as vt,jsxs as Ct}from"react/jsx-runtime";var D=e=>Ct(gt,{variant:"caption",color:"error",...e,children:["Invalid seed phrase. See -"," ",vt(St,{target:"_blank",href:"https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki",children:"bip39 Proposal"})]});import{CheckCircleOutline as bt,HighlightOff as wt}from"@mui/icons-material";import{FlexRow as Wt}from"@xylabs/react-flexbox";import{useMemo as de}from"react";import{jsx as ue,jsxs as At}from"react/jsx-runtime";var E=({children:e,conditional:t,...o})=>{let r=de(()=>{switch(t){case!0:return"success";case!1:return"error";default:return null}},[t]),a=de(()=>{switch(r){case"success":return ue(bt,{fontSize:"small",color:"success"});case"error":return ue(wt,{fontSize:"small",color:"error"});default:return null}},[r]);return At(Wt,{justifyContent:"start",columnGap:1,...o,children:[a,e]})};import{Fragment as yt,jsx as $,jsxs as kt}from"react/jsx-runtime";var me=({children:e,disableColor:t,...o})=>{let{phrase:r,setPhrase:a,validPhrase:n}=f();return $(yt,{children:kt(Bt,{fullWidth:!0,size:"small",sx:{display:"flex",flexDirection:"column",rowGap:1},children:[e,$(It,{focused:!0,color:t?void 0:ce(n),error:n===!1,helperText:n===!1?$(D,{}):null,fullWidth:!0,maxRows:Number.POSITIVE_INFINITY,multiline:!0,onChange:s=>a?.(s.target.value),value:r,...o})]})})};import{Button as pe,DialogActions as Tt}from"@mui/material";import{jsx as fe,jsxs as Ft}from"react/jsx-runtime";var he=()=>{let{handleClear:e,handleGenerate:t,overwriteWarning:o}=f();return Ft(Tt,{sx:{justifyContent:"center"},children:[fe(pe,{disabled:o,variant:"outlined",onClick:t,children:"Generate"}),fe(pe,{variant:"outlined",onClick:e,children:"Clear"})]})};import{Chip as Rt,FormControl as Dt,FormLabel as Et,TextField as Ot}from"@mui/material";import{useState as Mt}from"react";import{Fragment as Ht,jsx as W,jsxs as xe}from"react/jsx-runtime";var Pe=({fullWidth:e,showPhraseHeader:t,...o})=>{let{validSeedPhrase:r,seedPhrase:a}=f(),[n,s]=Mt(!1);return xe(Dt,{fullWidth:e,size:"small",sx:{display:"flex",flexDirection:"column",rowGap:1},children:[W(Rt,{label:n?"Hide Saved Seed Phrase":"Reveal Saved Seed Phrase",onClick:()=>s(!n),sx:{alignSelf:"center"}}),n?xe(Ht,{children:[t?W(Et,{children:W(E,{conditional:r,children:"Saved Seed Phrase"})}):null,W(Ot,{defaultValue:a,disabled:!0,error:r===!1,helperText:r===!1?W(D,{}):null,fullWidth:!0,maxRows:Number.POSITIVE_INFINITY,multiline:!0,...o})]}):null]})};import{Alert as zt,Button as Se}from"@mui/material";import{FlexRow as Nt}from"@xylabs/react-flexbox";import{jsx as _,jsxs as Gt}from"react/jsx-runtime";var ge=()=>{let{handleCancelOverwrite:e,handleSave:t}=f();return _(zt,{variant:"outlined",severity:"warning",action:Gt(Nt,{sx:{columnGap:1},children:[_(Se,{variant:"outlined",color:"inherit",size:"small",onClick:t,children:"Overwrite"}),_(Se,{variant:"outlined",color:"inherit",size:"small",onClick:e,children:"Cancel"})]}),children:"Are you sure you want to overwrite existing seed phrase? This action cannot be undone."})};import{Dialog as Lt,DialogContent as $t,DialogTitle as _t,FormLabel as Ut}from"@mui/material";import{jsx as P,jsxs as U}from"react/jsx-runtime";var ve=({changeSeedPhrase:e,seedPhrase:t,...o})=>P(oe,{seedPhrase:t,handleChangeSeedPhrase:e,open:o.open,saveCallback:()=>o.onClose?.({},"escapeKeyDown"),children:P(Vt,{...o})}),Vt=e=>{let{overwriteWarning:t,seedPhrase:o,validPhrase:r}=f();return U(Lt,{"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"sm",...e,children:[U(_t,{id:"alert-dialog-title",children:["Update Your Seed Phrase ",P(T,{})]}),U($t,{sx:{display:"flex",flexDirection:"column",rowGap:2},children:[P(me,{children:P(Ut,{children:P(E,{conditional:r,children:"New Seed Phrase"})})}),P(he,{}),o?P(Pe,{}):null,t?P(ge,{}):null]}),P(ie,{onClose:e.onClose})]})};import{Cancel as Yt,RadioButtonChecked as Kt}from"@mui/icons-material";import{Button as qt,ButtonGroup as Xt,TableCell as V,TableRow as Jt}from"@mui/material";import{useState as Qt}from"react";import{jsx as g,jsxs as Y}from"react/jsx-runtime";var dn=({changeSeedPhrase:e,seedPhrase:t,...o})=>{let[r,a]=Qt(!1);return Y(Jt,{...o,children:[Y(V,{children:["Seed Phrase ",g(T,{})]}),g(V,{align:"center",children:t?g(Kt,{color:"success"}):g(Yt,{color:"error"})}),Y(V,{children:[g(ve,{changeSeedPhrase:e,open:r,onClose:()=>a(!1),seedPhrase:t}),g(Xt,{fullWidth:!0,children:g(qt,{variant:"contained",size:"small",onClick:()=>{a(!0)},children:"Update"})})]})]})};import{EthAddress as so}from"@xylabs/eth-address";import{EthAccountButton as lo}from"@xylabs/react-crypto";import{FlexCol as io,FlexRow as co}from"@xylabs/react-flexbox";import{NumberStatus as O}from"@xylabs/react-number-status";import{useNetwork as uo}from"@xyo-network/react-network";import{usePromise as Zt}from"@xylabs/react-promise";import{useState as Ce}from"react";var be=({wallet:e,account:t,index:o,required:r=!1}={})=>{let a=re(),[n,s]=Ce();e&&t&&!n&&s(new Error("useAccount can not have both a wallet and an account in the parameters")),o&&t&&!n&&s(new Error("useAccount can not have both a index and an account in the parameters"));let[i,c]=Ce(),[l]=ne(!e&&r),{activeAccountIndex:u}=h(!1),[m]=Zt(async()=>{try{if(!n){if(e)return await e?.derivePath?.(`${o??0}'\0`);if(l)return await l?.derivePath?.(`${o??u??0}'\0`)}}catch(k){let p=k;console.error(p.message),c(p)}},[o,e,l,u,n]);return n&&!i&&(console.error(n.message),c(n)),[i?void 0:t??m??a?null:void 0,i]};import{usePromise as jt}from"@xylabs/react-promise";import{HDWallet as we}from"@xyo-network/account";import{useState as eo}from"react";var A=({mnemonic:e,wallet:t,path:o,required:r=!1,seed:a}={})=>{let n=h(!1),[s,i]=eo(),[c]=ae(!t&&r),[l]=jt(async()=>{try{let u=await(t||(e?we.fromPhrase(e):a?we.fromSeed(a):c));return o?u?.derivePath?.(o):u??t}catch(u){i(u)}},[e,c,a,o,t]);return[l??(n?null:l),s]};import{usePromise as to}from"@xylabs/react-promise";var An=({wallet:e,paths:t})=>{let o=h(!1),[r]=A({wallet:e}),[a,n]=to(async()=>r?await Promise.all(t.map(s=>r.derivePath(s))):void 0,[r,t]);return[a??(o?null:a),n]};import{usePromise as oo}from"@xylabs/react-promise";import{HDWallet as ro}from"@xyo-network/account";import{Mutex as no}from"async-mutex";var B,ao=new no,Fn=e=>oo(async()=>await ao.runExclusive(async()=>{if(e!==void 0)return e;if(B)return B;try{B=await ro.random(),console.log(`Global Wrapper Wallet Creation Success: ${B.address}`)}catch(t){console.error(`Global Wrapper Wallet Creation Failed: ${t.message}`)}return B}),[e]);import{jsx as I,jsxs as We}from"react/jsx-runtime";var Gn=({exploreUrl:e="https://explore.xyo.network",account:t,...o})=>{let[r]=be({account:t}),{network:a}=uo(),n=`${e}/recent?account=${r?.address}&network=${a?.name??"main"}`;return We(io,{...o,children:[I(lo,{address:so.fromString(r?.address)}),We(co,{gap:1,children:[I(O,{rounded:!0,title:"Tokens",value:0,to:`${n}&schema=network.xyo.account.tokens`,target:"_blank"}),I(O,{rounded:!0,title:"NFTs",value:0,to:`${n}&schema=network.xyo.account.nfts`,target:"_blank"}),I(O,{rounded:!0,title:"Signatures",value:0,to:`${n}&schema=network.xyo.account.signatures`,target:"_blank"}),I(O,{rounded:!0,title:"Signins",value:0,to:`${n}&schema=network.xyo.account.signins`,target:"_blank"})]})]})};import{CircularProgress as mo,MenuItem as Ae}from"@mui/material";import{SelectEx as po}from"@xylabs/react-select";import{AddressRenderRowBox as Be}from"@xyo-network/react-address-render";import{Fragment as ho,jsx as S}from"react/jsx-runtime";var fo=(e,t=0)=>[...Array.from({length:e}).keys()].map(o=>o+t),Ie=({addressNames:e={},iconOnly:t,iconSize:o=24,icons:r,maxAccounts:a=1,showFavorite:n=!1,size:s,variant:i="outlined",...c})=>{let{activeAccountIndex:l=0,setActiveAccountIndex:u,rootWallet:m}=h();return S(ho,{children:m?S(po,{margin:"dense",disabled:!m||l===void 0,renderValue:p=>S(()=>{let[d]=A({path:p.toString(),wallet:m}),C=d?e[d.address]:void 0,H=!!d&&d.address in e;return S(Ae,{value:p,sx:{minHeight:0,paddingBottom:0,paddingTop:0},children:S(Be,{disableSharedRef:!0,flexGrow:1,address:d?.address,iconOnly:t,iconSize:o,icons:r,name:C,favorite:H,showFavorite:n})})},{}),value:l,onChange:p=>u?.(Number.parseInt(`${p.target.value}`)),size:s,variant:i,...c,children:fo(a).map(p=>S(()=>{let[d]=A({path:p.toString(),wallet:m}),C=d?e[d.address]:void 0,H=!!d&&d.address in e;return S(Ae,{value:p,sx:{minHeight:0,paddingBottom:0,paddingTop:0},children:S(Be,{disableSharedRef:!0,flexGrow:1,address:d?.address,favorite:H,iconOnly:t,iconSize:o,icons:r,name:C,showFavorite:n})},d?.address)},{},p))}):S(mo,{size:24})})};import{FlexCol as xo}from"@xylabs/react-flexbox";import{jsx as ke}from"react/jsx-runtime";var ta=({addressNames:e={},iconOnly:t,iconSize:o,icons:r,maxAccounts:a=1,showFavorite:n=!1,size:s="small",...i})=>ke(xo,{alignItems:"stretch",...i,children:ke(Ie,{addressNames:e,fullWidth:!0,showFavorite:n,iconSize:o,iconOnly:t,icons:r,maxAccounts:a,size:s??"small",variant:"outlined"})});export{No as DefaultSeedPhrase,ie as DialogActionButtons,D as InvalidPhraseTypography,Bo as MaxAccountsTableRow,me as NewPhraseTextField,ge as OverwriteWarning,he as PhraseDialogActions,E as PhraseHeaderBox,Pe as SavedPhraseTextField,F as SeedPhraseContext,ve as SeedPhraseDialog,Vt as SeedPhraseDialogInner,T as SeedPhraseIconButton,oe as SeedPhraseProvider,dn as SeedPhraseTableRow,Gn as WalletAccountDetails,Ie as WalletAccountSelect,ta as WalletAccountSelectBar,w as WalletContext,nr as WalletProvider,ce as colorParser,be as useAccount,ht as useIndexedWalletFromContext,ne as useRootWallet,f as useSeedPhrase,ae as useSelectedWalletAccount,A as useWallet,h as useWalletContext,re as useWalletProvided,An as useWallets,Fn as useWrapperAccount};
1
+ // src/components/MaxAccounts/MaxAccountsTableRow.tsx
2
+ import { ButtonGroup, TableCell, TableRow, Typography } from "@mui/material";
3
+ import { ButtonEx } from "@xylabs/react-button";
4
+ import { useState } from "react";
5
+
6
+ // src/components/MaxAccounts/OutOfBoundsSnackBar.tsx
7
+ import { Alert, AlertTitle, Snackbar } from "@mui/material";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+ var OutOfBoundsSnackBar = ({
10
+ activeAccountIndex,
11
+ desiredMaximumAccounts,
12
+ setShowSnackBar,
13
+ showSnackBar
14
+ }) => {
15
+ return /* @__PURE__ */ jsx(
16
+ Snackbar,
17
+ {
18
+ anchorOrigin: { horizontal: "center", vertical: "top" },
19
+ autoHideDuration: 5e3,
20
+ onClose: () => setShowSnackBar?.(false),
21
+ open: showSnackBar,
22
+ children: /* @__PURE__ */ jsxs(Alert, { severity: "error", onClose: () => setShowSnackBar?.(false), children: [
23
+ /* @__PURE__ */ jsx(AlertTitle, { children: "Maximum Accounts Error" }),
24
+ "Your currently selected account number (",
25
+ activeAccountIndex === void 0 ? "" : activeAccountIndex + 1,
26
+ ") cannot be greater than the desired Maximum Accounts (",
27
+ desiredMaximumAccounts,
28
+ ")."
29
+ ] })
30
+ }
31
+ );
32
+ };
33
+
34
+ // src/components/MaxAccounts/MaxAccountsTableRow.tsx
35
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
36
+ var MaxAccountsTableRow = ({ activeAccountIndex, changeMaxAccounts, maxAccounts }) => {
37
+ const [desiredMaximumAccounts, setDesiredMaximumAccounts] = useState();
38
+ const [showSnackBar, setShowSnackBar] = useState(false);
39
+ const handleChangeMaxAccounts = (change) => {
40
+ if (maxAccounts !== void 0 && activeAccountIndex !== void 0) {
41
+ switch (change) {
42
+ case "decrease": {
43
+ const desiredMaximumAccounts2 = maxAccounts - 1;
44
+ const validMaximumAccounts = desiredMaximumAccounts2 > 0;
45
+ const maxAccountsWithinRange = activeAccountIndex + 1 <= desiredMaximumAccounts2;
46
+ if (validMaximumAccounts && maxAccountsWithinRange) {
47
+ changeMaxAccounts?.(desiredMaximumAccounts2);
48
+ }
49
+ if (!maxAccountsWithinRange) setShowSnackBar(true);
50
+ setDesiredMaximumAccounts(desiredMaximumAccounts2);
51
+ return;
52
+ }
53
+ case "increase": {
54
+ changeMaxAccounts?.(maxAccounts + 1);
55
+ return;
56
+ }
57
+ default: {
58
+ console.error(change, "is not a recognized value");
59
+ }
60
+ }
61
+ } else {
62
+ throw new Error("Max Accounts is unset and needs a default");
63
+ }
64
+ };
65
+ return /* @__PURE__ */ jsxs2(TableRow, { children: [
66
+ /* @__PURE__ */ jsx2(TableCell, { children: "Maximum Accounts" }),
67
+ /* @__PURE__ */ jsx2(TableCell, { align: "center", children: /* @__PURE__ */ jsx2(Typography, { variant: "caption", children: maxAccounts }) }),
68
+ /* @__PURE__ */ jsxs2(TableCell, { align: "center", children: [
69
+ /* @__PURE__ */ jsxs2(ButtonGroup, { children: [
70
+ /* @__PURE__ */ jsx2(ButtonEx, { onClick: () => handleChangeMaxAccounts("decrease"), variant: "contained", size: "small", children: "-" }),
71
+ /* @__PURE__ */ jsx2(ButtonEx, { onClick: () => handleChangeMaxAccounts("increase"), variant: "contained", size: "small", children: "+" })
72
+ ] }),
73
+ /* @__PURE__ */ jsx2(
74
+ OutOfBoundsSnackBar,
75
+ {
76
+ desiredMaximumAccounts,
77
+ activeAccountIndex,
78
+ setShowSnackBar,
79
+ showSnackBar
80
+ }
81
+ )
82
+ ] })
83
+ ] });
84
+ };
85
+
86
+ // src/components/SeedPhrase/_shared/SeedPhraseIconButton.tsx
87
+ import { HelpOutline as HelpOutlineIcon } from "@mui/icons-material";
88
+ import {
89
+ Button,
90
+ Dialog,
91
+ DialogActions,
92
+ DialogContent,
93
+ DialogTitle,
94
+ IconButton,
95
+ Link,
96
+ List,
97
+ ListItem,
98
+ Typography as Typography2
99
+ } from "@mui/material";
100
+ import { useState as useState2 } from "react";
101
+ import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
102
+ var SeedPhraseIconButton = (props) => {
103
+ const [open, setOpen] = useState2(false);
104
+ const onClose = () => setOpen(false);
105
+ return /* @__PURE__ */ jsxs3(Fragment, { children: [
106
+ /* @__PURE__ */ jsx3(IconButton, { onClick: () => setOpen(true), ...props, children: /* @__PURE__ */ jsx3(HelpOutlineIcon, { fontSize: "small" }) }),
107
+ /* @__PURE__ */ jsxs3(Dialog, { open, children: [
108
+ /* @__PURE__ */ jsx3(DialogTitle, { children: "Understanding your Seed Phrase" }),
109
+ /* @__PURE__ */ jsxs3(DialogContent, { children: [
110
+ /* @__PURE__ */ jsxs3(Typography2, { children: [
111
+ "Your Seed Phrase should adhere to the",
112
+ " ",
113
+ /* @__PURE__ */ jsx3(Link, { target: "_blank", href: "https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki", children: "bip39 specification" }),
114
+ " ",
115
+ "and is used to generate accounts which identify your data on the XYO Network."
116
+ ] }),
117
+ /* @__PURE__ */ jsxs3(List, { children: [
118
+ /* @__PURE__ */ jsx3(ListItem, { children: "Do not share this phrase with anyone." }),
119
+ /* @__PURE__ */ jsx3(ListItem, { children: "Do not save it to a public computer." }),
120
+ /* @__PURE__ */ jsx3(ListItem, { children: "Do not use a existing phrase from another wallet (i.e. Metamask)." }),
121
+ /* @__PURE__ */ jsx3(ListItem, { children: "Do not use before copying it down somewhere safe." })
122
+ ] })
123
+ ] }),
124
+ /* @__PURE__ */ jsx3(DialogActions, { children: /* @__PURE__ */ jsx3(Button, { onClick: onClose, variant: "outlined", children: "OK" }) })
125
+ ] })
126
+ ] });
127
+ };
128
+
129
+ // src/components/SeedPhrase/DefaultSeedPhrase.tsx
130
+ import { Alert as Alert2, AlertTitle as AlertTitle2, Snackbar as Snackbar2 } from "@mui/material";
131
+ import { generateMnemonic } from "@scure/bip39";
132
+ import { wordlist } from "@scure/bip39/wordlists/english";
133
+ import { useEffect, useState as useState3 } from "react";
134
+ import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
135
+ var DefaultSeedPhrase = ({ changeSeedPhrase, children, hideDefaultSeedPhraseMessage, seedPhrase }) => {
136
+ const [showSnackBar, setShowSnackBar] = useState3(false);
137
+ useEffect(() => {
138
+ if (!seedPhrase) {
139
+ const mnemonic = generateMnemonic(wordlist, 256);
140
+ changeSeedPhrase?.(mnemonic);
141
+ setShowSnackBar(true);
142
+ }
143
+ }, [changeSeedPhrase, seedPhrase]);
144
+ return /* @__PURE__ */ jsxs4(Fragment2, { children: [
145
+ hideDefaultSeedPhraseMessage ? null : /* @__PURE__ */ jsx4(
146
+ Snackbar2,
147
+ {
148
+ open: showSnackBar,
149
+ autoHideDuration: 5e3,
150
+ onClose: () => setShowSnackBar(false),
151
+ anchorOrigin: { horizontal: "center", vertical: "top" },
152
+ children: /* @__PURE__ */ jsxs4(Alert2, { severity: "success", children: [
153
+ /* @__PURE__ */ jsx4(AlertTitle2, { children: "Default Seed Phrase Generated" }),
154
+ "Go to application settings to save it."
155
+ ] })
156
+ }
157
+ ),
158
+ children
159
+ ] });
160
+ };
161
+
162
+ // src/components/SeedPhrase/dialog/components/DialogActionButtons.tsx
163
+ import { Button as Button2, DialogActions as DialogActions2 } from "@mui/material";
164
+
165
+ // src/contexts/SeedPhrase/Context.ts
166
+ import { createContextEx } from "@xyo-network/react-shared";
167
+ var SeedPhraseContext = createContextEx();
168
+
169
+ // src/contexts/SeedPhrase/Provider.tsx
170
+ import { generateMnemonic as generateMnemonic2, validateMnemonic } from "@scure/bip39";
171
+ import { wordlist as wordlist2 } from "@scure/bip39/wordlists/english";
172
+ import { useCallback, useEffect as useEffect2, useMemo, useState as useState4 } from "react";
173
+ import { jsx as jsx5 } from "react/jsx-runtime";
174
+ var validate = (passedPhrase) => {
175
+ if (!passedPhrase) {
176
+ return null;
177
+ }
178
+ return validateMnemonic(passedPhrase, wordlist2);
179
+ };
180
+ var SeedPhraseProvider = ({
181
+ children,
182
+ defaultPhrase,
183
+ handleChangeSeedPhrase,
184
+ saveCallback,
185
+ seedPhrase,
186
+ open
187
+ }) => {
188
+ const [phrase, setPhrase] = useState4();
189
+ const [overwriteWarning, setOverwriteWarning] = useState4(false);
190
+ useEffect2(() => {
191
+ setPhrase(defaultPhrase);
192
+ }, [defaultPhrase]);
193
+ useEffect2(() => {
194
+ if (seedPhrase || open) {
195
+ setPhrase?.(seedPhrase ?? "");
196
+ }
197
+ }, [seedPhrase, open, setPhrase]);
198
+ const handleGenerate = useCallback(() => {
199
+ const mnemonic = generateMnemonic2(wordlist2, 256);
200
+ setPhrase?.(mnemonic);
201
+ setOverwriteWarning?.(false);
202
+ }, []);
203
+ const handleCancelOverwrite = useCallback(() => {
204
+ setOverwriteWarning?.(false);
205
+ }, []);
206
+ const handleClear = useCallback(() => {
207
+ setPhrase?.("");
208
+ setOverwriteWarning?.(false);
209
+ }, []);
210
+ const handleSave = useCallback(() => {
211
+ if (!overwriteWarning && seedPhrase && seedPhrase !== phrase) {
212
+ setOverwriteWarning?.(true);
213
+ } else {
214
+ handleChangeSeedPhrase?.(phrase ?? "");
215
+ saveCallback?.();
216
+ }
217
+ }, [handleChangeSeedPhrase, overwriteWarning, phrase, saveCallback, seedPhrase]);
218
+ useEffect2(() => {
219
+ if (!open) {
220
+ handleCancelOverwrite();
221
+ }
222
+ }, [handleCancelOverwrite, open]);
223
+ const validSeedPhrase = useMemo(() => validate?.(seedPhrase), [seedPhrase]);
224
+ const validPhrase = useMemo(() => validate?.(phrase), [phrase]);
225
+ return /* @__PURE__ */ jsx5(
226
+ SeedPhraseContext.Provider,
227
+ {
228
+ value: {
229
+ handleCancelOverwrite,
230
+ handleChangeSeedPhrase,
231
+ handleClear,
232
+ handleGenerate,
233
+ handleSave,
234
+ overwriteWarning,
235
+ phrase,
236
+ provided: true,
237
+ seedPhrase,
238
+ setOverwriteWarning,
239
+ setPhrase,
240
+ validPhrase,
241
+ validSeedPhrase,
242
+ validate
243
+ },
244
+ children
245
+ }
246
+ );
247
+ };
248
+
249
+ // src/contexts/SeedPhrase/use.tsx
250
+ import { useContextEx } from "@xyo-network/react-shared";
251
+ var useSeedPhrase = () => useContextEx(SeedPhraseContext, "SeedPhrase", true);
252
+
253
+ // src/contexts/Wallet/Context.ts
254
+ import { createContextEx as createContextEx2 } from "@xyo-network/react-shared";
255
+ var WalletContext = createContextEx2();
256
+
257
+ // src/contexts/Wallet/Provider.tsx
258
+ import { usePromise } from "@xylabs/react-promise";
259
+ import { useEffect as useEffect3, useState as useState5 } from "react";
260
+ import { jsx as jsx6 } from "react/jsx-runtime";
261
+ var WalletProvider = ({
262
+ children,
263
+ defaultActiveAccountIndex = 0,
264
+ rootWallet = null,
265
+ ...props
266
+ }) => {
267
+ const [activeAccountIndex, setActiveAccountIndex] = useState5(defaultActiveAccountIndex);
268
+ useEffect3(() => {
269
+ if (defaultActiveAccountIndex !== void 0) {
270
+ setActiveAccountIndex(defaultActiveAccountIndex);
271
+ }
272
+ }, [defaultActiveAccountIndex]);
273
+ const [activeAccount = null] = usePromise(async () => await rootWallet?.derivePath(activeAccountIndex.toString()), [activeAccountIndex, rootWallet]);
274
+ return /* @__PURE__ */ jsx6(
275
+ WalletContext.Provider,
276
+ {
277
+ value: {
278
+ activeAccount,
279
+ activeAccountIndex,
280
+ provided: true,
281
+ rootWallet,
282
+ setActiveAccountIndex
283
+ },
284
+ ...props,
285
+ children
286
+ }
287
+ );
288
+ };
289
+
290
+ // src/contexts/Wallet/use.ts
291
+ import { usePromise as usePromise2 } from "@xylabs/react-promise";
292
+ import { useContextEx as useContextEx2, useProvided } from "@xyo-network/react-shared";
293
+ var useWalletContext = (required = true) => {
294
+ return useContextEx2(WalletContext, "Wallet", required);
295
+ };
296
+ var useWalletProvided = () => {
297
+ return useProvided(WalletContext);
298
+ };
299
+ var useRootWallet = (required = true) => {
300
+ const { rootWallet } = useWalletContext(required);
301
+ return [rootWallet, void 0];
302
+ };
303
+ var useIndexedWalletFromContext = (index, required = true) => {
304
+ const { rootWallet } = useWalletContext(required);
305
+ const [wallet] = usePromise2(async () => await rootWallet?.derivePath(index.toString()) ?? rootWallet, [rootWallet, index]);
306
+ return [wallet, void 0];
307
+ };
308
+ var useSelectedWalletAccount = (required = true) => {
309
+ const { activeAccountIndex } = useWalletContext(required);
310
+ const [account] = useIndexedWalletFromContext(activeAccountIndex ?? 0, required);
311
+ return activeAccountIndex === void 0 && account === null ? [null, void 0] : [account, void 0];
312
+ };
313
+
314
+ // src/components/SeedPhrase/dialog/components/DialogActionButtons.tsx
315
+ import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
316
+ var DialogActionButtons = ({ onClose, ...props }) => {
317
+ const { handleSave, setPhrase } = useSeedPhrase();
318
+ const wrappedOnClose = (e) => {
319
+ setPhrase?.("");
320
+ onClose?.(e, "escapeKeyDown");
321
+ };
322
+ return /* @__PURE__ */ jsxs5(DialogActions2, { ...props, children: [
323
+ /* @__PURE__ */ jsx7(Button2, { variant: "outlined", onClick: wrappedOnClose, children: "Cancel" }),
324
+ /* @__PURE__ */ jsx7(Button2, { variant: "outlined", onClick: handleSave, children: "Save" })
325
+ ] });
326
+ };
327
+
328
+ // src/components/SeedPhrase/dialog/components/fields/NewPhraseTextField.tsx
329
+ import { FormControl, TextField } from "@mui/material";
330
+
331
+ // src/components/SeedPhrase/dialog/components/fields/validation-messages/colorParser.ts
332
+ var colorParser = (conditional) => {
333
+ switch (conditional) {
334
+ case true: {
335
+ return "success";
336
+ }
337
+ case false: {
338
+ return "error";
339
+ }
340
+ default: {
341
+ return;
342
+ }
343
+ }
344
+ };
345
+
346
+ // src/components/SeedPhrase/dialog/components/fields/validation-messages/InvalidPhrase.tsx
347
+ import { Link as Link2, Typography as Typography3 } from "@mui/material";
348
+ import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
349
+ var InvalidPhraseTypography = (props) => /* @__PURE__ */ jsxs6(Typography3, { variant: "caption", color: "error", ...props, children: [
350
+ "Invalid seed phrase. See -",
351
+ " ",
352
+ /* @__PURE__ */ jsx8(Link2, { target: "_blank", href: "https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki", children: "bip39 Proposal" })
353
+ ] });
354
+
355
+ // src/components/SeedPhrase/dialog/components/fields/validation-messages/PhraseHeaderBox.tsx
356
+ import { CheckCircleOutline as CheckCircleOutlineIcon, HighlightOff as HighlightOffIcon } from "@mui/icons-material";
357
+ import { FlexRow } from "@xylabs/react-flexbox";
358
+ import { useMemo as useMemo2 } from "react";
359
+ import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
360
+ var PhraseHeaderBox = ({ children, conditional, ...props }) => {
361
+ const state = useMemo2(() => {
362
+ switch (conditional) {
363
+ case true: {
364
+ return "success";
365
+ }
366
+ case false: {
367
+ return "error";
368
+ }
369
+ default: {
370
+ return null;
371
+ }
372
+ }
373
+ }, [conditional]);
374
+ const Icon = useMemo2(() => {
375
+ switch (state) {
376
+ case "success": {
377
+ return /* @__PURE__ */ jsx9(CheckCircleOutlineIcon, { fontSize: "small", color: "success" });
378
+ }
379
+ case "error": {
380
+ return /* @__PURE__ */ jsx9(HighlightOffIcon, { fontSize: "small", color: "error" });
381
+ }
382
+ default: {
383
+ return null;
384
+ }
385
+ }
386
+ }, [state]);
387
+ return /* @__PURE__ */ jsxs7(FlexRow, { justifyContent: "start", columnGap: 1, ...props, children: [
388
+ Icon,
389
+ children
390
+ ] });
391
+ };
392
+
393
+ // src/components/SeedPhrase/dialog/components/fields/NewPhraseTextField.tsx
394
+ import { Fragment as Fragment3, jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
395
+ var NewPhraseTextField = ({ children, disableColor, ...props }) => {
396
+ const { phrase, setPhrase, validPhrase } = useSeedPhrase();
397
+ return /* @__PURE__ */ jsx10(Fragment3, { children: /* @__PURE__ */ jsxs8(FormControl, { fullWidth: true, size: "small", sx: { display: "flex", flexDirection: "column", rowGap: 1 }, children: [
398
+ children,
399
+ /* @__PURE__ */ jsx10(
400
+ TextField,
401
+ {
402
+ focused: true,
403
+ color: disableColor ? void 0 : colorParser(validPhrase),
404
+ error: validPhrase === false,
405
+ helperText: validPhrase === false ? /* @__PURE__ */ jsx10(InvalidPhraseTypography, {}) : null,
406
+ fullWidth: true,
407
+ maxRows: Number.POSITIVE_INFINITY,
408
+ multiline: true,
409
+ onChange: (e) => setPhrase?.(e.target.value),
410
+ value: phrase,
411
+ ...props
412
+ }
413
+ )
414
+ ] }) });
415
+ };
416
+
417
+ // src/components/SeedPhrase/dialog/components/fields/PhraseDialogActions.tsx
418
+ import { Button as Button3, DialogActions as DialogActions3 } from "@mui/material";
419
+ import { jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
420
+ var PhraseDialogActions = () => {
421
+ const { handleClear, handleGenerate, overwriteWarning } = useSeedPhrase();
422
+ return /* @__PURE__ */ jsxs9(DialogActions3, { sx: { justifyContent: "center" }, children: [
423
+ /* @__PURE__ */ jsx11(Button3, { disabled: overwriteWarning, variant: "outlined", onClick: handleGenerate, children: "Generate" }),
424
+ /* @__PURE__ */ jsx11(Button3, { variant: "outlined", onClick: handleClear, children: "Clear" })
425
+ ] });
426
+ };
427
+
428
+ // src/components/SeedPhrase/dialog/components/fields/SavedPhraseTextField.tsx
429
+ import { Chip, FormControl as FormControl2, FormLabel, TextField as TextField2 } from "@mui/material";
430
+ import { useState as useState6 } from "react";
431
+ import { Fragment as Fragment4, jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
432
+ var SavedPhraseTextField = ({ fullWidth, showPhraseHeader, ...props }) => {
433
+ const { validSeedPhrase, seedPhrase } = useSeedPhrase();
434
+ const [visible, setVisible] = useState6(false);
435
+ return /* @__PURE__ */ jsxs10(FormControl2, { fullWidth, size: "small", sx: { display: "flex", flexDirection: "column", rowGap: 1 }, children: [
436
+ /* @__PURE__ */ jsx12(Chip, { label: visible ? "Hide Saved Seed Phrase" : "Reveal Saved Seed Phrase", onClick: () => setVisible(!visible), sx: { alignSelf: "center" } }),
437
+ visible ? /* @__PURE__ */ jsxs10(Fragment4, { children: [
438
+ showPhraseHeader ? /* @__PURE__ */ jsx12(FormLabel, { children: /* @__PURE__ */ jsx12(PhraseHeaderBox, { conditional: validSeedPhrase, children: "Saved Seed Phrase" }) }) : null,
439
+ /* @__PURE__ */ jsx12(
440
+ TextField2,
441
+ {
442
+ defaultValue: seedPhrase,
443
+ disabled: true,
444
+ error: validSeedPhrase === false,
445
+ helperText: validSeedPhrase === false ? /* @__PURE__ */ jsx12(InvalidPhraseTypography, {}) : null,
446
+ fullWidth: true,
447
+ maxRows: Number.POSITIVE_INFINITY,
448
+ multiline: true,
449
+ ...props
450
+ }
451
+ )
452
+ ] }) : null
453
+ ] });
454
+ };
455
+
456
+ // src/components/SeedPhrase/dialog/components/OverwriteWarning.tsx
457
+ import { Alert as Alert3, Button as Button4 } from "@mui/material";
458
+ import { FlexRow as FlexRow2 } from "@xylabs/react-flexbox";
459
+ import { jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
460
+ var OverwriteWarning = () => {
461
+ const { handleCancelOverwrite, handleSave } = useSeedPhrase();
462
+ return /* @__PURE__ */ jsx13(
463
+ Alert3,
464
+ {
465
+ variant: "outlined",
466
+ severity: "warning",
467
+ action: /* @__PURE__ */ jsxs11(FlexRow2, { sx: { columnGap: 1 }, children: [
468
+ /* @__PURE__ */ jsx13(Button4, { variant: "outlined", color: "inherit", size: "small", onClick: handleSave, children: "Overwrite" }),
469
+ /* @__PURE__ */ jsx13(Button4, { variant: "outlined", color: "inherit", size: "small", onClick: handleCancelOverwrite, children: "Cancel" })
470
+ ] }),
471
+ children: "Are you sure you want to overwrite existing seed phrase? This action cannot be undone."
472
+ }
473
+ );
474
+ };
475
+
476
+ // src/components/SeedPhrase/dialog/SeedPhraseDialog.tsx
477
+ import { Dialog as Dialog2, DialogContent as DialogContent2, DialogTitle as DialogTitle2, FormLabel as FormLabel2 } from "@mui/material";
478
+ import { jsx as jsx14, jsxs as jsxs12 } from "react/jsx-runtime";
479
+ var SeedPhraseDialog = ({ changeSeedPhrase, seedPhrase, ...props }) => {
480
+ return /* @__PURE__ */ jsx14(
481
+ SeedPhraseProvider,
482
+ {
483
+ seedPhrase,
484
+ handleChangeSeedPhrase: changeSeedPhrase,
485
+ open: props.open,
486
+ saveCallback: () => props.onClose?.({}, "escapeKeyDown"),
487
+ children: /* @__PURE__ */ jsx14(SeedPhraseDialogInner, { ...props })
488
+ }
489
+ );
490
+ };
491
+ var SeedPhraseDialogInner = (props) => {
492
+ const { overwriteWarning, seedPhrase, validPhrase } = useSeedPhrase();
493
+ return /* @__PURE__ */ jsxs12(Dialog2, { "aria-labelledby": "alert-dialog-title", "aria-describedby": "alert-dialog-description", fullWidth: true, maxWidth: "sm", ...props, children: [
494
+ /* @__PURE__ */ jsxs12(DialogTitle2, { id: "alert-dialog-title", children: [
495
+ "Update Your Seed Phrase ",
496
+ /* @__PURE__ */ jsx14(SeedPhraseIconButton, {})
497
+ ] }),
498
+ /* @__PURE__ */ jsxs12(DialogContent2, { sx: { display: "flex", flexDirection: "column", rowGap: 2 }, children: [
499
+ /* @__PURE__ */ jsx14(NewPhraseTextField, { children: /* @__PURE__ */ jsx14(FormLabel2, { children: /* @__PURE__ */ jsx14(PhraseHeaderBox, { conditional: validPhrase, children: "New Seed Phrase" }) }) }),
500
+ /* @__PURE__ */ jsx14(PhraseDialogActions, {}),
501
+ seedPhrase ? /* @__PURE__ */ jsx14(SavedPhraseTextField, {}) : null,
502
+ overwriteWarning ? /* @__PURE__ */ jsx14(OverwriteWarning, {}) : null
503
+ ] }),
504
+ /* @__PURE__ */ jsx14(DialogActionButtons, { onClose: props.onClose })
505
+ ] });
506
+ };
507
+
508
+ // src/components/SeedPhrase/settings/SeedPhraseTableRow.tsx
509
+ import { Cancel as CancelIcon, RadioButtonChecked as RadioButtonCheckedIcon } from "@mui/icons-material";
510
+ import { Button as Button5, ButtonGroup as ButtonGroup2, TableCell as TableCell2, TableRow as TableRow2 } from "@mui/material";
511
+ import { useState as useState7 } from "react";
512
+ import { jsx as jsx15, jsxs as jsxs13 } from "react/jsx-runtime";
513
+ var SeedPhraseTableRow = ({ changeSeedPhrase, seedPhrase, ...props }) => {
514
+ const [open, setOpen] = useState7(false);
515
+ const handleOpen = () => {
516
+ setOpen(true);
517
+ };
518
+ return /* @__PURE__ */ jsxs13(TableRow2, { ...props, children: [
519
+ /* @__PURE__ */ jsxs13(TableCell2, { children: [
520
+ "Seed Phrase ",
521
+ /* @__PURE__ */ jsx15(SeedPhraseIconButton, {})
522
+ ] }),
523
+ /* @__PURE__ */ jsx15(TableCell2, { align: "center", children: seedPhrase ? /* @__PURE__ */ jsx15(RadioButtonCheckedIcon, { color: "success" }) : /* @__PURE__ */ jsx15(CancelIcon, { color: "error" }) }),
524
+ /* @__PURE__ */ jsxs13(TableCell2, { children: [
525
+ /* @__PURE__ */ jsx15(SeedPhraseDialog, { changeSeedPhrase, open, onClose: () => setOpen(false), seedPhrase }),
526
+ /* @__PURE__ */ jsx15(ButtonGroup2, { fullWidth: true, children: /* @__PURE__ */ jsx15(Button5, { variant: "contained", size: "small", onClick: handleOpen, children: "Update" }) })
527
+ ] })
528
+ ] });
529
+ };
530
+
531
+ // src/components/WalletAccountDetails/WalletAccountDetails.tsx
532
+ import { EthAddress } from "@xylabs/eth-address";
533
+ import { EthAccountButton } from "@xylabs/react-crypto";
534
+ import { FlexCol, FlexRow as FlexRow3 } from "@xylabs/react-flexbox";
535
+ import { NumberStatus } from "@xylabs/react-number-status";
536
+ import { useNetwork } from "@xyo-network/react-network";
537
+
538
+ // src/hooks/useAccount.ts
539
+ import { usePromise as usePromise3 } from "@xylabs/react-promise";
540
+ import { useState as useState8 } from "react";
541
+ var useAccount = ({ wallet, account, index, required = false } = {}) => {
542
+ const walletContextProvided = useWalletProvided();
543
+ const [validationError, setValidationError] = useState8();
544
+ if (wallet && account && !validationError) {
545
+ setValidationError(new Error("useAccount can not have both a wallet and an account in the parameters"));
546
+ }
547
+ if (index && account && !validationError) {
548
+ setValidationError(new Error("useAccount can not have both a index and an account in the parameters"));
549
+ }
550
+ const [error, setError] = useState8();
551
+ const [rootWallet] = useRootWallet(!wallet && required);
552
+ const { activeAccountIndex } = useWalletContext(false);
553
+ const [activeAccount] = usePromise3(async () => {
554
+ try {
555
+ if (!validationError) {
556
+ if (wallet) {
557
+ return await wallet?.derivePath?.(`${index ?? 0}'\0`);
558
+ } else if (rootWallet) {
559
+ return await rootWallet?.derivePath?.(`${index ?? activeAccountIndex ?? 0}'\0`);
560
+ }
561
+ }
562
+ } catch (ex) {
563
+ const error2 = ex;
564
+ console.error(error2.message);
565
+ setError(error2);
566
+ }
567
+ }, [index, wallet, rootWallet, activeAccountIndex, validationError]);
568
+ if (validationError && !error) {
569
+ console.error(validationError.message);
570
+ setError(validationError);
571
+ }
572
+ return [
573
+ error ? void 0 : account ?? activeAccount ?? walletContextProvided ? null : void 0,
574
+ error
575
+ ];
576
+ };
577
+
578
+ // src/hooks/useWallet.ts
579
+ import { usePromise as usePromise4 } from "@xylabs/react-promise";
580
+ import { HDWallet } from "@xyo-network/account";
581
+ import { useState as useState9 } from "react";
582
+ var useWallet = ({ mnemonic, wallet, path, required = false, seed } = {}) => {
583
+ const walletContextProvided = useWalletContext(false);
584
+ const [error, setError] = useState9();
585
+ const [contextAccount] = useSelectedWalletAccount(!wallet && required);
586
+ const [activeAccount] = usePromise4(async () => {
587
+ try {
588
+ const newAccount = await (() => {
589
+ if (wallet) {
590
+ return wallet;
591
+ } else if (mnemonic) {
592
+ return HDWallet.fromPhrase(mnemonic);
593
+ } else if (seed) {
594
+ return HDWallet.fromSeed(seed);
595
+ }
596
+ return contextAccount;
597
+ })();
598
+ return path ? newAccount?.derivePath?.(path) : newAccount ?? wallet;
599
+ } catch (ex) {
600
+ setError(ex);
601
+ }
602
+ }, [mnemonic, contextAccount, seed, path, wallet]);
603
+ return [activeAccount ?? (walletContextProvided ? null : activeAccount), error];
604
+ };
605
+
606
+ // src/hooks/useWallets.ts
607
+ import { usePromise as usePromise5 } from "@xylabs/react-promise";
608
+ var useWallets = ({ wallet, paths }) => {
609
+ const walletContextProvided = useWalletContext(false);
610
+ const [foundWallet] = useWallet({ wallet });
611
+ const [wallets, error] = usePromise5(
612
+ async () => foundWallet ? await Promise.all(paths.map((path) => foundWallet.derivePath(path))) : void 0,
613
+ [foundWallet, paths]
614
+ );
615
+ return [wallets ?? (walletContextProvided ? null : wallets), error];
616
+ };
617
+
618
+ // src/hooks/useWrapperAccount.ts
619
+ import { usePromise as usePromise6 } from "@xylabs/react-promise";
620
+ import { HDWallet as HDWallet2 } from "@xyo-network/account";
621
+ import { Mutex } from "async-mutex";
622
+ var globalWrapperWallet;
623
+ var globalWrapperWalletMutex = new Mutex();
624
+ var useWrapperAccount = (account) => {
625
+ return usePromise6(async () => {
626
+ return await globalWrapperWalletMutex.runExclusive(async () => {
627
+ if (account !== void 0) {
628
+ return account;
629
+ }
630
+ if (globalWrapperWallet) {
631
+ return globalWrapperWallet;
632
+ }
633
+ try {
634
+ globalWrapperWallet = await HDWallet2.random();
635
+ console.log(`Global Wrapper Wallet Creation Success: ${globalWrapperWallet.address}`);
636
+ } catch (ex) {
637
+ const error = ex;
638
+ console.error(`Global Wrapper Wallet Creation Failed: ${error.message}`);
639
+ }
640
+ return globalWrapperWallet;
641
+ });
642
+ }, [account]);
643
+ };
644
+
645
+ // src/components/WalletAccountDetails/WalletAccountDetails.tsx
646
+ import { jsx as jsx16, jsxs as jsxs14 } from "react/jsx-runtime";
647
+ var WalletAccountDetails = ({ exploreUrl = "https://explore.xyo.network", account, ...props }) => {
648
+ const [accountToUse] = useAccount({ account });
649
+ const { network } = useNetwork();
650
+ const exploreAddressUrl = `${exploreUrl}/recent?account=${accountToUse?.address}&network=${network?.name ?? "main"}`;
651
+ return /* @__PURE__ */ jsxs14(FlexCol, { ...props, children: [
652
+ /* @__PURE__ */ jsx16(EthAccountButton, { address: EthAddress.fromString(accountToUse?.address) }),
653
+ /* @__PURE__ */ jsxs14(FlexRow3, { gap: 1, children: [
654
+ /* @__PURE__ */ jsx16(NumberStatus, { rounded: true, title: "Tokens", value: 0, to: `${exploreAddressUrl}&schema=network.xyo.account.tokens`, target: "_blank" }),
655
+ /* @__PURE__ */ jsx16(NumberStatus, { rounded: true, title: "NFTs", value: 0, to: `${exploreAddressUrl}&schema=network.xyo.account.nfts`, target: "_blank" }),
656
+ /* @__PURE__ */ jsx16(NumberStatus, { rounded: true, title: "Signatures", value: 0, to: `${exploreAddressUrl}&schema=network.xyo.account.signatures`, target: "_blank" }),
657
+ /* @__PURE__ */ jsx16(NumberStatus, { rounded: true, title: "Signins", value: 0, to: `${exploreAddressUrl}&schema=network.xyo.account.signins`, target: "_blank" })
658
+ ] })
659
+ ] });
660
+ };
661
+
662
+ // src/components/WalletAccountSelect/Select.tsx
663
+ import { CircularProgress, MenuItem } from "@mui/material";
664
+ import { SelectEx } from "@xylabs/react-select";
665
+ import { AddressRenderRowBox } from "@xyo-network/react-address-render";
666
+ import { Fragment as Fragment5, jsx as jsx17 } from "react/jsx-runtime";
667
+ var arrayRange = (length, start = 0) => {
668
+ return [...Array.from({ length }).keys()].map((x) => x + start);
669
+ };
670
+ var WalletAccountSelect = ({
671
+ addressNames = {},
672
+ iconOnly,
673
+ iconSize = 24,
674
+ icons,
675
+ maxAccounts = 1,
676
+ showFavorite = false,
677
+ size,
678
+ variant = "outlined",
679
+ ...props
680
+ }) => {
681
+ const { activeAccountIndex = 0, setActiveAccountIndex, rootWallet } = useWalletContext();
682
+ const disabled = !rootWallet || activeAccountIndex === void 0;
683
+ return /* @__PURE__ */ jsx17(Fragment5, { children: rootWallet ? /* @__PURE__ */ jsx17(
684
+ SelectEx,
685
+ {
686
+ margin: "dense",
687
+ disabled,
688
+ renderValue: (selectedAccountIndex) => {
689
+ const Item = () => {
690
+ const [selectedAccount] = useWallet({ path: selectedAccountIndex.toString(), wallet: rootWallet });
691
+ const customName = selectedAccount ? addressNames[selectedAccount.address] : void 0;
692
+ const favorite = !!selectedAccount && selectedAccount.address in addressNames;
693
+ return /* @__PURE__ */ jsx17(MenuItem, { value: selectedAccountIndex, sx: { minHeight: 0, paddingBottom: 0, paddingTop: 0 }, children: /* @__PURE__ */ jsx17(
694
+ AddressRenderRowBox,
695
+ {
696
+ disableSharedRef: true,
697
+ flexGrow: 1,
698
+ address: selectedAccount?.address,
699
+ iconOnly,
700
+ iconSize,
701
+ icons,
702
+ name: customName,
703
+ favorite,
704
+ showFavorite
705
+ }
706
+ ) });
707
+ };
708
+ return /* @__PURE__ */ jsx17(Item, {});
709
+ },
710
+ value: activeAccountIndex,
711
+ onChange: (event) => setActiveAccountIndex?.(Number.parseInt(`${event.target.value}`)),
712
+ size,
713
+ variant,
714
+ ...props,
715
+ children: arrayRange(maxAccounts).map((index) => {
716
+ const Item = () => {
717
+ const [account] = useWallet({ path: index.toString(), wallet: rootWallet });
718
+ const customName = account ? addressNames[account.address] : void 0;
719
+ const favorite = !!account && account.address in addressNames;
720
+ return /* @__PURE__ */ jsx17(MenuItem, { value: index, sx: { minHeight: 0, paddingBottom: 0, paddingTop: 0 }, children: /* @__PURE__ */ jsx17(
721
+ AddressRenderRowBox,
722
+ {
723
+ disableSharedRef: true,
724
+ flexGrow: 1,
725
+ address: account?.address,
726
+ favorite,
727
+ iconOnly,
728
+ iconSize,
729
+ icons,
730
+ name: customName,
731
+ showFavorite
732
+ }
733
+ ) }, account?.address);
734
+ };
735
+ return /* @__PURE__ */ jsx17(Item, {}, index);
736
+ })
737
+ }
738
+ ) : /* @__PURE__ */ jsx17(CircularProgress, { size: 24 }) });
739
+ };
740
+
741
+ // src/components/WalletAccountSelect/SelectBar.tsx
742
+ import { FlexCol as FlexCol2 } from "@xylabs/react-flexbox";
743
+ import { jsx as jsx18 } from "react/jsx-runtime";
744
+ var WalletAccountSelectBar = ({
745
+ addressNames = {},
746
+ iconOnly,
747
+ iconSize,
748
+ icons,
749
+ maxAccounts = 1,
750
+ showFavorite = false,
751
+ size = "small",
752
+ ...props
753
+ }) => {
754
+ return /* @__PURE__ */ jsx18(FlexCol2, { alignItems: "stretch", ...props, children: /* @__PURE__ */ jsx18(
755
+ WalletAccountSelect,
756
+ {
757
+ addressNames,
758
+ fullWidth: true,
759
+ showFavorite,
760
+ iconSize,
761
+ iconOnly,
762
+ icons,
763
+ maxAccounts,
764
+ size: size ?? "small",
765
+ variant: "outlined"
766
+ }
767
+ ) });
768
+ };
769
+ export {
770
+ DefaultSeedPhrase,
771
+ DialogActionButtons,
772
+ InvalidPhraseTypography,
773
+ MaxAccountsTableRow,
774
+ NewPhraseTextField,
775
+ OverwriteWarning,
776
+ PhraseDialogActions,
777
+ PhraseHeaderBox,
778
+ SavedPhraseTextField,
779
+ SeedPhraseContext,
780
+ SeedPhraseDialog,
781
+ SeedPhraseDialogInner,
782
+ SeedPhraseIconButton,
783
+ SeedPhraseProvider,
784
+ SeedPhraseTableRow,
785
+ WalletAccountDetails,
786
+ WalletAccountSelect,
787
+ WalletAccountSelectBar,
788
+ WalletContext,
789
+ WalletProvider,
790
+ colorParser,
791
+ useAccount,
792
+ useIndexedWalletFromContext,
793
+ useRootWallet,
794
+ useSeedPhrase,
795
+ useSelectedWalletAccount,
796
+ useWallet,
797
+ useWalletContext,
798
+ useWalletProvided,
799
+ useWallets,
800
+ useWrapperAccount
801
+ };
2
802
  //# sourceMappingURL=index.js.map