@blocklet/payment-react 1.18.33 → 1.18.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,7 +40,7 @@ function OverdueInvoicePayment({
40
40
  alertMessage = "",
41
41
  authToken
42
42
  }) {
43
- const { t } = useLocaleContext();
43
+ const { t, locale } = useLocaleContext();
44
44
  const { connect, session } = usePaymentContext();
45
45
  const [selectCurrencyId, setSelectCurrencyId] = useState("");
46
46
  const [payLoading, setPayLoading] = useState(false);
@@ -170,12 +170,18 @@ function OverdueInvoicePayment({
170
170
  extraParams.customerId = effectiveCustomerId;
171
171
  }
172
172
  connect.open({
173
+ locale,
173
174
  containerEl: void 0,
174
175
  saveConnect: false,
175
176
  action: "collect-batch",
176
177
  prefix: joinURL(getPrefix(), "/api/did"),
177
178
  useSocket: !isCrossOriginRequest,
178
179
  extraParams,
180
+ messages: {
181
+ scan: t("common.connect.defaultScan"),
182
+ title: t("payment.customer.invoice.payBatch"),
183
+ confirm: t("common.connect.confirm")
184
+ },
179
185
  onSuccess: () => {
180
186
  connect.close();
181
187
  handleConnected();
@@ -469,7 +469,7 @@ const InvoiceList = React.memo((props) => {
469
469
  });
470
470
  export default function CustomerInvoiceList(props) {
471
471
  const { action, type } = props;
472
- const { t } = useLocaleContext();
472
+ const { t, locale } = useLocaleContext();
473
473
  const { connect } = usePaymentContext();
474
474
  const [state, setState] = useSetState({ paying: "" });
475
475
  const onPay = (invoiceId) => {
@@ -480,6 +480,7 @@ export default function CustomerInvoiceList(props) {
480
480
  connect.open({
481
481
  action: "collect",
482
482
  saveConnect: false,
483
+ locale,
483
484
  useSocket: isCrossOrigin() === false,
484
485
  messages: {
485
486
  scan: "",
package/es/libs/util.d.ts CHANGED
@@ -120,3 +120,4 @@ export declare function parseMarkedText(text: string): Array<{
120
120
  type: 'text' | 'marked';
121
121
  content: string;
122
122
  }>;
123
+ export declare function getTokenBalanceLink(method: TPaymentMethod, address: string): string;
package/es/libs/util.js CHANGED
@@ -979,3 +979,16 @@ export function parseMarkedText(text) {
979
979
  }
980
980
  return result.filter((p) => p.content !== "");
981
981
  }
982
+ export function getTokenBalanceLink(method, address) {
983
+ if (!method || !address) {
984
+ return "";
985
+ }
986
+ const explorerHost = method?.settings?.[method?.type]?.explorer_host || "";
987
+ if (method.type === "arcblock" && address) {
988
+ return joinURL(explorerHost, "accounts", address, "tokens");
989
+ }
990
+ if (["ethereum", "base"].includes(method.type) && address) {
991
+ return joinURL(explorerHost, "address", address);
992
+ }
993
+ return "";
994
+ }
@@ -1 +1,2 @@
1
1
  export declare function validatePostalCode(postalCode: string, country?: string): boolean;
2
+ export declare function getFieldValidation(fieldName: string, validations?: Record<string, any>, locale?: string): Record<string, any>;
@@ -1,4 +1,5 @@
1
1
  import isPostalCode from "validator/lib/isPostalCode";
2
+ import { t } from "../locales/index.js";
2
3
  const POSTAL_CODE_SUPPORTED_COUNTRIES = [
3
4
  "AD",
4
5
  "AT",
@@ -68,3 +69,16 @@ export function validatePostalCode(postalCode, country) {
68
69
  return false;
69
70
  }
70
71
  }
72
+ export function getFieldValidation(fieldName, validations, locale = "en") {
73
+ if (!validations || !validations[fieldName])
74
+ return {};
75
+ const fieldValidation = validations[fieldName];
76
+ const rules = {};
77
+ if (fieldValidation.pattern) {
78
+ rules.pattern = {
79
+ value: new RegExp(fieldValidation.pattern),
80
+ message: fieldValidation.pattern_message?.[locale] || t("payment.checkout.invalid", locale)
81
+ };
82
+ }
83
+ return rules;
84
+ }
package/es/locales/en.js CHANGED
@@ -94,7 +94,13 @@ export default flat({
94
94
  stakeAmount: "Stake Amount",
95
95
  slashStakeAmount: "Slash Stake Amount",
96
96
  know: "I know",
97
- relatedSubscription: "Subscription"
97
+ relatedSubscription: "Subscription",
98
+ connect: {
99
+ defaultScan: "Use following methods to complete this action",
100
+ scan: "Use following methods to complete this {action}",
101
+ confirm: "Confirm",
102
+ cancel: "Cancel"
103
+ }
98
104
  },
99
105
  payment: {
100
106
  checkout: {
@@ -166,7 +172,10 @@ export default flat({
166
172
  donate: "Thanks for your tip",
167
173
  tip: "A payment to {payee} has been completed. You can view the details of this payment in your account."
168
174
  },
169
- confirm: "Confirming allows {payee} to charge or reduce your staking. You can cancel or revoke staking anytime.",
175
+ confirm: {
176
+ withStake: "By confirming, you allow {payee} to charge your account for future payments and, if necessary, slash your stake. You can cancel your subscription or withdraw your stake at any time.",
177
+ withoutStake: "By confirming, you allow {payee} to charge your account for future payments. You can cancel your subscription at any time."
178
+ },
170
179
  required: "Required",
171
180
  invalid: "Invalid",
172
181
  billing: {
@@ -209,7 +218,23 @@ export default flat({
209
218
  },
210
219
  orderSummary: "Order Summary",
211
220
  paymentDetails: "Payment Details",
212
- productListTotal: "Includes {total} items"
221
+ productListTotal: "Includes {total} items",
222
+ connectModal: {
223
+ title: "{action}",
224
+ scan: "Use following methods to complete this payment",
225
+ confirm: "Confirm",
226
+ cancel: "Cancel"
227
+ },
228
+ fastPay: {
229
+ title: "Confirm Payment",
230
+ confirmMessage: "You will pay {amount} {symbol} from {sourceType}.",
231
+ autoPaymentReason: "This payment will be processed automatically due to prior delegation or sufficient balance.",
232
+ confirmPrompt: "Please confirm the details before proceeding.",
233
+ payer: "Account",
234
+ amount: "Amount",
235
+ failed: "Account changed, please pay manually.",
236
+ balanceLink: "View Balance"
237
+ }
213
238
  },
214
239
  customer: {
215
240
  payments: "Payment History",
@@ -275,7 +300,8 @@ export default flat({
275
300
  select: "Select payment method",
276
301
  submit: "Confirm change",
277
302
  confirm: "By confirming this change, you allow {payee} to charge {symbol} from your account for future payments in accordance with their terms. You can always change your payment method.",
278
- completed: "Your payment method has been successfully updated, all future payments will use the new payment method unless you change it again."
303
+ completed: "Your payment method has been successfully updated, all future payments will use the new payment method unless you change it again.",
304
+ title: "Payment Method Change"
279
305
  },
280
306
  invoice: {
281
307
  summary: "Summary",
@@ -296,7 +322,8 @@ export default flat({
296
322
  next: "No invoices yet, next invoice will be generated on {date}",
297
323
  invoiceNumber: "Invoice Number",
298
324
  emptyList: "No Invoice",
299
- noPaymentRequired: "No Payment Required"
325
+ noPaymentRequired: "No Payment Required",
326
+ payBatch: "Pay Due Invoices"
300
327
  },
301
328
  payment: {
302
329
  empty: "There are no payments",
package/es/locales/zh.js CHANGED
@@ -94,7 +94,13 @@ export default flat({
94
94
  stakeAmount: "\u8D28\u62BC\u91D1\u989D",
95
95
  slashStakeAmount: "\u7F5A\u6CA1\u91D1\u989D",
96
96
  know: "\u6211\u77E5\u9053\u4E86",
97
- relatedSubscription: "\u8BA2\u9605"
97
+ relatedSubscription: "\u8BA2\u9605",
98
+ connect: {
99
+ defaultScan: "\u4F7F\u7528\u4EE5\u4E0B\u65B9\u5F0F\u5B8C\u6210\u672C\u6B21\u64CD\u4F5C",
100
+ scan: "\u4F7F\u7528\u4EE5\u4E0B\u65B9\u5F0F\u5B8C\u6210\u672C\u6B21{action}",
101
+ confirm: "\u786E\u8BA4",
102
+ cancel: "\u53D6\u6D88"
103
+ }
98
104
  },
99
105
  payment: {
100
106
  checkout: {
@@ -166,7 +172,10 @@ export default flat({
166
172
  donate: "\u611F\u8C22\u60A8\u7684\u652F\u6301",
167
173
  tip: "\u5411{payee}\u7684\u4ED8\u6B3E\u5DF2\u5B8C\u6210\u3002\u60A8\u53EF\u4EE5\u5728\u60A8\u7684\u8D26\u6237\u4E2D\u67E5\u770B\u6B64\u4ED8\u6B3E\u7684\u8BE6\u7EC6\u4FE1\u606F\u3002"
168
174
  },
169
- confirm: "\u786E\u8BA4\u5141\u8BB8{payee}\u5BF9\u60A8\u7684\u8D26\u6237\u8FDB\u884C\u4ED8\u6B3E\u6216\u8005\u7F5A\u6CA1\u60A8\u7684\u8D28\u62BC\u3002\u60A8\u968F\u65F6\u53EF\u4EE5\u53D6\u6D88\u60A8\u7684\u8BA2\u9605\uFF0C\u6216\u8005\u64A4\u9500\u8D28\u62BC\u3002",
175
+ confirm: {
176
+ withStake: "\u786E\u8BA4\u8BA2\u9605\uFF0C\u5373\u8868\u793A\u60A8\u6388\u6743 {payee} \u4ECE\u60A8\u7684\u8D26\u6237\u6263\u53D6\u672A\u6765\u6B3E\u9879\uFF0C\u5E76\u5728\u5FC5\u8981\u65F6\u7F5A\u6CA1\u8D28\u62BC\u3002\u60A8\u53EF\u968F\u65F6\u53D6\u6D88\u8BA2\u9605\u6216\u64A4\u9500\u8D28\u62BC\u3002",
177
+ withoutStake: "\u786E\u8BA4\u8BA2\u9605\uFF0C\u5373\u8868\u793A\u60A8\u6388\u6743 {payee} \u4ECE\u60A8\u7684\u8D26\u6237\u6263\u53D6\u672A\u6765\u6B3E\u9879\u3002\u60A8\u53EF\u968F\u65F6\u53D6\u6D88\u8BA2\u9605\u3002"
178
+ },
170
179
  required: "\u5FC5\u586B\u9879",
171
180
  invalid: "\u65E0\u6548",
172
181
  billing: {
@@ -209,7 +218,23 @@ export default flat({
209
218
  },
210
219
  orderSummary: "\u8BA2\u5355\u6982\u89C8",
211
220
  paymentDetails: "\u652F\u4ED8\u4FE1\u606F",
212
- productListTotal: "\u5305\u62EC {total} \u9879"
221
+ productListTotal: "\u5305\u62EC {total} \u9879",
222
+ connectModal: {
223
+ title: "{action}",
224
+ scan: "\u4F7F\u7528\u4EE5\u4E0B\u65B9\u5F0F\u5B8C\u6210\u672C\u6B21\u652F\u4ED8",
225
+ confirm: "\u786E\u8BA4",
226
+ cancel: "\u53D6\u6D88"
227
+ },
228
+ fastPay: {
229
+ title: "\u786E\u8BA4\u652F\u4ED8",
230
+ confirmMessage: "\u60A8\u5C06\u652F\u4ED8 {amount} {symbol}\uFF0C\u4ECE{sourceType}\u6263\u9664\u3002",
231
+ autoPaymentReason: "\u7531\u4E8E\u6388\u6743\u6216\u4F59\u989D\u5145\u8DB3\uFF0C\u7CFB\u7EDF\u5C06\u65E0\u9700\u94B1\u5305\u786E\u8BA4\u81EA\u52A8\u5B8C\u6210\u652F\u4ED8\u3002",
232
+ confirmPrompt: "\u8BF7\u786E\u8BA4\u652F\u4ED8\u4FE1\u606F\u65E0\u8BEF\u540E\u7EE7\u7EED\u3002",
233
+ payer: "\u8D26\u6237\u5730\u5740",
234
+ amount: "\u652F\u4ED8\u91D1\u989D",
235
+ failed: "\u8D26\u6237\u53D1\u751F\u53D8\u5316\uFF0C\u65E0\u6CD5\u81EA\u52A8\u5B8C\u6210\u652F\u4ED8\uFF0C\u8BF7\u624B\u52A8\u652F\u4ED8\u3002",
236
+ balanceLink: "\u67E5\u770B\u4F59\u989D"
237
+ }
213
238
  },
214
239
  customer: {
215
240
  payments: "\u652F\u4ED8\u5386\u53F2",
@@ -276,7 +301,8 @@ export default flat({
276
301
  select: "\u9009\u62E9\u652F\u4ED8\u65B9\u5F0F",
277
302
  submit: "\u786E\u8BA4\u53D8\u66F4",
278
303
  confirm: "\u786E\u8BA4\u53D8\u66F4\u65B9\u5F0F\u610F\u5473\u7740\u4F60\u5141\u8BB8 {payee} \u4F7F\u7528\u65B0\u7684\u652F\u4ED8\u65B9\u5F0F\u652F\u4ED8\u4F60\u7684\u672A\u6765\u8D26\u5355\u3002\u4F60\u53EF\u4EE5\u968F\u65F6\u518D\u6B21\u53D8\u66F4\u652F\u4ED8\u65B9\u5F0F\u3002",
279
- completed: "\u4F60\u7684\u652F\u4ED8\u65B9\u5F0F \u5DF2\u7ECF\u66F4\u65B0\u6210\u529F\u3002\u4F60\u53EF\u4EE5\u5728\u4F60\u7684\u8D26\u6237\u4E2D\u67E5\u770B\u6B64\u652F\u4ED8\u65B9\u5F0F\u7684\u8BE6\u7EC6\u4FE1\u606F\u3002"
304
+ completed: "\u4F60\u7684\u652F\u4ED8\u65B9\u5F0F \u5DF2\u7ECF\u66F4\u65B0\u6210\u529F\u3002\u4F60\u53EF\u4EE5\u5728\u4F60\u7684\u8D26\u6237\u4E2D\u67E5\u770B\u6B64\u652F\u4ED8\u65B9\u5F0F\u7684\u8BE6\u7EC6\u4FE1\u606F\u3002",
305
+ title: "\u652F\u4ED8\u65B9\u5F0F\u53D8\u66F4"
280
306
  },
281
307
  invoice: {
282
308
  summary: "\u6458\u8981",
@@ -297,7 +323,8 @@ export default flat({
297
323
  next: "\u8FD8\u6CA1\u6709\u8D26\u5355\uFF0C\u4E0B\u6B21\u8D26\u5355\u5C06\u5728 {date} \u751F\u6210",
298
324
  invoiceNumber: "\u8D26\u5355\u7F16\u53F7",
299
325
  emptyList: "\u6CA1\u6709\u8D26\u5355",
300
- noPaymentRequired: "\u65E0\u9700\u652F\u4ED8"
326
+ noPaymentRequired: "\u65E0\u9700\u652F\u4ED8",
327
+ payBatch: "\u652F\u4ED8\u6B20\u6B3E"
301
328
  },
302
329
  payment: {
303
330
  empty: "\u6CA1\u6709\u652F\u4ED8\u8BB0\u5F55",
@@ -3,11 +3,15 @@ type Props = {
3
3
  mode: string;
4
4
  stripe: boolean;
5
5
  sx?: SxProps;
6
+ fieldValidation?: Record<string, any>;
7
+ errorPosition?: 'right' | 'bottom';
6
8
  };
7
- declare function AddressForm({ mode, stripe, sx }: Props): import("react").JSX.Element | null;
9
+ declare function AddressForm({ mode, stripe, sx, fieldValidation, errorPosition }: Props): import("react").JSX.Element | null;
8
10
  declare namespace AddressForm {
9
11
  var defaultProps: {
10
12
  sx: {};
13
+ fieldValidation: {};
14
+ errorPosition: string;
11
15
  };
12
16
  }
13
17
  export default AddressForm;
@@ -4,11 +4,13 @@ import { Fade, FormLabel, InputAdornment, Stack } from "@mui/material";
4
4
  import { Controller, useFormContext, useWatch } from "react-hook-form";
5
5
  import FormInput from "../../components/input.js";
6
6
  import CountrySelect from "../../components/country-select.js";
7
- import { validatePostalCode } from "../../libs/validator.js";
7
+ import { getFieldValidation, validatePostalCode } from "../../libs/validator.js";
8
8
  AddressForm.defaultProps = {
9
- sx: {}
9
+ sx: {},
10
+ fieldValidation: {},
11
+ errorPosition: "right"
10
12
  };
11
- export default function AddressForm({ mode, stripe, sx = {} }) {
13
+ export default function AddressForm({ mode, stripe, sx = {}, fieldValidation, errorPosition }) {
12
14
  const { t } = useLocaleContext();
13
15
  const { control } = useFormContext();
14
16
  const country = useWatch({ control, name: "billing_address.country" });
@@ -19,8 +21,11 @@ export default function AddressForm({ mode, stripe, sx = {} }) {
19
21
  FormInput,
20
22
  {
21
23
  name: "billing_address.line1",
22
- rules: { required: t("payment.checkout.required") },
23
- errorPosition: "right",
24
+ rules: {
25
+ required: t("payment.checkout.required"),
26
+ ...getFieldValidation("billing_address.line1", fieldValidation)
27
+ },
28
+ errorPosition,
24
29
  variant: "outlined",
25
30
  placeholder: t("payment.checkout.billing.line1")
26
31
  }
@@ -30,8 +35,11 @@ export default function AddressForm({ mode, stripe, sx = {} }) {
30
35
  FormInput,
31
36
  {
32
37
  name: "billing_address.city",
33
- rules: { required: t("payment.checkout.required") },
34
- errorPosition: "right",
38
+ rules: {
39
+ required: t("payment.checkout.required"),
40
+ ...getFieldValidation("billing_address.city", fieldValidation)
41
+ },
42
+ errorPosition,
35
43
  variant: "outlined",
36
44
  placeholder: t("payment.checkout.billing.city")
37
45
  }
@@ -41,8 +49,11 @@ export default function AddressForm({ mode, stripe, sx = {} }) {
41
49
  FormInput,
42
50
  {
43
51
  name: "billing_address.state",
44
- rules: { required: t("payment.checkout.required") },
45
- errorPosition: "right",
52
+ rules: {
53
+ required: t("payment.checkout.required"),
54
+ ...getFieldValidation("billing_address.state", fieldValidation)
55
+ },
56
+ errorPosition,
46
57
  variant: "outlined",
47
58
  placeholder: t("payment.checkout.billing.state")
48
59
  }
@@ -57,9 +68,10 @@ export default function AddressForm({ mode, stripe, sx = {} }) {
57
68
  validate: (x) => {
58
69
  const isValid = validatePostalCode(x, country);
59
70
  return isValid ? true : t("payment.checkout.invalid");
60
- }
71
+ },
72
+ ...getFieldValidation("billing_address.postal_code", fieldValidation)
61
73
  },
62
- errorPosition: "right",
74
+ errorPosition,
63
75
  variant: "outlined",
64
76
  placeholder: t("payment.checkout.billing.postal_code"),
65
77
  InputProps: {
@@ -98,9 +110,10 @@ export default function AddressForm({ mode, stripe, sx = {} }) {
98
110
  validate: (x) => {
99
111
  const isValid = validatePostalCode(x, country);
100
112
  return isValid ? true : t("payment.checkout.invalid");
101
- }
113
+ },
114
+ ...getFieldValidation("billing_address.postal_code", fieldValidation)
102
115
  },
103
- errorPosition: "right",
116
+ errorPosition,
104
117
  variant: "outlined",
105
118
  placeholder: t("payment.checkout.billing.postal_code"),
106
119
  wrapperStyle: { height: "40px" },