@huma-finance/widgets 0.0.61-beta.551 → 0.0.61-beta.552

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@huma-finance/widgets",
3
- "version": "0.0.61-beta.551+578021f",
3
+ "version": "0.0.61-beta.552+89568b3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -195,5 +195,5 @@
195
195
  "optionalDependencies": {
196
196
  "encoding": "^0.1.13"
197
197
  },
198
- "gitHead": "578021f365d10b0fe79112837b797631d92cda48"
198
+ "gitHead": "89568b3b32040fb6bcbaac6f238577ae720c109c"
199
199
  }
@@ -77,21 +77,34 @@ export function ChooseAmount({
77
77
  dispatch(setStep(step))
78
78
  }
79
79
 
80
- const getAvailable = () => {
81
- const trancheCap =
82
- selectedTranche === 'junior' ? juniorAvailableCapBN : seniorAvailableCapBN
80
+ const getTrancheCap = () => {
81
+ if (selectedTranche === 'junior') {
82
+ return juniorAvailableCapBN
83
+ }
84
+ return seniorAvailableCapBN
85
+ }
86
+
87
+ const getMaxAmount = () => {
88
+ const trancheCap = getTrancheCap()
83
89
  return balance.gt(trancheCap) ? trancheCap : balance
84
90
  }
85
91
 
86
92
  const getInfos = () => {
87
- const available = getAvailable()
88
- const infos: string[] = [
93
+ const trancheCap = getTrancheCap()
94
+ const currentAmountBN = ethers.utils.parseUnits(
95
+ String(currentAmount),
96
+ decimals,
97
+ )
98
+ const remainingCap = trancheCap.sub(currentAmountBN)
99
+
100
+ if (remainingCap.lt(0)) {
101
+ return ['0 remaining capacity']
102
+ }
103
+ return [
89
104
  `${formatNumber(
90
- ethers.utils.formatUnits(available, decimals),
105
+ ethers.utils.formatUnits(remainingCap, decimals),
91
106
  )} remaining capacity`,
92
107
  ]
93
-
94
- return infos
95
108
  }
96
109
 
97
110
  return (
@@ -103,7 +116,7 @@ export function ChooseAmount({
103
116
  tokenSymbol={symbol}
104
117
  currentAmount={currentAmount}
105
118
  handleChangeAmount={handleChangeAmount}
106
- maxAmount={Number(ethers.utils.formatUnits(getAvailable(), decimals))}
119
+ maxAmount={Number(ethers.utils.formatUnits(getMaxAmount(), decimals))}
107
120
  maxAmountTitle={`${formatNumber(
108
121
  ethers.utils.formatUnits(balance, decimals),
109
122
  )} balance`}