Skip to content

Commit

Permalink
fix: confirmation screen after wallet connect
Browse files Browse the repository at this point in the history
  • Loading branch information
muddlebee committed Nov 19, 2024
1 parent 9d7926a commit c5bf3eb
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,43 @@ export default function Component() {
}

const handleSwap = async () => {
setIsSwapping(true)
if (!isConnected) {
return;
}

setIsSwapping(true);

try {
for (let i = 0; i < swapSteps.length; i++) {
setSwapSteps(steps => steps.map(step =>
step.id === i + 1 ? { ...step, status: 'loading' } : step
))
await new Promise(r => setTimeout(r, 2000 + Math.random() * 1000))
));

await new Promise(r => setTimeout(r, 2000 + Math.random() * 1000));

const success = await mockBlockchainTransaction();

if (!success) {
throw new Error(`Step ${i + 1} failed`);
}

setSwapSteps(steps => steps.map(step =>
step.id === i + 1 ? { ...step, status: 'completed' } : step
))
));
}
} catch (error) {
console.error('Swap failed:', error)
console.error('Swap failed:', error);
setSwapSteps(steps => steps.map(step =>
step.status === 'loading' ? { ...step, status: 'pending' } : step
));
}
}

const mockBlockchainTransaction = async (): Promise<boolean> => {
const success = Math.random() > 0.1;
return success;
}

const tokens = [
{ name: 'DOT', icon: '●', price: '$2.00' },
{ name: 'ETH', icon: 'Ξ', price: '$2000' },
Expand Down

0 comments on commit c5bf3eb

Please sign in to comment.