@blocklet/aigne-hub 0.6.26 → 0.7.0

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.
@@ -12,8 +12,9 @@ const react_1 = require("react");
12
12
  const app_1 = require("../../api/app");
13
13
  const withLocaleProvider_1 = __importDefault(require("../../utils/withLocaleProvider"));
14
14
  function CreditBalance({ balance = undefined, currency = undefined, useAIKitService = false }) {
15
- var _a, _b;
15
+ var _a, _b, _c, _d;
16
16
  const { t } = (0, context_1.useLocaleContext)();
17
+ const creditPrefix = (typeof window !== 'undefined' && ((_b = (_a = window.blocklet) === null || _a === void 0 ? void 0 : _a.preferences) === null || _b === void 0 ? void 0 : _b.creditPrefix)) || '';
17
18
  const [creditData, setCreditData] = (0, react_1.useState)(null);
18
19
  const [loading, setLoading] = (0, react_1.useState)(true);
19
20
  const [error, setError] = (0, react_1.useState)(null);
@@ -50,8 +51,8 @@ function CreditBalance({ balance = undefined, currency = undefined, useAIKitServ
50
51
  }, children: error }) }) }));
51
52
  }
52
53
  // Use props or API data
53
- const displayBalance = (_a = balance !== null && balance !== void 0 ? balance : creditData === null || creditData === void 0 ? void 0 : creditData.balance) !== null && _a !== void 0 ? _a : '0';
54
- const displayCurrency = (_b = currency !== null && currency !== void 0 ? currency : creditData === null || creditData === void 0 ? void 0 : creditData.currency) !== null && _b !== void 0 ? _b : 'USD';
54
+ const displayBalance = (_c = balance !== null && balance !== void 0 ? balance : creditData === null || creditData === void 0 ? void 0 : creditData.balance) !== null && _c !== void 0 ? _c : '0';
55
+ const displayCurrency = (_d = currency !== null && currency !== void 0 ? currency : creditData === null || creditData === void 0 ? void 0 : creditData.currency) !== null && _d !== void 0 ? _d : 'USD';
55
56
  return ((0, jsx_runtime_1.jsxs)(material_1.Card, { sx: {
56
57
  background: `linear-gradient(135deg, ${colors_1.blue[500]} 0%, ${colors_1.blue[700]} 100%)`,
57
58
  color: 'white',
@@ -59,7 +60,7 @@ function CreditBalance({ balance = undefined, currency = undefined, useAIKitServ
59
60
  overflow: 'hidden',
60
61
  }, children: [(0, jsx_runtime_1.jsx)(material_1.CardContent, { sx: { position: 'relative', zIndex: 1 }, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { spacing: 2, children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 1, sx: {
61
62
  alignItems: 'center',
62
- }, children: [(0, jsx_runtime_1.jsx)(icons_material_1.AccountBalanceWalletRounded, { sx: { fontSize: 28 } }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", sx: { fontWeight: 'bold' }, children: t('creditBalance') })] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h3", sx: { fontWeight: 'bold', lineHeight: 1 }, children: displayBalance }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body1", sx: { opacity: 0.9, mt: 0.5 }, children: displayCurrency })] }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", sx: { opacity: 0.8 }, children: t('availableForUse') })] }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
63
+ }, children: [(0, jsx_runtime_1.jsx)(icons_material_1.AccountBalanceWalletRounded, { sx: { fontSize: 28 } }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", sx: { fontWeight: 'bold' }, children: t('creditBalance') })] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "h3", sx: { fontWeight: 'bold', lineHeight: 1 }, children: [creditPrefix, displayBalance] }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body1", sx: { opacity: 0.9, mt: 0.5 }, children: displayCurrency })] }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", sx: { opacity: 0.8 }, children: t('availableForUse') })] }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
63
64
  position: 'absolute',
64
65
  top: -20,
65
66
  right: -20,
@@ -14,8 +14,9 @@ const user_1 = require("../api/user");
14
14
  const util_1 = require("../utils/util");
15
15
  const withLocaleProvider_1 = __importDefault(require("../utils/withLocaleProvider"));
16
16
  function UserCreditCard({ baseUrl, apiKey, onSuccess = () => { }, onError = () => { }, mode = 'default', render = () => null, chargeBtnProps = {}, manageBtnProps = {}, }) {
17
- var _a, _b;
17
+ var _a, _b, _c, _d;
18
18
  const { t } = (0, context_1.useLocaleContext)();
19
+ const creditPrefix = (typeof window !== 'undefined' && ((_b = (_a = window.blocklet) === null || _a === void 0 ? void 0 : _a.preferences) === null || _b === void 0 ? void 0 : _b.creditPrefix)) || '';
19
20
  const { data: userInfoData, loading } = (0, ahooks_1.useRequest)(() => (0, user_1.getUserInfo)({ baseUrl, accessKey: apiKey }), {
20
21
  refreshDeps: [baseUrl, apiKey],
21
22
  onError: (err) => {
@@ -54,17 +55,17 @@ function UserCreditCard({ baseUrl, apiKey, onSuccess = () => { }, onError = () =
54
55
  alignItems: 'center',
55
56
  }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", sx: {
56
57
  color: 'text.secondary',
57
- }, children: t('creditBalance') }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", sx: {
58
+ }, children: t('creditBalance') }), (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "h6", sx: {
58
59
  fontWeight: 'bold',
59
- }, 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", sx: {
60
+ }, children: [creditPrefix, (0, util_1.formatNumber)(((_c = userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.creditBalance) === null || _c === void 0 ? void 0 : _c.balance) || '0')] })] }), ((_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", sx: {
60
61
  justifyContent: 'space-between',
61
62
  alignItems: 'center',
62
63
  }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", sx: {
63
64
  color: 'text.secondary',
64
- }, children: t('pendingCredit') }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", sx: {
65
+ }, children: t('pendingCredit') }), (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "h6", sx: {
65
66
  fontWeight: 'bold',
66
67
  color: 'error.main',
67
- }, 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: () => {
68
+ }, children: [creditPrefix, (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: () => {
68
69
  window.open((userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.paymentLink) || '', '_blank');
69
70
  }, sx: {
70
71
  flex: 1,
@@ -3,9 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CREDIT_DISPLAY_DECIMAL_PLACES = void 0;
6
7
  exports.formatNumber = formatNumber;
7
8
  const trimEnd_1 = __importDefault(require("lodash/trimEnd"));
8
9
  const numbro_1 = __importDefault(require("numbro"));
10
+ // Decimal places for credit display in UI (different from backend calculation precision)
11
+ exports.CREDIT_DISPLAY_DECIMAL_PLACES = 6;
9
12
  function formatNumber(n, precision = 6, trim = true, thousandSeparated = true) {
10
13
  if (!n || n === '0') {
11
14
  return '0';
@@ -7,8 +7,9 @@ import { useCallback, useEffect, useState } from 'react';
7
7
  import { getCreditBalance } from '../../api/app';
8
8
  import withLocaleProvider from '../../utils/withLocaleProvider';
9
9
  function CreditBalance({ balance = undefined, currency = undefined, useAIKitService = false }) {
10
- var _a, _b;
10
+ var _a, _b, _c, _d;
11
11
  const { t } = useLocaleContext();
12
+ const creditPrefix = (typeof window !== 'undefined' && ((_b = (_a = window.blocklet) === null || _a === void 0 ? void 0 : _a.preferences) === null || _b === void 0 ? void 0 : _b.creditPrefix)) || '';
12
13
  const [creditData, setCreditData] = useState(null);
13
14
  const [loading, setLoading] = useState(true);
14
15
  const [error, setError] = useState(null);
@@ -45,8 +46,8 @@ function CreditBalance({ balance = undefined, currency = undefined, useAIKitServ
45
46
  }, children: error }) }) }));
46
47
  }
47
48
  // Use props or API data
48
- const displayBalance = (_a = balance !== null && balance !== void 0 ? balance : creditData === null || creditData === void 0 ? void 0 : creditData.balance) !== null && _a !== void 0 ? _a : '0';
49
- const displayCurrency = (_b = currency !== null && currency !== void 0 ? currency : creditData === null || creditData === void 0 ? void 0 : creditData.currency) !== null && _b !== void 0 ? _b : 'USD';
49
+ const displayBalance = (_c = balance !== null && balance !== void 0 ? balance : creditData === null || creditData === void 0 ? void 0 : creditData.balance) !== null && _c !== void 0 ? _c : '0';
50
+ const displayCurrency = (_d = currency !== null && currency !== void 0 ? currency : creditData === null || creditData === void 0 ? void 0 : creditData.currency) !== null && _d !== void 0 ? _d : 'USD';
50
51
  return (_jsxs(Card, { sx: {
51
52
  background: `linear-gradient(135deg, ${blue[500]} 0%, ${blue[700]} 100%)`,
52
53
  color: 'white',
@@ -54,7 +55,7 @@ function CreditBalance({ balance = undefined, currency = undefined, useAIKitServ
54
55
  overflow: 'hidden',
55
56
  }, children: [_jsx(CardContent, { sx: { position: 'relative', zIndex: 1 }, children: _jsxs(Stack, { spacing: 2, children: [_jsxs(Stack, { direction: "row", spacing: 1, sx: {
56
57
  alignItems: 'center',
57
- }, children: [_jsx(AccountBalanceWalletRounded, { sx: { fontSize: 28 } }), _jsx(Typography, { variant: "h6", sx: { fontWeight: 'bold' }, children: t('creditBalance') })] }), _jsxs(Box, { children: [_jsx(Typography, { variant: "h3", sx: { fontWeight: 'bold', lineHeight: 1 }, children: displayBalance }), _jsx(Typography, { variant: "body1", sx: { opacity: 0.9, mt: 0.5 }, children: displayCurrency })] }), _jsx(Typography, { variant: "body2", sx: { opacity: 0.8 }, children: t('availableForUse') })] }) }), _jsx(Box, { sx: {
58
+ }, children: [_jsx(AccountBalanceWalletRounded, { sx: { fontSize: 28 } }), _jsx(Typography, { variant: "h6", sx: { fontWeight: 'bold' }, children: t('creditBalance') })] }), _jsxs(Box, { children: [_jsxs(Typography, { variant: "h3", sx: { fontWeight: 'bold', lineHeight: 1 }, children: [creditPrefix, displayBalance] }), _jsx(Typography, { variant: "body1", sx: { opacity: 0.9, mt: 0.5 }, children: displayCurrency })] }), _jsx(Typography, { variant: "body2", sx: { opacity: 0.8 }, children: t('availableForUse') })] }) }), _jsx(Box, { sx: {
58
59
  position: 'absolute',
59
60
  top: -20,
60
61
  right: -20,
@@ -9,8 +9,9 @@ import { getUserInfo } from '../api/user';
9
9
  import { formatNumber } from '../utils/util';
10
10
  import withLocaleProvider from '../utils/withLocaleProvider';
11
11
  function UserCreditCard({ baseUrl, apiKey, onSuccess = () => { }, onError = () => { }, mode = 'default', render = () => null, chargeBtnProps = {}, manageBtnProps = {}, }) {
12
- var _a, _b;
12
+ var _a, _b, _c, _d;
13
13
  const { t } = useLocaleContext();
14
+ const creditPrefix = (typeof window !== 'undefined' && ((_b = (_a = window.blocklet) === null || _a === void 0 ? void 0 : _a.preferences) === null || _b === void 0 ? void 0 : _b.creditPrefix)) || '';
14
15
  const { data: userInfoData, loading } = useRequest(() => getUserInfo({ baseUrl, accessKey: apiKey }), {
15
16
  refreshDeps: [baseUrl, apiKey],
16
17
  onError: (err) => {
@@ -49,17 +50,17 @@ function UserCreditCard({ baseUrl, apiKey, onSuccess = () => { }, onError = () =
49
50
  alignItems: 'center',
50
51
  }, children: [_jsx(Typography, { variant: "body2", sx: {
51
52
  color: 'text.secondary',
52
- }, children: t('creditBalance') }), _jsx(Typography, { variant: "h6", sx: {
53
+ }, children: t('creditBalance') }), _jsxs(Typography, { variant: "h6", sx: {
53
54
  fontWeight: 'bold',
54
- }, 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", sx: {
55
+ }, children: [creditPrefix, formatNumber(((_c = userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.creditBalance) === null || _c === void 0 ? void 0 : _c.balance) || '0')] })] }), ((_d = userInfoData.creditBalance) === null || _d === void 0 ? void 0 : _d.pendingCredit) && Number(userInfoData.creditBalance.pendingCredit) > 0 && (_jsxs(Stack, { direction: "row", sx: {
55
56
  justifyContent: 'space-between',
56
57
  alignItems: 'center',
57
58
  }, children: [_jsx(Typography, { variant: "body2", sx: {
58
59
  color: 'text.secondary',
59
- }, children: t('pendingCredit') }), _jsx(Typography, { variant: "h6", sx: {
60
+ }, children: t('pendingCredit') }), _jsxs(Typography, { variant: "h6", sx: {
60
61
  fontWeight: 'bold',
61
62
  color: 'error.main',
62
- }, 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: () => {
63
+ }, children: [creditPrefix, 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: () => {
63
64
  window.open((userInfoData === null || userInfoData === void 0 ? void 0 : userInfoData.paymentLink) || '', '_blank');
64
65
  }, sx: {
65
66
  flex: 1,
@@ -1,5 +1,7 @@
1
1
  import trimEnd from 'lodash/trimEnd';
2
2
  import numbro from 'numbro';
3
+ // Decimal places for credit display in UI (different from backend calculation precision)
4
+ export const CREDIT_DISPLAY_DECIMAL_PLACES = 6;
3
5
  export function formatNumber(n, precision = 6, trim = true, thousandSeparated = true) {
4
6
  if (!n || n === '0') {
5
7
  return '0';
@@ -1 +1,2 @@
1
+ export declare const CREDIT_DISPLAY_DECIMAL_PLACES = 6;
1
2
  export declare function formatNumber(n: number | string, precision?: number, trim?: boolean, thousandSeparated?: boolean): string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/aigne-hub",
3
- "version": "0.6.26",
3
+ "version": "0.7.0",
4
4
  "description": "The react.js component library for AIGNE Hub",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -100,12 +100,12 @@
100
100
  "react": "^18.2.0"
101
101
  },
102
102
  "dependencies": {
103
- "@arcblock/did": "^1.27.14",
104
- "@arcblock/ux": "^3.2.11",
105
- "@blocklet/error": "0.3.2",
106
- "@blocklet/logger": "^1.17.4",
107
- "@blocklet/payment-js": "^1.22.30",
108
- "@blocklet/sdk": "^1.17.4",
103
+ "@arcblock/did": "^1.27.15",
104
+ "@arcblock/ux": "^3.2.15",
105
+ "@blocklet/error": "0.3.5",
106
+ "@blocklet/logger": "^1.17.6-beta-20251216-081847-bf91c4db",
107
+ "@blocklet/payment-js": "^1.23.2",
108
+ "@blocklet/sdk": "^1.17.6-beta-20251216-081847-bf91c4db",
109
109
  "@emotion/css": "^11.13.5",
110
110
  "@emotion/react": "^11.14.0",
111
111
  "@emotion/styled": "^11.14.1",
@@ -113,8 +113,8 @@
113
113
  "@mui/lab": "^7.0.0-beta.14",
114
114
  "@mui/material": "^7.2.0",
115
115
  "@mui/system": "^7.2.0",
116
- "@ocap/mcrypto": "^1.27.14",
117
- "@ocap/util": "^1.27.14",
116
+ "@ocap/mcrypto": "^1.27.15",
117
+ "@ocap/util": "^1.27.15",
118
118
  "@types/express": "^5.0.3",
119
119
  "ahooks": "^3.8.1",
120
120
  "axios": "^1.7.4",