@rango-dev/ui 0.1.16-next.2 → 0.1.16-next.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/ui",
3
- "version": "0.1.16-next.2",
3
+ "version": "0.1.16-next.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
@@ -57,7 +57,7 @@
57
57
  "@radix-ui/react-radio-group": "^1.1.1",
58
58
  "@radix-ui/react-switch": "^1.0.1",
59
59
  "@radix-ui/react-tooltip": "^1.0.2",
60
- "@rango-dev/wallets-shared": "^0.1.15-next.1",
60
+ "@rango-dev/wallets-shared": "^0.1.15-next.2",
61
61
  "@stitches/react": "^1.2.8",
62
62
  "@types/react-color": "^3.0.6",
63
63
  "rango-sdk": "^0.1.27",
@@ -77,12 +77,9 @@ export interface PropTypes {
77
77
  onChange: (w: SelectableWallet) => void;
78
78
  }
79
79
 
80
- export function SelectableWalletList({
81
- list,
82
- onChange,
83
- }: PropsWithChildren<PropTypes>) {
80
+ export function SelectableWalletList({ list, onChange }: PropsWithChildren<PropTypes>) {
84
81
  const [active, setActive] = useState<string>(
85
- list.find((item) => item.selected)?.walletType || ''
82
+ list.find((item) => item.selected)?.walletType || '',
86
83
  );
87
84
  const onClick = (w: SelectableWallet) => {
88
85
  setActive(w.walletType);
@@ -98,19 +95,11 @@ export function SelectableWalletList({
98
95
  {list.map((w, index) => {
99
96
  const checked = active === w.walletType;
100
97
  return (
101
- <Container
102
- checked={checked}
103
- onClick={onClick.bind(null, w)}
104
- key={index}
105
- >
98
+ <Container checked={checked} onClick={onClick.bind(null, w)} key={index}>
106
99
  <Image src={w.image} alt={w.walletType} size={24} />
107
100
  <Typography variant="body2">{w.name}</Typography>
108
- <Typography variant="caption">
109
- {getConciseAddress(w.address)}
110
- </Typography>
111
- <Circle checked={checked}>
112
- <SolidCircle checked={checked} />
113
- </Circle>
101
+ <Typography variant="caption">{getConciseAddress(w.address)}</Typography>
102
+ <Circle checked={checked}>{checked && <SolidCircle checked={checked} />}</Circle>
114
103
  </Container>
115
104
  );
116
105
  })}
@@ -1,5 +1,5 @@
1
1
  import React, { PropsWithChildren, ReactNode } from 'react';
2
- import { Alert, Divider } from '../../components';
2
+ import { Alert, Checkbox, Divider, TextField } from '../../components';
3
3
  import { Button } from '../../components/Button';
4
4
  import { SecondaryPage } from '../../components/SecondaryPage/SecondaryPage';
5
5
  import { SelectableWalletList } from '../../components/SelectableWalletList';
@@ -72,6 +72,13 @@ export interface PropTypes {
72
72
  errors?: Message[];
73
73
  warnings?: Message[];
74
74
  extraMessages?: ReactNode;
75
+ customDestination?: string;
76
+ checkedDestination: boolean;
77
+ setDestinationChain: (chain: string) => void;
78
+ setCustomDestination: (customDestination: string) => void;
79
+ customDestinationEnabled?: boolean;
80
+ isValidCustomDestination: (blockchain: string, address: string) => boolean;
81
+ isWalletRequired?: boolean;
75
82
  }
76
83
  export function ConfirmSwap(props: PropsWithChildren<PropTypes>) {
77
84
  const {
@@ -88,8 +95,14 @@ export function ConfirmSwap(props: PropsWithChildren<PropTypes>) {
88
95
  errors,
89
96
  warnings,
90
97
  extraMessages,
98
+ customDestination,
99
+ setCustomDestination,
100
+ checkedDestination,
101
+ setDestinationChain,
102
+ customDestinationEnabled = true,
103
+ isValidCustomDestination,
104
+ isWalletRequired,
91
105
  } = props;
92
- console.log(props);
93
106
 
94
107
  return (
95
108
  <SecondaryPage
@@ -104,13 +117,18 @@ console.log(props);
104
117
  type="primary"
105
118
  variant="contained"
106
119
  onClick={onConfirm}
107
- disabled={confirmDisabled}
108
- >
120
+ disabled={
121
+ confirmDisabled ||
122
+ (!!customDestination &&
123
+ !isValidCustomDestination(
124
+ requiredWallets[requiredWallets.length - 1],
125
+ customDestination,
126
+ ))
127
+ }>
109
128
  {confirmButtonTitle}
110
129
  </ConfirmButton>
111
130
  </Footer>
112
- }
113
- >
131
+ }>
114
132
  <MainContainer>
115
133
  <div>
116
134
  {extraMessages || null}
@@ -121,9 +139,7 @@ console.log(props);
121
139
  <Alert
122
140
  type="error"
123
141
  key={index}
124
- {...(typeof error === 'string'
125
- ? { title: error }
126
- : { children: error })}
142
+ {...(typeof error === 'string' ? { title: error } : { children: error })}
127
143
  />
128
144
  </React.Fragment>
129
145
  ))}
@@ -133,9 +149,7 @@ console.log(props);
133
149
  <Alert
134
150
  type="warning"
135
151
  key={index}
136
- {...(typeof warning === 'string'
137
- ? { title: warning }
138
- : { children: warning })}
152
+ {...(typeof warning === 'string' ? { title: warning } : { children: warning })}
139
153
  />
140
154
  </React.Fragment>
141
155
  ))}
@@ -148,7 +162,6 @@ console.log(props);
148
162
  {props.previewRoutes}
149
163
  </Section>
150
164
  ) : null}
151
-
152
165
  {requiredWallets.map((wallet, index) => {
153
166
  const list = selectableWallets.filter((w) => wallet === w.chain);
154
167
  return (
@@ -158,28 +171,73 @@ console.log(props);
158
171
  <Divider size={8} direction="horizontal" />
159
172
  <Typography variant="body2">Your {wallet} Wallet</Typography>
160
173
  </div>
161
- {list.length === 0 && (
174
+ {list.length === 0 &&
175
+ (isWalletRequired || (!isWalletRequired && !checkedDestination)) && (
176
+ <>
177
+ <AlertContainer>
178
+ <Alert type="error">
179
+ You need to connect a compatible wallet with {wallet}.
180
+ </Alert>
181
+ </AlertContainer>
182
+ {isExperimentalChain?.(wallet) && (
183
+ <Button
184
+ variant="contained"
185
+ type="primary"
186
+ align="grow"
187
+ onClick={() => handleConnectChain?.(wallet)}>
188
+ {`Add ${wallet} chain to Cosmos wallets`}
189
+ </Button>
190
+ )}
191
+ </>
192
+ )}
193
+ {list.length != 0 && (
194
+ <SelectableWalletList
195
+ list={list}
196
+ onChange={(w) => {
197
+ onChange(w);
198
+ setDestinationChain('');
199
+ setCustomDestination('');
200
+ }}
201
+ />
202
+ )}
203
+ {index === requiredWallets.length - 1 && customDestinationEnabled && (
162
204
  <>
163
- <AlertContainer>
164
- <Alert type="error">
165
- You need to connect a compatible wallet with {wallet}.
166
- </Alert>
167
- </AlertContainer>
168
- {isExperimentalChain?.(wallet) && (
169
- <Button
170
- variant="contained"
171
- type="primary"
172
- align="grow"
173
- onClick={() => handleConnectChain?.(wallet)}
174
- >
175
- {`Add ${wallet} chain to Cosmos wallets`}
176
- </Button>
205
+ <Divider />
206
+ <Checkbox
207
+ label={`Choose a custom ${wallet} address`}
208
+ checked={checkedDestination}
209
+ onCheckedChange={(checked) => {
210
+ if (!checked) {
211
+ setDestinationChain('');
212
+ setCustomDestination('');
213
+ list.length && onChange(list[0]);
214
+ } else {
215
+ setDestinationChain(wallet);
216
+ }
217
+ }}
218
+ id={'custom_destination'}
219
+ />
220
+ <Divider />
221
+
222
+ {checkedDestination && (
223
+ <>
224
+ <TextField
225
+ placeholder="Your destination address"
226
+ value={customDestination}
227
+ onChange={(e) => {
228
+ setCustomDestination(e.target.value);
229
+ }}
230
+ />
231
+ {!!customDestination &&
232
+ !isValidCustomDestination(wallet, customDestination) && (
233
+ <AlertContainer>
234
+ <Alert type="error">Not a valid {wallet} address.</Alert>
235
+ </AlertContainer>
236
+ )}
237
+ </>
177
238
  )}
178
239
  </>
179
240
  )}
180
- {list.length != 0 && (
181
- <SelectableWalletList list={list} onChange={onChange} />
182
- )}
183
241
  </Container>
184
242
  );
185
243
  })}