Merge pull request 'fix: unstakePosition() has no error handling at all (#482)' (#514) from fix/issue-482 into master
This commit is contained in:
commit
b97ab18514
1 changed files with 18 additions and 5 deletions
|
|
@ -39,6 +39,9 @@
|
|||
<span>{{ error }}</span>
|
||||
<FButton size="tiny" outlined @click="loadActivePositionData">Retry</FButton>
|
||||
</div>
|
||||
<div v-if="unstakeError" class="collapsed-body--error">
|
||||
<span>{{ unstakeError }}</span>
|
||||
</div>
|
||||
<div v-if="!error || taxPaidGes !== undefined" class="profit-stats-wrapper">
|
||||
<div class="profit-stats-item">
|
||||
<div><b>Tax Cost</b></div>
|
||||
|
|
@ -122,6 +125,7 @@ const taxPaidGes = ref<number>();
|
|||
const profit = ref<number>();
|
||||
const loading = ref<boolean>(false);
|
||||
const error = ref<string | null>(null);
|
||||
const unstakeError = ref<string | null>(null);
|
||||
|
||||
const tag = computed(() => {
|
||||
// Compare by index instead of decimal to avoid floating-point issues
|
||||
|
|
@ -214,12 +218,15 @@ async function changeTax(id: bigint, nextTaxRateIndex: number | null) {
|
|||
}
|
||||
|
||||
async function unstakePosition() {
|
||||
await unstake.exitPosition(props.id);
|
||||
loading.value = true;
|
||||
const POLL_INTERVAL_MS = 1000;
|
||||
const TIMEOUT_MS = 30_000;
|
||||
const deadline = Date.now() + TIMEOUT_MS;
|
||||
unstakeError.value = null;
|
||||
let exitSucceeded = false;
|
||||
try {
|
||||
await unstake.exitPosition(props.id);
|
||||
exitSucceeded = true;
|
||||
loading.value = true;
|
||||
const POLL_INTERVAL_MS = 1000;
|
||||
const TIMEOUT_MS = 30_000;
|
||||
const deadline = Date.now() + TIMEOUT_MS;
|
||||
while (Date.now() < deadline) {
|
||||
const { positions } = await loadActivePositions(currentChainId.value);
|
||||
if (!positions.some(p => BigInt(p.id) === props.id)) break;
|
||||
|
|
@ -227,6 +234,12 @@ async function unstakePosition() {
|
|||
await new Promise<void>(resolve => setTimeout(resolve, POLL_INTERVAL_MS));
|
||||
}
|
||||
await loadPositions(currentChainId.value);
|
||||
} catch (err) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(exitSucceeded ? 'Failed to refresh positions after unstake:' : 'Failed to unstake position:', err);
|
||||
unstakeError.value = exitSucceeded
|
||||
? 'Position unstaked, but failed to refresh data.'
|
||||
: 'Failed to unstake position.';
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue