@blocklet/aigne-hub 0.2.20 → 0.2.22

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.
@@ -13,11 +13,11 @@ const ahooks_1 = require("ahooks");
13
13
  const user_1 = require("../api/user");
14
14
  const util_1 = require("../utils/util");
15
15
  const withLocaleProvider_1 = __importDefault(require("../utils/withLocaleProvider"));
16
- function UserCreditCard({ baseUrl, accessKey, onSuccess = () => { }, onError = () => { }, mode = 'default', render = () => null, }) {
17
- var _a, _b, _c, _d, _e, _f;
16
+ function UserCreditCard({ baseUrl, apiKey, onSuccess = () => { }, onError = () => { }, mode = 'default', render = () => null, chargeBtnProps = {}, manageBtnProps = {}, }) {
17
+ var _a, _b;
18
18
  const { t } = (0, context_1.useLocaleContext)();
19
- const { data: userInfoData, loading } = (0, ahooks_1.useRequest)(() => (0, user_1.getUserInfo)({ baseUrl, accessKey }), {
20
- refreshDeps: [baseUrl, accessKey],
19
+ const { data: userInfoData, loading } = (0, ahooks_1.useRequest)(() => (0, user_1.getUserInfo)({ baseUrl, accessKey: apiKey }), {
20
+ refreshDeps: [baseUrl, apiKey],
21
21
  onError: (err) => {
22
22
  Toast_1.default.error((0, error_1.formatError)(err));
23
23
  onError === null || onError === void 0 ? void 0 : onError(err);
@@ -41,16 +41,16 @@ function UserCreditCard({ baseUrl, accessKey, onSuccess = () => { }, onError = (
41
41
  minWidth: 0,
42
42
  }, avatarProps: {
43
43
  size: 24,
44
- } })] }), (userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.enableCredit) ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", color: "text.secondary", children: t('creditBalance') }), (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "h6", fontWeight: "bold", children: [(0, util_1.formatNumber)(((_a = userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.creditBalance) === null || _a === void 0 ? void 0 : _a.balance) || '0'), " ", (_c = (_b = userInfoData.currency) === null || _b === void 0 ? void 0 : _b.symbol) !== null && _c !== void 0 ? _c : 'AHC'] })] }), ((_d = userInfoData.creditBalance) === null || _d === void 0 ? void 0 : _d.pendingCredit) && Number(userInfoData.creditBalance.pendingCredit) > 0 && ((0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", color: "text.secondary", children: t('pendingCredit') }), (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "h6", fontWeight: "bold", sx: { color: 'error.main' }, children: [(0, util_1.formatNumber)(userInfoData.creditBalance.pendingCredit), " ", (_f = (_e = userInfoData.currency) === null || _e === void 0 ? void 0 : _e.symbol) !== null && _f !== void 0 ? _f : 'AHC'] })] })), (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 1.5, sx: { mt: 1 }, children: [(userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.paymentLink) && ((0, jsx_runtime_1.jsx)(material_1.Button, { variant: "outlined", onClick: () => {
44
+ } })] }), (userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.enableCredit) ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", color: "text.secondary", children: t('creditBalance') }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", fontWeight: "bold", children: (0, util_1.formatNumber)(((_a = userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.creditBalance) === null || _a === void 0 ? void 0 : _a.balance) || '0') })] }), ((_b = userInfoData.creditBalance) === null || _b === void 0 ? void 0 : _b.pendingCredit) && Number(userInfoData.creditBalance.pendingCredit) > 0 && ((0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", color: "text.secondary", children: t('pendingCredit') }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", fontWeight: "bold", sx: { color: 'error.main' }, children: (0, util_1.formatNumber)(userInfoData.creditBalance.pendingCredit) })] })), (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 1.5, sx: { mt: 1 }, className: "user-credit-card-actions", children: [(userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.paymentLink) && ((0, jsx_runtime_1.jsx)(material_1.Button, { variant: "outlined", className: "recharge-button", onClick: () => {
45
45
  window.open((userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.paymentLink) || '', '_blank');
46
46
  }, sx: {
47
47
  flex: 1,
48
- }, children: t('recharge') })), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "text", onClick: () => {
48
+ }, ...chargeBtnProps, children: t('recharge') })), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "text", className: "manage-button", onClick: () => {
49
49
  window.open((userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.profileLink) || '', '_blank');
50
50
  }, sx: {
51
51
  borderColor: 'primary.main',
52
52
  color: 'primary.main',
53
- }, children: t('manage') })] })] })) : ((0, jsx_runtime_1.jsxs)(material_1.Alert, { severity: "info", sx: {
53
+ }, ...manageBtnProps, children: t('manage') })] })] })) : ((0, jsx_runtime_1.jsxs)(material_1.Alert, { severity: "info", sx: {
54
54
  textAlign: 'left',
55
55
  }, children: [t('creditNotEnabled'), (0, jsx_runtime_1.jsx)(material_1.Typography, { sx: {
56
56
  display: 'inline-block',
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./util"), exports);
@@ -8,11 +8,11 @@ import { useRequest } from 'ahooks';
8
8
  import { getUserInfo } from '../api/user';
9
9
  import { formatNumber } from '../utils/util';
10
10
  import withLocaleProvider from '../utils/withLocaleProvider';
11
- function UserCreditCard({ baseUrl, accessKey, onSuccess = () => { }, onError = () => { }, mode = 'default', render = () => null, }) {
12
- var _a, _b, _c, _d, _e, _f;
11
+ function UserCreditCard({ baseUrl, apiKey, onSuccess = () => { }, onError = () => { }, mode = 'default', render = () => null, chargeBtnProps = {}, manageBtnProps = {}, }) {
12
+ var _a, _b;
13
13
  const { t } = useLocaleContext();
14
- const { data: userInfoData, loading } = useRequest(() => getUserInfo({ baseUrl, accessKey }), {
15
- refreshDeps: [baseUrl, accessKey],
14
+ const { data: userInfoData, loading } = useRequest(() => getUserInfo({ baseUrl, accessKey: apiKey }), {
15
+ refreshDeps: [baseUrl, apiKey],
16
16
  onError: (err) => {
17
17
  Toast.error(formatError(err));
18
18
  onError === null || onError === void 0 ? void 0 : onError(err);
@@ -36,16 +36,16 @@ function UserCreditCard({ baseUrl, accessKey, onSuccess = () => { }, onError = (
36
36
  minWidth: 0,
37
37
  }, avatarProps: {
38
38
  size: 24,
39
- } })] }), (userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.enableCredit) ? (_jsxs(_Fragment, { children: [_jsxs(Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", children: [_jsx(Typography, { variant: "body2", color: "text.secondary", children: t('creditBalance') }), _jsxs(Typography, { variant: "h6", fontWeight: "bold", children: [formatNumber(((_a = userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.creditBalance) === null || _a === void 0 ? void 0 : _a.balance) || '0'), " ", (_c = (_b = userInfoData.currency) === null || _b === void 0 ? void 0 : _b.symbol) !== null && _c !== void 0 ? _c : 'AHC'] })] }), ((_d = userInfoData.creditBalance) === null || _d === void 0 ? void 0 : _d.pendingCredit) && Number(userInfoData.creditBalance.pendingCredit) > 0 && (_jsxs(Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", children: [_jsx(Typography, { variant: "body2", color: "text.secondary", children: t('pendingCredit') }), _jsxs(Typography, { variant: "h6", fontWeight: "bold", sx: { color: 'error.main' }, children: [formatNumber(userInfoData.creditBalance.pendingCredit), " ", (_f = (_e = userInfoData.currency) === null || _e === void 0 ? void 0 : _e.symbol) !== null && _f !== void 0 ? _f : 'AHC'] })] })), _jsxs(Stack, { direction: "row", spacing: 1.5, sx: { mt: 1 }, children: [(userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.paymentLink) && (_jsx(Button, { variant: "outlined", onClick: () => {
39
+ } })] }), (userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.enableCredit) ? (_jsxs(_Fragment, { children: [_jsxs(Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", children: [_jsx(Typography, { variant: "body2", color: "text.secondary", children: t('creditBalance') }), _jsx(Typography, { variant: "h6", fontWeight: "bold", children: formatNumber(((_a = userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.creditBalance) === null || _a === void 0 ? void 0 : _a.balance) || '0') })] }), ((_b = userInfoData.creditBalance) === null || _b === void 0 ? void 0 : _b.pendingCredit) && Number(userInfoData.creditBalance.pendingCredit) > 0 && (_jsxs(Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", children: [_jsx(Typography, { variant: "body2", color: "text.secondary", children: t('pendingCredit') }), _jsx(Typography, { variant: "h6", fontWeight: "bold", sx: { color: 'error.main' }, children: formatNumber(userInfoData.creditBalance.pendingCredit) })] })), _jsxs(Stack, { direction: "row", spacing: 1.5, sx: { mt: 1 }, className: "user-credit-card-actions", children: [(userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.paymentLink) && (_jsx(Button, { variant: "outlined", className: "recharge-button", onClick: () => {
40
40
  window.open((userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.paymentLink) || '', '_blank');
41
41
  }, sx: {
42
42
  flex: 1,
43
- }, children: t('recharge') })), _jsx(Button, { variant: "text", onClick: () => {
43
+ }, ...chargeBtnProps, children: t('recharge') })), _jsx(Button, { variant: "text", className: "manage-button", onClick: () => {
44
44
  window.open((userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.profileLink) || '', '_blank');
45
45
  }, sx: {
46
46
  borderColor: 'primary.main',
47
47
  color: 'primary.main',
48
- }, children: t('manage') })] })] })) : (_jsxs(Alert, { severity: "info", sx: {
48
+ }, ...manageBtnProps, children: t('manage') })] })] })) : (_jsxs(Alert, { severity: "info", sx: {
49
49
  textAlign: 'left',
50
50
  }, children: [t('creditNotEnabled'), _jsx(Typography, { sx: {
51
51
  display: 'inline-block',
@@ -0,0 +1 @@
1
+ export * from './util';
@@ -1,11 +1,14 @@
1
+ import { ButtonProps } from '@mui/material';
1
2
  import { UserInfoResult } from '../api/types/user';
2
3
  interface UserCreditCardProps {
3
4
  baseUrl: string;
4
- accessKey: string;
5
+ apiKey: string;
5
6
  onSuccess?: (userInfo: UserInfoResult) => void;
6
7
  onError?: (error: Error) => void;
7
8
  mode?: 'default' | 'custom';
8
9
  render?: (userInfo: UserInfoResult) => React.ReactNode | null;
10
+ chargeBtnProps?: ButtonProps;
11
+ manageBtnProps?: ButtonProps;
9
12
  }
10
13
  declare const _default: import("react").ComponentType<UserCreditCardProps>;
11
14
  export default _default;
@@ -0,0 +1 @@
1
+ export * from './util';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/aigne-hub",
3
- "version": "0.2.20",
3
+ "version": "0.2.22",
4
4
  "description": "The react.js component library for AIGNE Hub",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -76,6 +76,13 @@
76
76
  "components/*": [
77
77
  "./lib/types/components/*.d.ts",
78
78
  "./lib/types/components/*/index.d.ts"
79
+ ],
80
+ "utils": [
81
+ "./lib/types/utils/index.d.ts"
82
+ ],
83
+ "utils/*": [
84
+ "./lib/types/utils/*.d.ts",
85
+ "./lib/types/utils/index.d.ts"
79
86
  ]
80
87
  }
81
88
  },
@@ -94,10 +101,10 @@
94
101
  },
95
102
  "dependencies": {
96
103
  "@arcblock/did": "^1.21.0",
97
- "@arcblock/ux": "^3.0.33",
104
+ "@arcblock/ux": "^3.0.36",
98
105
  "@blocklet/error": "0.2.5",
99
106
  "@blocklet/logger": "^1.16.46",
100
- "@blocklet/payment-js": "^1.19.8",
107
+ "@blocklet/payment-js": "^1.19.9",
101
108
  "@blocklet/sdk": "^1.16.46",
102
109
  "@emotion/css": "^11.13.5",
103
110
  "@emotion/react": "^11.14.0",