Update dependencies and enhance App component functionality
- Added new dependencies: @polkadot/util and @gear-js/api to package.json and example/package.json. - Implemented a test function in App component to interact with GearApi for balance transfer. - Updated transaction signing logic to support both raw and payload types. - Refactored Wallet class to improve socket connection handling and transaction management. - Enhanced WalletStore by removing unnecessary listener setup code.
This commit is contained in:
1 parent
deae91a3e6
commit
4b7a39d332
12 files changed
+1347
-204
No files matched your search
+65
@@ -0,0 +1,65 @@
|
||||
import type {
|
||||
ServerMessage,
|
||||
ConnectResponseMessage,
|
||||
SignTransactionResponseMessage
|
||||
} from './socket';
|
||||
|
||||
const API_URL = 'https://connect.varan.app';
|
||||
|
||||
/**
|
||||
* Sends a connect response message to the API
|
||||
* This will be received by the client's WebSocket and handled by the socket
|
||||
* @param message The connect response message
|
||||
* @param connectionId The unique connection ID from WebSocket
|
||||
* @returns Promise resolving when the message is sent
|
||||
*/
|
||||
export async function sendConnect(
|
||||
message: ConnectResponseMessage,
|
||||
connectionId: string,
|
||||
): Promise<void> {
|
||||
await sendServerMessage(message, connectionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a signed transaction response message to the API
|
||||
* This will be received by the client's WebSocket and handled by the socket
|
||||
* @param message The sign transaction response message
|
||||
* @param connectionId The unique connection ID from WebSocket
|
||||
* @returns Promise resolving when the message is sent
|
||||
*/
|
||||
export async function sendSignedTransaction(
|
||||
message: SignTransactionResponseMessage,
|
||||
connectionId: string,
|
||||
): Promise<void> {
|
||||
await sendServerMessage(message, connectionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends any server message to the API
|
||||
* This will be received by the client's WebSocket and handled by the socket
|
||||
* @param message The server message to send
|
||||
* @param connectionId The unique connection ID from WebSocket
|
||||
* @returns Promise resolving when the message is sent
|
||||
*/
|
||||
async function sendServerMessage(
|
||||
message: ServerMessage,
|
||||
connectionId: string,
|
||||
): Promise<void> {
|
||||
try {
|
||||
const response = await fetch(`${API_URL}/send/${connectionId}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(message),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[VARANINJECT] Error sending server message:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user