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
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
|
-
|
|
110
|
-
|
|
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
|
-
|
|
246
|
+
onInput={(e) => {
|
|
227
247
|
onPercentageChange(
|
|
228
248
|
item.bizType,
|
|
229
249
|
formatPercentageInput(
|
package/src/demo/App.tsx
CHANGED