Skip to content

Commit 51d14bd

Browse files
committed
fix: input clamp behavior
1 parent 9f7ff09 commit 51d14bd

File tree

7 files changed

+236
-58
lines changed

7 files changed

+236
-58
lines changed

examples/stake-tokens/components/staking/DelegateModal.tsx

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export const DelegateModal = ({
6363
const [isDelegating, setIsDelegating] = useState(false);
6464
const [isSimulating, setIsSimulating] = useState(false);
6565
const [maxAmountAndFee, setMaxAmountAndFee] = useState<MaxAmountAndFee>();
66-
const [, forceUpdate] = useState(0);
6766

6867
const coin = getCoin(chainName);
6968
const exp = getExponent(chainName);
@@ -193,34 +192,30 @@ export const DelegateModal = ({
193192
notionalValue: amount
194193
? calcDollarValue(coin.base, amount, prices)
195194
: undefined,
195+
minValue: 0,
196+
maxValue: maxAmountAndFee?.maxAmount ?? Number(balance),
196197
value: amount,
197-
onValueInput: (val) => {
198-
if (!val) {
199-
setAmount(undefined);
200-
return;
201-
}
202-
203-
const max = maxAmountAndFee?.maxAmount || balance;
204-
205-
if (new BigNumber(val).gt(max)) {
206-
setAmount(Number(max));
207-
forceUpdate((n) => n + 1);
208-
return;
209-
}
210-
211-
setAmount(Number(val));
198+
onValueChange: (val) => {
199+
setAmount(val);
212200
},
213201
partials: [
214202
{
215203
label: '1/2',
216204
onClick: () => {
217-
setAmount(new BigNumber(balance).dividedBy(2).toNumber());
205+
const newAmount = new BigNumber(balance)
206+
.dividedBy(2)
207+
.toNumber();
208+
setAmount(newAmount);
218209
},
219210
},
220211
{
221212
label: '1/3',
222213
onClick: () => {
223-
setAmount(new BigNumber(balance).dividedBy(3).toNumber());
214+
const newAmount = new BigNumber(balance)
215+
.dividedBy(3)
216+
.toNumber();
217+
218+
setAmount(newAmount);
224219
},
225220
},
226221
{

examples/stake-tokens/components/staking/RedelegateModal.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,29 @@ export const RedelegateModal = ({
114114
tokenName: coin.symbol,
115115
tokenIconUrl: getAssetLogoUrl(coin),
116116
}}
117+
minValue={0}
118+
maxValue={Number(maxAmount)}
117119
value={amount}
118120
notionalValue={
119121
amount ? calcDollarValue(coin.base, amount, prices) : undefined
120122
}
121-
onValueInput={(val) => {
122-
if (!val) {
123-
setAmount(undefined);
124-
return;
125-
}
126-
127-
if (new BigNumber(val).gt(maxAmount)) {
128-
setAmount(Number(maxAmount));
129-
forceUpdate((n) => n + 1);
130-
return;
131-
}
132-
133-
setAmount(Number(val));
123+
onValueChange={(val) => {
124+
setAmount(val);
134125
}}
126+
// onValueInput={(val) => {
127+
// if (!val) {
128+
// setAmount(undefined);
129+
// return;
130+
// }
131+
132+
// if (new BigNumber(val).gt(maxAmount)) {
133+
// setAmount(Number(maxAmount));
134+
// forceUpdate((n) => n + 1);
135+
// return;
136+
// }
137+
138+
// setAmount(Number(val));
139+
// }}
135140
partials={[
136141
{
137142
label: '1/2',

examples/stake-tokens/components/staking/UndelegateModal.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,25 @@ export const UndelegateModal = ({
133133
? calcDollarValue(coin.base, amount, prices)
134134
: undefined,
135135
value: amount,
136-
onValueInput: (val) => {
137-
if (!val) {
138-
setAmount(undefined);
139-
return;
140-
}
136+
minValue: 0,
137+
maxValue: Number(maxAmount),
138+
onValueChange: (val) => {
139+
setAmount(val);
140+
},
141+
// onValueInput: (val) => {
142+
// if (!val) {
143+
// setAmount(undefined);
144+
// return;
145+
// }
141146

142-
if (new BigNumber(val).gt(maxAmount)) {
143-
setAmount(Number(maxAmount));
144-
forceUpdate((n) => n + 1);
145-
return;
146-
}
147+
// if (new BigNumber(val).gt(maxAmount)) {
148+
// setAmount(Number(maxAmount));
149+
// forceUpdate((n) => n + 1);
150+
// return;
151+
// }
147152

148-
setAmount(Number(val));
149-
},
153+
// setAmount(Number(val));
154+
// },
150155
partials: [
151156
{
152157
label: '1/2',

examples/stake-tokens/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"eslint": "8.56.0",
3838
"eslint-config-next": "14.1.0",
3939
"generate-lockfile": "0.0.12",
40-
"typescript": "^5.1.6"
40+
"typescript": "^5.5.4"
4141
},
4242
"packageManager": "[email protected]"
4343
}
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
22
"compilerOptions": {
3-
"target": "ES2020",
3+
"target": "ESNext",
44
"lib": ["dom", "dom.iterable", "esnext"],
55
"allowJs": true,
66
"skipLibCheck": true,
77
"strict": true,
8-
"forceConsistentCasingInFileNames": true,
98
"noEmit": true,
109
"esModuleInterop": true,
1110
"module": "esnext",
@@ -14,11 +13,17 @@
1413
"isolatedModules": true,
1514
"jsx": "preserve",
1615
"incremental": true,
16+
"types": ["node", "react"],
17+
"plugins": [
18+
{
19+
"name": "next"
20+
}
21+
],
1722
"baseUrl": ".",
1823
"paths": {
1924
"@/*": ["*"]
2025
}
2126
},
22-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
27+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
2328
"exclude": ["node_modules"]
2429
}

examples/stake-tokens/yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ __metadata:
657657
react: "npm:18.2.0"
658658
react-dom: "npm:18.2.0"
659659
react-icons: "npm:4.6.0"
660-
typescript: "npm:^5.1.6"
660+
typescript: "npm:^5.5.4"
661661
languageName: unknown
662662
linkType: soft
663663

@@ -10352,23 +10352,23 @@ __metadata:
1035210352
languageName: node
1035310353
linkType: hard
1035410354

10355-
"typescript@npm:^5.1.6":
10356-
version: 5.4.5
10357-
resolution: "typescript@npm:5.4.5"
10355+
"typescript@npm:^5.5.4":
10356+
version: 5.5.4
10357+
resolution: "typescript@npm:5.5.4"
1035810358
bin:
1035910359
tsc: bin/tsc
1036010360
tsserver: bin/tsserver
10361-
checksum: 10c0/2954022ada340fd3d6a9e2b8e534f65d57c92d5f3989a263754a78aba549f7e6529acc1921913560a4b816c46dce7df4a4d29f9f11a3dc0d4213bb76d043251e
10361+
checksum: 10c0/422be60f89e661eab29ac488c974b6cc0a660fb2228003b297c3d10c32c90f3bcffc1009b43876a082515a3c376b1eefcce823d6e78982e6878408b9a923199c
1036210362
languageName: node
1036310363
linkType: hard
1036410364

10365-
"typescript@patch:typescript@npm%3A^5.1.6#optional!builtin<compat/typescript>":
10366-
version: 5.4.5
10367-
resolution: "typescript@patch:typescript@npm%3A5.4.5#optional!builtin<compat/typescript>::version=5.4.5&hash=5adc0c"
10365+
"typescript@patch:typescript@npm%3A^5.5.4#optional!builtin<compat/typescript>":
10366+
version: 5.5.4
10367+
resolution: "typescript@patch:typescript@npm%3A5.5.4#optional!builtin<compat/typescript>::version=5.5.4&hash=b45daf"
1036810368
bin:
1036910369
tsc: bin/tsc
1037010370
tsserver: bin/tsserver
10371-
checksum: 10c0/db2ad2a16ca829f50427eeb1da155e7a45e598eec7b086d8b4e8ba44e5a235f758e606d681c66992230d3fc3b8995865e5fd0b22a2c95486d0b3200f83072ec9
10371+
checksum: 10c0/10dd9881baba22763de859e8050d6cb6e2db854197495c6f1929b08d1eb2b2b00d0b5d9b0bcee8472f1c3f4a7ef6a5d7ebe0cfd703f853aa5ae465b8404bc1ba
1037210372
languageName: node
1037310373
linkType: hard
1037410374

0 commit comments

Comments
 (0)