Skip to content

Commit a776c0e

Browse files
authored
Merge pull request #7 from hyli-org/callbacks
Use callbacks for wallet proper event/error handling
2 parents 56db340 + da02417 commit a776c0e

File tree

16 files changed

+468
-448
lines changed

16 files changed

+468
-448
lines changed

front/bun.lockb

28 KB
Binary file not shown.

front/src/App.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useEffect } from 'react';
21
import { BrowserRouter, Routes, Route, useNavigate } from 'react-router-dom';
32
import './App.css';
43
import { WalletShowcase } from './components/WalletShowcase';
@@ -7,11 +6,10 @@ import { useWalletTransactions } from './hooks/useWalletTransactions';
76
import { useWebSocketConnection } from './hooks/useWebSocketConnection';
87
import { getPublicRoutes, getProtectedRoutes, ROUTES } from './routes/routes';
98
import { WalletProvider, useWallet } from 'hyli-wallet';
10-
import { LoadingErrorState } from './components/common/LoadingErrorState';
119
import { WebSocketProvider } from './providers/WebSocketProvider';
1210

1311
function AppContent() {
14-
const { wallet, logout, stage, error } = useWallet();
12+
const { wallet, logout } = useWallet();
1513
const navigate = useNavigate();
1614

1715
// Use custom hooks
@@ -30,22 +28,11 @@ function AppContent() {
3028
}
3129
});
3230

33-
// Redirect back to root on auth settlement error and show message via state
34-
useEffect(() => {
35-
if (stage === 'error') {
36-
navigate(ROUTES.ROOT, { state: { authError: error } });
37-
}
38-
}, [stage, error, navigate]);
39-
4031
const handleLogout = () => {
4132
logout();
4233
navigate(ROUTES.ROOT);
4334
};
4435

45-
if (error) {
46-
return <LoadingErrorState isLoading={false} error={error} />;
47-
}
48-
4936
// If wallet is not connected, show the showcase screen
5037
if (!wallet) {
5138
return <WalletShowcase providers={['password', 'google', 'github']} />;

front/src/components/common/LoadingErrorState.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

front/src/components/wallet/SessionKeys.tsx

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,19 @@ export const SessionKeys = () => {
6565
password,
6666
expiration,
6767
["oranj"],
68-
(txHash: string, type: string) => {
69-
if (type === 'blob') {
70-
setStatus('Verifying identity...');
71-
setTransactionHash(txHash);
72-
} else if (type === 'proof') {
73-
setStatus('Proof transaction sent, waiting for confirmation...');
68+
(event) => {
69+
if (event.event) {
70+
if (event.event.includes('Blob transaction sent:')) {
71+
const txHash = event.event.split(':')[1].trim();
72+
setStatus('Verifying identity...');
73+
setTransactionHash(txHash);
74+
} else if (event.event.includes('Proof transaction sent:')) {
75+
setStatus('Proof transaction sent, waiting for confirmation...');
76+
}
7477
}
78+
},
79+
(error) => {
80+
setError(error.message);
7581
}
7682
);
7783

@@ -111,13 +117,19 @@ export const SessionKeys = () => {
111117
await removeSessionKey(
112118
password,
113119
publicKey,
114-
(txHash: string, type: string) => {
115-
if (type === 'blob') {
116-
setStatus('Verifying identity...');
117-
setTransactionHash(txHash);
118-
} else if (type === 'proof') {
119-
setStatus('Proof transaction sent, waiting for confirmation...');
120+
(event) => {
121+
if (event.event) {
122+
if (event.event.includes('Blob transaction sent:')) {
123+
const txHash = event.event.split(':')[1].trim();
124+
setStatus('Verifying identity...');
125+
setTransactionHash(txHash);
126+
} else if (event.event.includes('Proof transaction sent:')) {
127+
setStatus('Proof transaction sent, waiting for confirmation...');
128+
}
120129
}
130+
},
131+
(error) => {
132+
setError(error.message);
121133
}
122134
);
123135

0 commit comments

Comments
 (0)