Files
aitbc/extensions/aitbc-wallet-firefox-simple/injected.js
oib 2cb2fbbeda ```
feat: add market stats endpoint, wallet integration, and browser wallet link

- Update devnet genesis timestamp to 1767000206
- Add market statistics endpoint with 24h volume, price change, and payment counts
- Add wallet balance and info API endpoints in exchange router
- Remove unused SessionDep dependencies from exchange endpoints
- Integrate real AITBC wallet extension connection in trade-exchange UI
- Add market data fetching with API fallback for price and volume display
- Add cache-busting query
2025-12-29 18:04:04 +01:00

114 lines
4.4 KiB
JavaScript

// Injected script that provides the AITBC wallet API to the dApp
(function() {
// Create the wallet API object
const aitbcWallet = {
// Check if wallet is available
isAvailable: function() {
return true;
},
// Connect to wallet
connect: async function() {
return new Promise((resolve, reject) => {
const requestId = Date.now().toString();
// Send request to content script
window.postMessage({
type: 'AITBC_WALLET_REQUEST',
id: requestId,
method: 'connect'
}, '*');
// Listen for response
const messageHandler = function(event) {
if (event.data.type === 'AITBC_WALLET_RESPONSE' && event.data.id === requestId) {
window.removeEventListener('message', messageHandler);
console.log('Wallet response received:', event.data);
if (event.data.response && event.data.response.error) {
reject(new Error(event.data.response.error));
} else if (event.data.response && event.data.response.result) {
resolve(event.data.response.result);
} else if (event.data.response) {
resolve(event.data.response);
} else {
reject(new Error('Invalid response from wallet'));
}
}
};
window.addEventListener('message', messageHandler);
// Timeout after 30 seconds
setTimeout(() => {
window.removeEventListener('message', messageHandler);
reject(new Error('Connection timeout'));
}, 30000);
});
},
// Get account address
getAccount: async function() {
const accounts = await this.request({ method: 'accounts' });
return accounts[0];
},
// Get balance
getBalance: async function(address) {
return this.request({ method: 'getBalance', params: { address } });
},
// Send transaction
sendTransaction: async function(to, amount, data = null) {
return this.request({
method: 'sendTransaction',
params: { to, amount, data }
});
},
// Sign message
signMessage: async function(message) {
return this.request({ method: 'signMessage', params: { message } });
},
// Generic request method
request: async function(payload) {
return new Promise((resolve, reject) => {
const requestId = Date.now().toString();
window.postMessage({
type: 'AITBC_WALLET_REQUEST',
id: requestId,
method: payload.method,
params: payload.params || {}
}, '*');
const messageHandler = function(event) {
if (event.data.type === 'AITBC_WALLET_RESPONSE' && event.data.id === requestId) {
window.removeEventListener('message', messageHandler);
if (event.data.response && event.data.response.error) {
reject(new Error(event.data.response.error));
} else if (event.data.response) {
resolve(event.data.response);
} else {
reject(new Error('Invalid response from wallet'));
}
}
};
window.addEventListener('message', messageHandler);
setTimeout(() => {
window.removeEventListener('message', messageHandler);
reject(new Error('Request timeout'));
}, 30000);
});
}
};
// Inject the wallet API into the window object
window.aitbcWallet = aitbcWallet;
// Fire an event to notify the dApp that the wallet is ready
window.dispatchEvent(new Event('aitbcWalletReady'));
})();