Compare commits
4 Commits
16383491b4
...
0ef94ef5e6
| Author | SHA1 | Date | |
|---|---|---|---|
| 0ef94ef5e6 | |||
| 41883b0356 | |||
| 0ca6fd6e6d | |||
| bbcc5000cd |
108
.gitignore
vendored
108
.gitignore
vendored
@ -1,19 +1,11 @@
|
|||||||
|
# ============================
|
||||||
# 4NK Environment - Git Ignore
|
# 4NK Environment - Git Ignore
|
||||||
# ============================
|
# ============================
|
||||||
|
|
||||||
|
# ----------------------------
|
||||||
|
# Configuration
|
||||||
|
# ----------------------------
|
||||||
confs/
|
confs/
|
||||||
# Dossiers de sauvegarde des scripts
|
|
||||||
**/backup/
|
|
||||||
**/*backup*
|
|
||||||
|
|
||||||
**/.cargo/
|
|
||||||
|
|
||||||
# Fichiers temporaires
|
|
||||||
**/*.tmp*
|
|
||||||
**/*.temp*
|
|
||||||
**/*.log*
|
|
||||||
**/*.pid*
|
|
||||||
|
|
||||||
# Fichiers de configuration locale
|
|
||||||
**/*.env*
|
**/*.env*
|
||||||
**/*.conf*
|
**/*.conf*
|
||||||
**/*.yaml*
|
**/*.yaml*
|
||||||
@ -23,57 +15,71 @@ confs/
|
|||||||
**/*.toml*
|
**/*.toml*
|
||||||
**/*.lock*
|
**/*.lock*
|
||||||
|
|
||||||
# Données et logs
|
# ----------------------------
|
||||||
|
# Backups
|
||||||
|
# ----------------------------
|
||||||
|
**/backup/
|
||||||
|
**/*backup*
|
||||||
|
**/*wallet*
|
||||||
|
**/*keys*
|
||||||
|
|
||||||
|
# ----------------------------
|
||||||
|
# Temporary files & logs
|
||||||
|
# ----------------------------
|
||||||
|
**/*.tmp*
|
||||||
|
**/*.temp*
|
||||||
|
**/*.log*
|
||||||
**/*.logs*
|
**/*.logs*
|
||||||
**/*.data
|
**/*.pid*
|
||||||
*.db
|
*.db
|
||||||
*.sqlite
|
*.sqlite
|
||||||
|
**/*.data
|
||||||
|
|
||||||
# Certificats et clés
|
# ----------------------------
|
||||||
|
# Certificates & keys
|
||||||
|
# ----------------------------
|
||||||
|
ssl/
|
||||||
|
certs/
|
||||||
**/*.key
|
**/*.key
|
||||||
**/*.pem
|
**/*.pem
|
||||||
**/*.crt
|
**/*.crt
|
||||||
**/*.p12
|
**/*.p12
|
||||||
**/*.pfx
|
**/*.pfx
|
||||||
ssl/
|
|
||||||
certs/
|
|
||||||
|
|
||||||
# Docker
|
# ----------------------------
|
||||||
**/*.docker*
|
# Build / Cache
|
||||||
|
# ----------------------------
|
||||||
# Cache et build
|
**/node_modules/
|
||||||
**/*.node_modules/
|
**/dist/
|
||||||
**/*.dist/
|
**/build/
|
||||||
**/*build/
|
**/target/
|
||||||
**/*target/
|
package-lock.json
|
||||||
**/*.*.o
|
**/*.o
|
||||||
**/*.so
|
**/*.so
|
||||||
**/*.dylib
|
**/*.dylib
|
||||||
|
|
||||||
# IDE et éditeurs
|
# ----------------------------
|
||||||
**/*.vscode/
|
# IDE / Editors
|
||||||
**/*.idea/
|
# ----------------------------
|
||||||
**/*.swp
|
.vscode/
|
||||||
**/*.swo
|
.idea/
|
||||||
**/*~
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*~
|
||||||
|
|
||||||
# OS
|
# ----------------------------
|
||||||
**/*.DS_Store
|
# OS files
|
||||||
**/*Thumbs.db
|
# ----------------------------
|
||||||
**/*tmp*
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
*tmp*
|
||||||
|
|
||||||
# Git
|
# ----------------------------
|
||||||
**/*.git/
|
# Docker
|
||||||
**/*.orig*
|
# ----------------------------
|
||||||
|
**/*.docker*
|
||||||
|
|
||||||
# Backup des projets existants
|
# ----------------------------
|
||||||
**/*backup*
|
# Git internals
|
||||||
|
# ----------------------------
|
||||||
|
*.orig
|
||||||
**/*wallet*
|
|
||||||
**/*keys*
|
|
||||||
|
|
||||||
**/*node_modules*
|
|
||||||
**/*cursor*
|
|
||||||
**/*pid*
|
|
||||||
**/*next*
|
|
||||||
|
|||||||
3155
package-lock.json
generated
3155
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
76
src/App.tsx
76
src/App.tsx
@ -7,7 +7,7 @@ import ProfileModal from './components/ProfileModal'
|
|||||||
import AuthModal from './sdk/AuthModal';
|
import AuthModal from './sdk/AuthModal';
|
||||||
import MessageBus from './sdk/MessageBus';
|
import MessageBus from './sdk/MessageBus';
|
||||||
import EventBus from './sdk/EventBus';
|
import EventBus from './sdk/EventBus';
|
||||||
import UserStore from './sdk/UserStrore';
|
import UserStore from './sdk/UserStore';
|
||||||
import Iframe from './sdk/Iframe'
|
import Iframe from './sdk/Iframe'
|
||||||
import BlockchainViewer from './components/ProcessesViewer';
|
import BlockchainViewer from './components/ProcessesViewer';
|
||||||
import FolderModal from './components/FolderModal';
|
import FolderModal from './components/FolderModal';
|
||||||
@ -27,47 +27,55 @@ function App() {
|
|||||||
const [userPairingId, setUserPairingId] = useState<string | null>(null)
|
const [userPairingId, setUserPairingId] = useState<string | null>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// Met à jour la connexion au montage
|
||||||
setIsConnected(UserStore.getInstance().isConnected());
|
setIsConnected(UserStore.getInstance().isConnected());
|
||||||
});
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// Charge le pairingId s’il existe déjà
|
||||||
setUserPairingId(UserStore.getInstance().getUserPairingId());
|
setUserPairingId(UserStore.getInstance().getUserPairingId());
|
||||||
});
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isConnected) {
|
const handleConnectionFlow = async () => {
|
||||||
|
if (!isConnected) return;
|
||||||
|
|
||||||
|
const userStore = UserStore.getInstance();
|
||||||
const messageBus = MessageBus.getInstance(iframeUrl);
|
const messageBus = MessageBus.getInstance(iframeUrl);
|
||||||
messageBus.isReady().then(() => {
|
|
||||||
messageBus.getProcesses().then((processes: any) => {
|
try {
|
||||||
setProcesses(processes);
|
await messageBus.isReady();
|
||||||
});
|
|
||||||
});
|
let pairingId = userStore.getUserPairingId();
|
||||||
}
|
|
||||||
|
// 1️⃣ Créer le pairing si non existant
|
||||||
|
if (!pairingId) {
|
||||||
|
console.log("🚀 No pairing found — creating new pairing...");
|
||||||
|
pairingId = await messageBus.createUserPairing();
|
||||||
|
console.log("✅ Pairing created:", pairingId);
|
||||||
|
|
||||||
|
userStore.pair(pairingId);
|
||||||
|
setUserPairingId(pairingId);
|
||||||
|
} else {
|
||||||
|
console.log("🔗 Already paired with ID:", pairingId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2️⃣ Charger les processes
|
||||||
|
const processes = await messageBus.getProcesses();
|
||||||
|
setProcesses(processes);
|
||||||
|
|
||||||
|
// 3️⃣ Charger les myProcesses
|
||||||
|
const myProcesses = await messageBus.getMyProcesses();
|
||||||
|
setMyProcesses(myProcesses);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error("❌ Error during pairing or process loading:", err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
handleConnectionFlow();
|
||||||
}, [isConnected, iframeUrl]);
|
}, [isConnected, iframeUrl]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (isConnected && processes !== null) {
|
|
||||||
const messageBus = MessageBus.getInstance(iframeUrl);
|
|
||||||
messageBus.isReady().then(() => {
|
|
||||||
messageBus.getMyProcesses().then((res: string[]) => {
|
|
||||||
setMyProcesses(res);
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [isConnected, processes]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (isConnected && userPairingId === null) {
|
|
||||||
const messageBus = MessageBus.getInstance(iframeUrl);
|
|
||||||
messageBus.isReady().then(() => {
|
|
||||||
messageBus.getUserPairingId().then((userPairingId: string) => {
|
|
||||||
UserStore.getInstance().pair(userPairingId);
|
|
||||||
setUserPairingId(UserStore.getInstance().getUserPairingId());
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [isConnected, userPairingId, processes]);
|
|
||||||
|
|
||||||
// Gestionnaire pour afficher la modale de connexion
|
// Gestionnaire pour afficher la modale de connexion
|
||||||
const handleLogin = useCallback(() => {
|
const handleLogin = useCallback(() => {
|
||||||
// Afficher la modale de connexion
|
// Afficher la modale de connexion
|
||||||
@ -189,7 +197,7 @@ function App() {
|
|||||||
{/* Espace pour contenu supplémentaire à droite */}
|
{/* Espace pour contenu supplémentaire à droite */}
|
||||||
<div className="content-area">
|
<div className="content-area">
|
||||||
{/* Affichage des blocs de la blockchain */}
|
{/* Affichage des blocs de la blockchain */}
|
||||||
<BlockchainViewer processes={processes} myProcesses={myProcesses} onProcessesUpdate={setProcesses}/>
|
<BlockchainViewer processes={processes} myProcesses={myProcesses} onProcessesUpdate={setProcesses} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import IframeReference from './IframeReference';
|
import IframeReference from './IframeReference';
|
||||||
import EventBus from './EventBus';
|
import EventBus from './EventBus';
|
||||||
import UserStore from './UserStrore';
|
import UserStore from './UserStore';
|
||||||
import { isProfileData, type ProfileCreated, type ProfileData } from './models/ProfileData';
|
import { isProfileData, type ProfileCreated, type ProfileData } from './models/ProfileData';
|
||||||
import { isFolderData, type FolderCreated, type FolderData } from './models/FolderData';
|
import { isFolderData, type FolderCreated, type FolderData } from './models/FolderData';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
@ -80,6 +80,48 @@ export default class MessageBus {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public createUserPairing(): Promise<string> {
|
||||||
|
return new Promise<string>((resolve, reject) => {
|
||||||
|
this.checkToken().then(async () => {
|
||||||
|
const userStore = UserStore.getInstance();
|
||||||
|
const accessToken = userStore.getAccessToken();
|
||||||
|
if (!accessToken) {
|
||||||
|
return reject('No access token found');
|
||||||
|
}
|
||||||
|
|
||||||
|
const correlationId = uuidv4();
|
||||||
|
this.initMessageListener(correlationId);
|
||||||
|
|
||||||
|
// ✅ Success listener
|
||||||
|
const unsubscribeSuccess = EventBus.getInstance().on('PAIRING_CREATED', (responseId: string, pairingId: string) => {
|
||||||
|
if (responseId !== correlationId) return;
|
||||||
|
unsubscribeSuccess();
|
||||||
|
unsubscribeError();
|
||||||
|
this.destroyMessageListener();
|
||||||
|
resolve(pairingId);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ❌ Error listener
|
||||||
|
const unsubscribeError = EventBus.getInstance().on('ERROR_CREATE_PAIRING', (responseId: string, error: string) => {
|
||||||
|
if (responseId !== correlationId) return;
|
||||||
|
unsubscribeError();
|
||||||
|
unsubscribeSuccess();
|
||||||
|
this.destroyMessageListener();
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 📨 Send CREATE_PAIRING message to iframe
|
||||||
|
this.sendMessage({
|
||||||
|
type: 'CREATE_PAIRING',
|
||||||
|
accessToken,
|
||||||
|
messageId: correlationId,
|
||||||
|
});
|
||||||
|
}).catch((err) => {
|
||||||
|
reject(`Failed to validate token before pairing: ${err}`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public getUserPairingId(): Promise<string> {
|
public getUserPairingId(): Promise<string> {
|
||||||
return new Promise<string>((resolve: (userPairingId: string) => void, reject: (error: string) => void) => {
|
return new Promise<string>((resolve: (userPairingId: string) => void, reject: (error: string) => void) => {
|
||||||
this.checkToken().then(() => {
|
this.checkToken().then(() => {
|
||||||
@ -740,6 +782,17 @@ export default class MessageBus {
|
|||||||
EventBus.getInstance().emit('PUBLIC_DATA_DECODED', correlationId, message.decodedData);
|
EventBus.getInstance().emit('PUBLIC_DATA_DECODED', correlationId, message.decodedData);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'PAIRING_CREATED':
|
||||||
|
if (this.errors[correlationId]) {
|
||||||
|
const error = this.errors[correlationId];
|
||||||
|
delete this.errors[correlationId];
|
||||||
|
EventBus.getInstance().emit('ERROR_PAIRING_CREATED', correlationId, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EventBus.getInstance().emit('MESSAGE_RECEIVED', message);
|
||||||
|
EventBus.getInstance().emit('PAIRING_CREATED', correlationId, message.decodedData);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'ERROR':
|
case 'ERROR':
|
||||||
console.error('Error:', message);
|
console.error('Error:', message);
|
||||||
this.errors[correlationId] = message.error;
|
this.errors[correlationId] = message.error;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user