```
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
This commit is contained in:
106
extensions/aitbc-wallet/injected.js
Normal file
106
extensions/aitbc-wallet/injected.js
Normal file
@@ -0,0 +1,106 @@
|
||||
// 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);
|
||||
if (event.data.response.error) {
|
||||
reject(new Error(event.data.response.error));
|
||||
} else {
|
||||
resolve(event.data.response);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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.error) {
|
||||
reject(new Error(event.data.response.error));
|
||||
} else {
|
||||
resolve(event.data.response);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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'));
|
||||
})();
|
||||
Reference in New Issue
Block a user