fix: unstakePosition() has no error handling at all (#482)
Wrap the entire unstakePosition() body in try/catch/finally so that errors from exitPosition(), loadActivePositions(), and loadPositions() are caught, displayed to the user via the existing error ref, and loading state is always reset correctly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
c45a898e90
commit
a8defd10b4
1 changed files with 10 additions and 5 deletions
|
|
@ -214,12 +214,13 @@ async function changeTax(id: bigint, nextTaxRateIndex: number | null) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function unstakePosition() {
|
async function unstakePosition() {
|
||||||
await unstake.exitPosition(props.id);
|
error.value = null;
|
||||||
loading.value = true;
|
|
||||||
const POLL_INTERVAL_MS = 1000;
|
|
||||||
const TIMEOUT_MS = 30_000;
|
|
||||||
const deadline = Date.now() + TIMEOUT_MS;
|
|
||||||
try {
|
try {
|
||||||
|
await unstake.exitPosition(props.id);
|
||||||
|
loading.value = true;
|
||||||
|
const POLL_INTERVAL_MS = 1000;
|
||||||
|
const TIMEOUT_MS = 30_000;
|
||||||
|
const deadline = Date.now() + TIMEOUT_MS;
|
||||||
while (Date.now() < deadline) {
|
while (Date.now() < deadline) {
|
||||||
const { positions } = await loadActivePositions(currentChainId.value);
|
const { positions } = await loadActivePositions(currentChainId.value);
|
||||||
if (!positions.some(p => BigInt(p.id) === props.id)) break;
|
if (!positions.some(p => BigInt(p.id) === props.id)) break;
|
||||||
|
|
@ -227,6 +228,10 @@ async function unstakePosition() {
|
||||||
await new Promise<void>(resolve => setTimeout(resolve, POLL_INTERVAL_MS));
|
await new Promise<void>(resolve => setTimeout(resolve, POLL_INTERVAL_MS));
|
||||||
}
|
}
|
||||||
await loadPositions(currentChainId.value);
|
await loadPositions(currentChainId.value);
|
||||||
|
} catch (err) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error('Failed to unstake position:', err);
|
||||||
|
error.value = 'Failed to unstake position.';
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue