payment-kit 1.17.5 → 1.17.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.
@@ -423,9 +423,16 @@ export default flat({
423
423
  },
424
424
  paymentCurrency: {
425
425
  name: 'Payment Currency',
426
- add: 'Add payment currency',
426
+ add: 'Add Currency',
427
+ edit: 'Edit Currency',
427
428
  save: 'Save payment currency',
428
429
  saved: 'Payment currency successfully saved',
430
+ delete: 'Delete payment currency',
431
+ deleteConfirm: 'Are you sure you want to delete this payment currency? Once deleted, it cannot be recovered',
432
+ deleted: 'Payment currency successfully deleted',
433
+ quickAdd: 'Quick add supported currency',
434
+ searchToken: 'Search currency',
435
+ orManualInput: 'Or manually fill in currency information below',
429
436
  logo: {
430
437
  label: 'Logo',
431
438
  tip: 'Displayed on payment page',
@@ -413,8 +413,15 @@ export default flat({
413
413
  paymentCurrency: {
414
414
  name: '支付货币',
415
415
  add: '添加货币',
416
+ edit: '编辑货币',
416
417
  save: '保存货币',
417
418
  saved: '货币已成功保存',
419
+ delete: '删除货币',
420
+ deleteConfirm: '确定要删除此货币吗?一旦删除,将无法恢复',
421
+ deleted: '货币已成功删除',
422
+ quickAdd: '快速添加已支持的货币',
423
+ searchToken: '搜索货币',
424
+ orManualInput: '或在下方手动填写货币信息',
418
425
  logo: {
419
426
  label: 'Logo',
420
427
  tip: '在支付页面显示',
@@ -1,6 +1,6 @@
1
1
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
2
- import { Switch, api, formatError, usePaymentContext } from '@blocklet/payment-react';
3
- import type { TPaymentMethodExpanded } from '@blocklet/payment-types';
2
+ import { ConfirmDialog, Switch, api, formatError, usePaymentContext } from '@blocklet/payment-react';
3
+ import type { TPaymentCurrency, TPaymentMethodExpanded } from '@blocklet/payment-types';
4
4
  import {
5
5
  AddOutlined,
6
6
  Check,
@@ -36,6 +36,7 @@ import IconCollapse from '../../../../components/collapse';
36
36
  import InfoCard from '../../../../components/info-card';
37
37
  import InfoRow from '../../../../components/info-row';
38
38
  import PaymentCurrencyAdd from '../../../../components/payment-currency/add';
39
+ import PaymentCurrencyEdit from '../../../../components/payment-currency/edit';
39
40
 
40
41
  const getMethods = (
41
42
  params: Record<string, any> = {}
@@ -154,9 +155,9 @@ export default function PaymentMethods() {
154
155
  addresses: true,
155
156
  })
156
157
  );
157
- const [state, setState] = useSetState({ method: '' });
158
158
  const [didDialog, setDidDialog] = useSetState({ open: false, chainId: '', did: '' });
159
159
  const { refresh } = usePaymentContext();
160
+ const [currencyDialog, setCurrencyDialog] = useSetState({ action: '', value: null, method: '' });
160
161
 
161
162
  const { list: methods, addresses } = data;
162
163
  useBus(
@@ -170,7 +171,19 @@ export default function PaymentMethods() {
170
171
  useBus(
171
172
  'paymentCurrency.added',
172
173
  () => {
173
- runAsync().then(() => setState({ method: '' }));
174
+ runAsync().then(() => {
175
+ setCurrencyDialog({ action: '', method: '' });
176
+ });
177
+ refresh(true);
178
+ },
179
+ []
180
+ );
181
+ useBus(
182
+ 'paymentCurrency.updated',
183
+ () => {
184
+ runAsync().then(() => {
185
+ setCurrencyDialog({ action: '', method: '' });
186
+ });
174
187
  refresh(true);
175
188
  },
176
189
  []
@@ -192,6 +205,21 @@ export default function PaymentMethods() {
192
205
  }
193
206
  return addresses?.arcblock || '';
194
207
  };
208
+
209
+ const handleDeleteCurrency = async (currency: TPaymentCurrency) => {
210
+ try {
211
+ await api.delete(`/api/payment-currencies/${currency.id}`);
212
+ runAsync();
213
+ refresh(true);
214
+ Toast.success(t('admin.paymentCurrency.deleted'));
215
+ } catch (err) {
216
+ Toast.error(formatError(err));
217
+ } finally {
218
+ // @ts-ignore
219
+ setCurrencyDialog({ action: '', method: '' });
220
+ }
221
+ };
222
+
195
223
  return (
196
224
  <>
197
225
  {Object.keys(groups).map((x) => (
@@ -269,14 +297,38 @@ export default function PaymentMethods() {
269
297
  value={
270
298
  <List>
271
299
  {method.payment_currencies.map((currency) => {
300
+ if (!currency) {
301
+ return null;
302
+ }
272
303
  return (
273
304
  <ListItem
274
305
  key={currency.id}
275
306
  disablePadding
276
307
  secondaryAction={
277
- <IconButton edge="end" disabled>
278
- <DeleteOutlined />
279
- </IconButton>
308
+ currency.locked || method.default_currency_id === currency.id ? null : (
309
+ <>
310
+ <IconButton
311
+ edge="end"
312
+ onClick={() => {
313
+ setCurrencyDialog({
314
+ action: 'edit',
315
+ // @ts-ignore
316
+ value: currency,
317
+ method: method.id,
318
+ });
319
+ }}>
320
+ <EditOutlined />
321
+ </IconButton>
322
+ <IconButton
323
+ edge="end"
324
+ onClick={() => {
325
+ // @ts-ignore
326
+ setCurrencyDialog({ action: 'delete', value: currency, method: method.id });
327
+ }}>
328
+ <DeleteOutlined />
329
+ </IconButton>
330
+ </>
331
+ )
280
332
  }>
281
333
  <ListItemAvatar>
282
334
  <Avatar src={currency.logo} alt={currency.name} />
@@ -290,17 +342,37 @@ export default function PaymentMethods() {
290
342
  key="add-currency"
291
343
  disablePadding
292
344
  sx={{ cursor: 'pointer' }}
293
- onClick={() => setState({ method: method.id })}>
345
+ onClick={() => {
346
+ setCurrencyDialog({ action: 'create', method: method.id });
347
+ }}>
294
348
  <ListItemAvatar>
295
349
  <Avatar>
296
350
  <AddOutlined fontSize="small" />
297
351
  </Avatar>
298
352
  </ListItemAvatar>
299
- <ListItemText primary="Add Currency" />
353
+ <ListItemText primary={t('admin.paymentCurrency.add')} />
300
354
  </ListItem>
301
355
  )}
302
- {state.method === method.id && (
303
- <PaymentCurrencyAdd method={method} onClose={() => setState({ method: '' })} />
356
+ {currencyDialog.method === method.id && currencyDialog.action === 'create' && (
357
+ <PaymentCurrencyAdd
358
+ method={method}
359
+ onClose={() => setCurrencyDialog({ action: '', method: '' })}
360
+ />
361
+ )}
362
+ {currencyDialog.method === method.id && currencyDialog.action === 'edit' && (
363
+ <PaymentCurrencyEdit
364
+ method={method}
365
+ onClose={() => setCurrencyDialog({ action: '', method: '' })}
366
+ value={currencyDialog.value!}
367
+ />
368
+ )}
369
+ {currencyDialog.method === method.id && currencyDialog.action === 'delete' && (
370
+ <ConfirmDialog
371
+ onConfirm={() => handleDeleteCurrency(currencyDialog.value!)}
372
+ onCancel={() => setCurrencyDialog({ action: '', method: '' })}
373
+ title={t('admin.paymentCurrency.delete')}
374
+ message={t('admin.paymentCurrency.deleteConfirm')}
375
+ />
304
376
  )}
305
377
  </List>
306
378
  }