Skip to content

Commit 6571082

Browse files
authored
Merge pull request #48 from synonymdev/error-api-limits
Setting input limit validation using API fields
2 parents 17af2a0 + fff700d commit 6571082

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"dependencies": {
66
"@reduxjs/toolkit": "^1.6.1",
7-
"@synonymdev/blocktank-client": "^0.0.45",
7+
"@synonymdev/blocktank-client": "^0.0.46",
88
"@testing-library/jest-dom": "^5.11.4",
99
"@testing-library/react": "^11.1.0",
1010
"@testing-library/user-event": "^12.1.10",

src/pages/public/configure/index.tsx

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@ function ConfigurePage(): JSX.Element {
123123
return true;
124124
}
125125

126-
const errors: IFormErrors = {};
126+
const { max_chan_receiving, max_chan_spending } = product;
127+
const max_chan_receiving_usd = Math.floor(product.max_chan_receiving_usd);
128+
const max_chan_spending_usd = Math.floor(product.max_chan_spending_usd);
127129

128-
// TODO check channel balance
130+
const errors: IFormErrors = {};
129131

130132
if (channelExpiry !== '' && Number(channelExpiry) < 1) {
131133
errors.channelExpiry = `Minimum channel expiry is ${product.min_chan_expiry} week${
@@ -135,26 +137,27 @@ function ConfigurePage(): JSX.Element {
135137
errors.channelExpiry = `Maximum channel expiry is ${product.max_chan_expiry} weeks`;
136138
}
137139

138-
if (Number(remoteBalance) > product.max_channel_size) {
140+
if (Number(remoteBalance) > max_chan_receiving) {
139141
errors.remoteBalance = `Max receiving capacity is ${numberWithSpaces(
140-
product.max_channel_size
141-
)} sats`;
142+
max_chan_receiving
143+
)} sats ($${numberWithSpaces(max_chan_receiving_usd)})`;
142144
} else if (Number(remoteBalance) < product.min_channel_size) {
143145
errors.remoteBalance = `Minimum receiving capacity is ${numberWithSpaces(
144146
product.min_channel_size
145147
)} sats`;
146148
}
147149

148-
if (Number(localBalance) !== 0 && Number(localBalance) < product.min_channel_size) {
149-
errors.localBalance = `Minimum spending balance is ${numberWithSpaces(
150-
product.min_channel_size
151-
)} sats`;
152-
}
153-
154-
if (Number(localBalance) !== 0 && Number(localBalance) > product.max_channel_size) {
155-
errors.localBalance = `Max spending balance is ${numberWithSpaces(
156-
product.max_channel_size
157-
)} sats`;
150+
if (Number(localBalance) !== 0) {
151+
if (Number(localBalance) > max_chan_spending) {
152+
errors.localBalance = `Max spending balance is ${numberWithSpaces(
153+
max_chan_spending
154+
)} sats ($${max_chan_spending_usd})`;
155+
} else if (Number(localBalance) < product.min_channel_size) {
156+
// TODO remove this check if the min spending cap check is removed from API
157+
errors.localBalance = `Minimum spending capacity is ${numberWithSpaces(
158+
product.min_channel_size
159+
)} sats`;
160+
}
158161
}
159162

160163
setFormErrors(errors);
@@ -171,9 +174,9 @@ function ConfigurePage(): JSX.Element {
171174
const rBalance = Number(remoteBalance);
172175
const lBalance = Number(localBalance);
173176

174-
if (rBalance < lBalance + product.min_channel_size) {
175-
setRemoteBalance(`${lBalance + product.min_channel_size}`); // TODO use new min field
176-
}
177+
// if (rBalance < lBalance + product.min_channel_size) {
178+
// setRemoteBalance(`${lBalance + product.min_channel_size}`); // TODO use new min field
179+
// }
177180
}, [localBalance]);
178181

179182
const onSetInput = (str: string, set: Function): void => {
@@ -209,6 +212,8 @@ function ConfigurePage(): JSX.Element {
209212
setChannelExpiry(Math.trunc(Number(channelExpiry)).toString());
210213
}
211214

215+
setGeneralError('');
216+
212217
isValid()
213218
.then()
214219
.catch((e) => console.error(e));

src/pages/public/settings/index.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
font-style: normal;
3131
font-weight: 600;
3232
font-size: 15px;
33-
letter-spacing: -0.4px;
3433
color: #FFFFFF;
3534
}
3635

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,10 +1768,10 @@
17681768
"@svgr/plugin-svgo" "^5.5.0"
17691769
loader-utils "^2.0.0"
17701770

1771-
"@synonymdev/blocktank-client@^0.0.45":
1772-
version "0.0.45"
1773-
resolved "https://registry.yarnpkg.com/@synonymdev/blocktank-client/-/blocktank-client-0.0.45.tgz#4369d4463d5831d701bd98cfa070ccf670d5713a"
1774-
integrity sha512-cASzVmT9HQA0y4+yI2Kaz24dLXk1uDjDPY2+g+cVRqOK9ZinljKtHHFUNyMwPQUpf9mi4Xo21twbGHvu3eQdAg==
1771+
"@synonymdev/blocktank-client@^0.0.46":
1772+
version "0.0.46"
1773+
resolved "https://registry.yarnpkg.com/@synonymdev/blocktank-client/-/blocktank-client-0.0.46.tgz#0b9fcb68aeffedb8f565c317dbee27f8986a0206"
1774+
integrity sha512-s88EDbs/mDTqoe/F4yAHtkPMslkJ+LJGJUrNsskbnyounfuij9BI6WZDPc4N/LpRy3ynqvjEZKIU0qO6V91+iQ==
17751775
dependencies:
17761776
cross-fetch "^3.1.4"
17771777
node-fetch "3.1.1"

0 commit comments

Comments
 (0)