Update transaction details and enhance logging in App component
- Changed the recipient address in the balance transfer transaction. - Added logging for the result of the transaction in a human-readable format.
This commit is contained in:
1 parent
54c2c2141f
commit
a1aadf8fbc
3 files changed
+39
-58
No files matched your search
+2
-1
@@ -34,11 +34,12 @@ function App() {
|
||||
}
|
||||
const apiPromise = new GearApi({ providerAddress: 'wss://rpc.vara.network' });
|
||||
await apiPromise.isReady;
|
||||
const tx = apiPromise.balance.transfer('kGi1Ui7VXBFmPmaoMD5xgWd2VHNixZ5BbLNhHFYD39T85rUi3', 100)
|
||||
const tx = apiPromise.balance.transfer('kGgMeagrS8yiLMech46HKYGBti5bxyQ5VrRYyD2EgTDvY9jj2', 100)
|
||||
console.log('[VARANINJECT] tx', tx);
|
||||
// @ts-expect-error - signer is not typed
|
||||
const result = await tx.signAndSend(address, { signer: extension?.signer })
|
||||
console.log('[VARANINJECT] result', result);
|
||||
console.log('[VARANINJECT] result toHuman', result.toHuman());
|
||||
}
|
||||
|
||||
const signTransaction = async () => {
|
||||
|
||||
+5
-13
@@ -20,7 +20,7 @@ export interface AcknowledgmentMessage extends WebSocketMessage {
|
||||
// Server message wrapper - contains actual message data
|
||||
export interface ServerMessageWrapper extends WebSocketMessage {
|
||||
type: 'server_message';
|
||||
message: ServerMessage;
|
||||
data: ServerMessage;
|
||||
}
|
||||
|
||||
// Data message wrapper - contains data payload
|
||||
@@ -183,21 +183,16 @@ export class WalletSocket {
|
||||
if (message.type === 'connection' && message.id) {
|
||||
const connMessage = message as ConnectionMessage;
|
||||
this.uniqueId = connMessage.id;
|
||||
console.log(`[VARANINJECT] Unique ID received: ${this.uniqueId}`);
|
||||
// Resolve connection promise if pending
|
||||
if (this.connectionResolve) {
|
||||
this.connectionResolve();
|
||||
}
|
||||
} else if (message.type === 'acknowledgment') {
|
||||
console.log('[VARANINJECT] Data acknowledged by server');
|
||||
} else if (message.type === 'server_message') {
|
||||
console.log('[VARANINJECT] Received server message');
|
||||
const serverWrapper = message as ServerMessageWrapper;
|
||||
if (serverWrapper.message) {
|
||||
this.handleServerMessage(serverWrapper.message);
|
||||
if (serverWrapper.data) {
|
||||
this.handleServerMessage(serverWrapper.data);
|
||||
}
|
||||
} else if (message.type === 'data' && message.data) {
|
||||
console.log('[VARANINJECT] Received data message');
|
||||
const dataWrapper = message as DataMessageWrapper;
|
||||
if (dataWrapper.data) {
|
||||
// Type guard to ensure data is a ServerMessage
|
||||
@@ -226,16 +221,13 @@ export class WalletSocket {
|
||||
}
|
||||
|
||||
async send(data: ClientRequest): Promise<void> {
|
||||
const id = await this.ensureConnected();
|
||||
// const id = await this.ensureConnected();
|
||||
|
||||
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
||||
throw new Error('WebSocket is not connected');
|
||||
}
|
||||
|
||||
const message = {
|
||||
...data,
|
||||
id,
|
||||
};
|
||||
const message = data;
|
||||
|
||||
this.ws.send(JSON.stringify(message));
|
||||
}
|
||||
|
||||
+32
-44
@@ -39,35 +39,6 @@ export class Wallet implements InjectedWindowProvider {
|
||||
private async _initializeSocket(): Promise<void> {
|
||||
try {
|
||||
await this.socket.connect();
|
||||
|
||||
// Listen for wallet connection messages
|
||||
this.socket.onMessage<ConnectResponseMessage>('connect', (data) => {
|
||||
if (data.success && data.wallets && Array.isArray(data.wallets)) {
|
||||
const allWallets = Array.from(
|
||||
new Set(
|
||||
this.store.get('accounts').concat(data.wallets)
|
||||
)
|
||||
);
|
||||
this.store.set('accounts', allWallets);
|
||||
}
|
||||
});
|
||||
|
||||
// Listen for transaction signing responses
|
||||
this.socket.onMessage<SignTransactionResponseMessage>('signTransaction', (data) => {
|
||||
const currentTransactions = this.store.get('transactions');
|
||||
const pendingTransactionIndex = currentTransactions.findIndex(
|
||||
t => t.id === data.id && t.status === 'signing'
|
||||
);
|
||||
|
||||
if (pendingTransactionIndex !== -1) {
|
||||
currentTransactions[pendingTransactionIndex] = {
|
||||
...currentTransactions[pendingTransactionIndex],
|
||||
status: data.success ? 'success' : 'failed',
|
||||
signedTx: data.signedTx || '',
|
||||
};
|
||||
this.store.set('transactions', currentTransactions);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('[VARANINJECT] Error initializing socket:', error);
|
||||
}
|
||||
@@ -120,10 +91,9 @@ export class Wallet implements InjectedWindowProvider {
|
||||
method: 'sT',
|
||||
tx: `p:${JSON.stringify(payload)}`,
|
||||
id: requestId,
|
||||
wallet: payload.address,
|
||||
};
|
||||
|
||||
console.log('[VARANINJECT] signPayloadTransaction request', request);
|
||||
|
||||
// Store transaction as pending
|
||||
const currentTransactions = this.store.get('transactions');
|
||||
currentTransactions.push({
|
||||
@@ -134,7 +104,7 @@ export class Wallet implements InjectedWindowProvider {
|
||||
this.store.set('transactions', currentTransactions);
|
||||
|
||||
// Send via WebSocket
|
||||
await this.socket.sendViaAPI(request);
|
||||
await this.socket.send(request);
|
||||
|
||||
const botUrl = `${this.varanWalletUrl}${this.socket.getUniqueId()}`;
|
||||
|
||||
@@ -148,12 +118,20 @@ export class Wallet implements InjectedWindowProvider {
|
||||
|
||||
const currentTransactions = this.store.get('transactions');
|
||||
const transaction = currentTransactions.find(t => t.id === requestId);
|
||||
const pendingTransactionIndex = currentTransactions.findIndex(t => t.id === requestId);
|
||||
|
||||
if (transaction && transaction.status !== 'signing') {
|
||||
if (transaction.status === 'success') {
|
||||
if (transaction && transaction.status === 'signing') {
|
||||
currentTransactions[pendingTransactionIndex] = {
|
||||
...currentTransactions[pendingTransactionIndex],
|
||||
status: data.success ? 'success' : 'failed',
|
||||
signedTx: data.signedTx || '',
|
||||
};
|
||||
this.store.set('transactions', currentTransactions);
|
||||
|
||||
if (data.success) {
|
||||
resolve({
|
||||
id: transaction.id,
|
||||
signature: transaction.signedTx,
|
||||
id: data.id,
|
||||
signature: data.signedTx,
|
||||
} as SignerResult);
|
||||
} else {
|
||||
reject(new Error('Transaction signing failed'));
|
||||
@@ -166,7 +144,6 @@ export class Wallet implements InjectedWindowProvider {
|
||||
|
||||
private async signRawTransaction(raw: SignerPayloadRaw): Promise<SignerResult> {
|
||||
if (raw.type === 'payload') {
|
||||
console.log('[VARANINJECT] signRawTransaction payload', raw.data);
|
||||
return this.signPayloadTransaction(JSON.parse(raw.data));
|
||||
}
|
||||
|
||||
@@ -194,7 +171,9 @@ export class Wallet implements InjectedWindowProvider {
|
||||
this.store.set('transactions', currentTransactions);
|
||||
|
||||
// Send via WebSocket
|
||||
await this.socket.sendViaAPI(request);
|
||||
await this.socket.send(request);
|
||||
|
||||
await this.webApp.openTelegramLink(`${this.varanWalletUrl}${this.socket.getUniqueId()}`);
|
||||
|
||||
// Wait for response
|
||||
return new Promise<SignerResult>((resolve, reject) => {
|
||||
@@ -203,13 +182,21 @@ export class Wallet implements InjectedWindowProvider {
|
||||
unsubscribe();
|
||||
|
||||
const currentTransactions = this.store.get('transactions');
|
||||
const transaction = currentTransactions.find(t => t.id === requestId);
|
||||
const pendingTransactionIndex = currentTransactions.findIndex(t => t.id === requestId);
|
||||
const transaction = currentTransactions[pendingTransactionIndex];
|
||||
|
||||
if (transaction && transaction.status !== 'signing') {
|
||||
if (transaction.status === 'success') {
|
||||
if (transaction && transaction.status === 'signing') {
|
||||
currentTransactions[pendingTransactionIndex] = {
|
||||
...currentTransactions[pendingTransactionIndex],
|
||||
status: data.success ? 'success' : 'failed',
|
||||
signedTx: data.signedTx || '',
|
||||
};
|
||||
this.store.set('transactions', currentTransactions);
|
||||
|
||||
if (data.success) {
|
||||
resolve({
|
||||
id: transaction.id,
|
||||
signature: transaction.signedTx,
|
||||
id: data.id,
|
||||
signature: data.signedTx,
|
||||
} as SignerResult);
|
||||
} else {
|
||||
reject(new Error('Transaction signing failed'));
|
||||
@@ -226,7 +213,7 @@ export class Wallet implements InjectedWindowProvider {
|
||||
await this.socket.connect();
|
||||
|
||||
// Send connect request via WebSocket
|
||||
await this.socket.sendViaAPI({
|
||||
await this.socket.send({
|
||||
method: 'connect',
|
||||
} as ConnectRequest);
|
||||
|
||||
@@ -237,6 +224,7 @@ export class Wallet implements InjectedWindowProvider {
|
||||
return new Promise<void>((resolve) => {
|
||||
const unsubscribe = this.socket.onMessage<ConnectResponseMessage>('connect', (data) => {
|
||||
if (data.success && data.wallets && data.wallets.length > 0) {
|
||||
this.store.set('accounts', data.wallets);
|
||||
unsubscribe();
|
||||
resolve();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user