best-unit 2.1.11 → 2.1.14

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,7 +1,7 @@
1
1
  {
2
2
  "name": "best-unit",
3
3
  "private": false,
4
- "version": "2.1.11",
4
+ "version": "2.1.14",
5
5
  "type": "module",
6
6
  "main": "dist/best-unit.cjs",
7
7
  "module": "dist/best-unit.js",
package/src/api/index.ts CHANGED
@@ -254,7 +254,7 @@ export const calculateBusinessExchangeRate = async (data: {
254
254
  return http()
255
255
  .post("/business_exchange_rate/calculate", {
256
256
  fund_balance_id: fundUnitParams.fundBalanceId,
257
- merchant_id: fundUnitParams.merchantId,
257
+ merchant_id: String(fundUnitParams.merchantId),
258
258
  biz_type: fundUnitParams.bizType,
259
259
  amount: data.amount,
260
260
  payment_currency: data.currency,
@@ -39,6 +39,10 @@ function formatPercentageInput(value: string) {
39
39
  return nextValue;
40
40
  }
41
41
 
42
+ function formatAutoFilledPercentage(value: number) {
43
+ return value.toFixed(2).replace(/\.?0+$/, "");
44
+ }
45
+
42
46
  export function useFundAllocation() {
43
47
  const [subBusinesses, setSubBusinesses] = useState<MerchantBalanceItem[]>([]);
44
48
  const [useFundAllocation, setUseFundAllocation] = useState(false);
@@ -105,10 +109,26 @@ export function useFundAllocation() {
105
109
  };
106
110
 
107
111
  const handlePercentageChange = (bizType: string, value: string) => {
108
- setSubBizPercentages((prev) => ({
109
- ...prev,
110
- [bizType]: value,
111
- }));
112
+ setSubBizPercentages((prev) => {
113
+ const nextPercentages = {
114
+ ...prev,
115
+ [bizType]: value,
116
+ };
117
+
118
+ if (subBusinesses.length === 2) {
119
+ const pairedBiz = subBusinesses.find((item) => item.bizType !== bizType);
120
+ const currentValue = Number(value);
121
+
122
+ if (pairedBiz) {
123
+ nextPercentages[pairedBiz.bizType] =
124
+ value.trim() && !Number.isNaN(currentValue) && currentValue >= 0 && currentValue <= 100
125
+ ? formatAutoFilledPercentage(100 - currentValue)
126
+ : "";
127
+ }
128
+ }
129
+
130
+ return nextPercentages;
131
+ });
112
132
  setSubBizError("");
113
133
  };
114
134
 
@@ -223,7 +243,7 @@ export function FundAllocationSection({
223
243
  inputMode="decimal"
224
244
  placeholder={getBizTypePlaceholder(item.bizType)}
225
245
  value={subBizPercentages[item.bizType] || ""}
226
- onChange={(e) => {
246
+ onInput={(e) => {
227
247
  onPercentageChange(
228
248
  item.bizType,
229
249
  formatPercentageInput(
package/src/demo/App.tsx CHANGED
@@ -46,7 +46,8 @@ export default function DemoApp() {
46
46
  env: env ?? currentEnv,
47
47
  size: Size.SMALL,
48
48
  biz_type: "ad",
49
- merchant_id: "1128",
49
+ merchant_id: "13226",
50
+ // merchant_id: "1128",
50
51
  // theme_config: {
51
52
  // white: {
52
53
  // color: "red",