Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const handleBitcoinCashRequest = async (
chrome.runtime.sendMessage({ action: 'utxo_build_tx', unsignedTx: requestInfo });
} catch (e) {
console.error(e);
chrome.runtime.sendMessage({ action: 'transaction_error', error: JSON.stringify(e) });
chrome.runtime.sendMessage({ action: 'transaction_error', eventId: requestInfo.id, error: JSON.stringify(e) });
}
};
buildTx();
Expand Down Expand Up @@ -104,6 +104,7 @@ export const handleBitcoinCashRequest = async (
await requestStorage.updateEventById(requestInfo.id, response);
chrome.runtime.sendMessage({
action: 'transaction_complete',
eventId: requestInfo.id,
txHash,
explorerTxLink: 'https://blockchair.com/bitcoin-cash/transaction/',
});
Expand Down
3 changes: 3 additions & 0 deletions chrome-extension/src/background/chains/bitcoinHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const handleBitcoinRequest = async (
console.error(e);
chrome.runtime.sendMessage({
action: 'transaction_error',
eventId: requestInfo.id,
error: JSON.stringify(e),
});
}
Expand Down Expand Up @@ -145,6 +146,7 @@ export const handleBitcoinRequest = async (

chrome.runtime.sendMessage({
action: 'transaction_complete',
eventId: requestInfo.id,
txHash: txHash,
explorerTxLink: 'https://mempool.space/tx/',
});
Expand All @@ -153,6 +155,7 @@ export const handleBitcoinRequest = async (
console.error(tag, e);
chrome.runtime.sendMessage({
action: 'transaction_error',
eventId: requestInfo.id,
error: JSON.stringify(e),
});
}
Expand Down
1 change: 1 addition & 0 deletions chrome-extension/src/background/chains/cosmosHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const handleCosmosRequest = async (
await requestStorage.updateEventById(requestInfo.id, response);
chrome.runtime.sendMessage({
action: 'transaction_complete',
eventId: requestInfo.id,
txHash,
explorerTxLink: 'https://www.mintscan.io/cosmos/tx/',
});
Expand Down
3 changes: 2 additions & 1 deletion chrome-extension/src/background/chains/dashHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const handleDashRequest = async (
chrome.runtime.sendMessage({ action: 'utxo_build_tx', unsignedTx: requestInfo });
} catch (e) {
console.error(e);
chrome.runtime.sendMessage({ action: 'transaction_error', error: JSON.stringify(e) });
chrome.runtime.sendMessage({ action: 'transaction_error', eventId: requestInfo.id, error: JSON.stringify(e) });
}
};
buildTx();
Expand Down Expand Up @@ -104,6 +104,7 @@ export const handleDashRequest = async (
await requestStorage.updateEventById(requestInfo.id, response);
chrome.runtime.sendMessage({
action: 'transaction_complete',
eventId: requestInfo.id,
txHash,
explorerTxLink: 'https://blockchair.com/dash/transaction/',
});
Expand Down
3 changes: 2 additions & 1 deletion chrome-extension/src/background/chains/dogecoinHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const handleDogecoinRequest = async (
chrome.runtime.sendMessage({ action: 'utxo_build_tx', unsignedTx: requestInfo });
} catch (e) {
console.error(e);
chrome.runtime.sendMessage({ action: 'transaction_error', error: JSON.stringify(e) });
chrome.runtime.sendMessage({ action: 'transaction_error', eventId: requestInfo.id, error: JSON.stringify(e) });
}
};
buildTx();
Expand Down Expand Up @@ -107,6 +107,7 @@ export const handleDogecoinRequest = async (
await requestStorage.updateEventById(requestInfo.id, response);
chrome.runtime.sendMessage({
action: 'transaction_complete',
eventId: requestInfo.id,
txHash,
explorerTxLink: 'https://blockchair.com/dogecoin/transaction/',
});
Expand Down
54 changes: 9 additions & 45 deletions chrome-extension/src/background/chains/ethereumHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,46 +74,6 @@ type Event = {
timestamp: string;
};

let isPopupOpen = false; // Flag to track popup state

const openPopup = function () {
const tag = TAG + ' | openPopup | ';
try {
console.log(tag, 'Opening popup');
chrome.windows.create(
{
url: chrome.runtime.getURL('popup/index.html'), // Adjust the URL to your popup file
type: 'popup',
width: 400,
height: 600,
},
window => {
if (chrome.runtime.lastError) {
console.error('Error creating popup:', chrome.runtime.lastError);
isPopupOpen = false;
} else {
console.log('Popup window created:', window);

// Optionally, handle the popup window focus or other behaviors
}
},
);
} catch (e) {
console.error(tag, e);
}
};

const requireUnlock = async function () {
const tag = TAG + ' | requireUnlock | ';
try {
console.log(tag, 'requireUnlock for domain');
openPopup();
} catch (e) {
console.error(e);
isPopupOpen = false;
}
};

const convertHexToDecimalChainId = (hexChainId: string): number => {
return parseInt(hexChainId, 16);
};
Expand Down Expand Up @@ -757,6 +717,7 @@ const handleTransfer = async (params, requestInfo, ADDRESS, KEEPKEY_WALLET, requ
// Notify transaction completion
chrome.runtime.sendMessage({
action: 'transaction_complete',
eventId: requestInfo.id,
txHash: txid,
explorerTxLink: currentProviderCtx?.explorerTxLink,
networkId,
Expand Down Expand Up @@ -890,18 +851,18 @@ const processApprovedEvent = async (method: string, params: any, KEEPKEY_WALLET:
case 'personal_sign':
// EIP-191 personal_sign: params = [message, address]. Prefer the dApp-supplied
// address so multi-account wallets sign with the correct derivation path.
result = await signMessage(params[0], KEEPKEY_WALLET, params[1] || ADDRESS);
result = await signMessage(params[0], KEEPKEY_WALLET, params[1] || ADDRESS, id);
break;
case 'eth_sign':
result = await signMessage(params[1], KEEPKEY_WALLET, params[0]);
result = await signMessage(params[1], KEEPKEY_WALLET, params[0], id);
break;
case 'eth_sendTransaction':
result = await sendTransaction(params, KEEPKEY_WALLET, ADDRESS, id);
break;
case 'eth_signTypedData':
case 'eth_signTypedData_v3':
case 'eth_signTypedData_v4':
result = await signTypedData(params, KEEPKEY_WALLET, ADDRESS);
result = await signTypedData(params, KEEPKEY_WALLET, ADDRESS, id);
break;
case 'eth_signTransaction':
result = await signTransaction(params[0], KEEPKEY_WALLET);
Expand All @@ -919,7 +880,7 @@ const processApprovedEvent = async (method: string, params: any, KEEPKEY_WALLET:
}
};

const signMessage = async (message, KEEPKEY_WALLET, ADDRESS: string) => {
const signMessage = async (message, KEEPKEY_WALLET, ADDRESS: string, eventId?: string) => {
const tag = TAG + ' [signMessage] ';
try {
console.log(tag, '**** message: ', message);
Expand Down Expand Up @@ -947,6 +908,7 @@ const signMessage = async (message, KEEPKEY_WALLET, ADDRESS: string) => {
// Notify popup that signature is complete
chrome.runtime.sendMessage({
action: 'signature_complete',
eventId,
signature: signatureHex,
});

Expand Down Expand Up @@ -1091,7 +1053,7 @@ const signTransaction = async (transaction: any, KEEPKEY_WALLET: any) => {
}
};

const signTypedData = async (params: any, KEEPKEY_WALLET: any, ADDRESS: string) => {
const signTypedData = async (params: any, KEEPKEY_WALLET: any, ADDRESS: string, eventId?: string) => {
const tag = ' | signTypedData | ';
try {
console.log(tag, '**** params: ', params);
Expand All @@ -1116,6 +1078,7 @@ const signTypedData = async (params: any, KEEPKEY_WALLET: any, ADDRESS: string)
// Notify popup that signature is complete
chrome.runtime.sendMessage({
action: 'signature_complete',
eventId,
signature: signatureHex,
});

Expand Down Expand Up @@ -1204,6 +1167,7 @@ const sendTransaction = async (params: any, KEEPKEY_WALLET: any, ADDRESS: string
//push event
chrome.runtime.sendMessage({
action: 'transaction_complete',
eventId: id,
txHash: txHash,
explorerTxLink: currentProvider.explorerTxLink,
networkId: currentProvider.networkId,
Expand Down
3 changes: 2 additions & 1 deletion chrome-extension/src/background/chains/litecoinHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const handleLitecoinRequest = async (
chrome.runtime.sendMessage({ action: 'utxo_build_tx', unsignedTx: requestInfo });
} catch (e) {
console.error(e);
chrome.runtime.sendMessage({ action: 'transaction_error', error: JSON.stringify(e) });
chrome.runtime.sendMessage({ action: 'transaction_error', eventId: requestInfo.id, error: JSON.stringify(e) });
}
};
buildTx();
Expand Down Expand Up @@ -104,6 +104,7 @@ export const handleLitecoinRequest = async (
await requestStorage.updateEventById(requestInfo.id, response);
chrome.runtime.sendMessage({
action: 'transaction_complete',
eventId: requestInfo.id,
txHash,
explorerTxLink: 'https://blockchair.com/litecoin/transaction/',
});
Expand Down
1 change: 1 addition & 0 deletions chrome-extension/src/background/chains/mayaHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const handleMayaRequest = async (
await requestStorage.updateEventById(requestInfo.id, response);
chrome.runtime.sendMessage({
action: 'transaction_complete',
eventId: requestInfo.id,
txHash,
explorerTxLink: 'https://www.mayascan.org/tx/',
});
Expand Down
1 change: 1 addition & 0 deletions chrome-extension/src/background/chains/osmosisHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const handleOsmosisRequest = async (
await requestStorage.updateEventById(requestInfo.id, response);
chrome.runtime.sendMessage({
action: 'transaction_complete',
eventId: requestInfo.id,
txHash,
explorerTxLink: 'https://www.mintscan.io/osmosis/tx/',
});
Expand Down
1 change: 1 addition & 0 deletions chrome-extension/src/background/chains/rippleHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const handleRippleRequest = async (
await requestStorage.updateEventById(requestInfo.id, response);
chrome.runtime.sendMessage({
action: 'transaction_complete',
eventId: requestInfo.id,
txHash,
explorerTxLink: 'https://xrpscan.com/tx/',
});
Expand Down
10 changes: 7 additions & 3 deletions chrome-extension/src/background/chains/solanaHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ async function getSolanaAddress(): Promise<string> {

/** Build the event object for popup approval flow */
function buildEvent(requestInfo: any, method: string, params: any[]) {
// Ensure requestInfo.id is set so callers downstream (including message payloads
// that tag chrome.runtime events with eventId) reference the same id we store.
if (!requestInfo.id) requestInfo.id = uuidv4();
return {
id: requestInfo.id || uuidv4(),
id: requestInfo.id,
networkId: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
chain: 'solana',
href: requestInfo.href,
Expand Down Expand Up @@ -373,7 +376,7 @@ export const handleSolanaRequest = async (
const messageBase64 = toBase64(messageArray);
const signatureArray = await signMessageViaRest(messageBase64);

chrome.runtime.sendMessage({ action: 'signature_complete' }).catch(() => {});
chrome.runtime.sendMessage({ action: 'signature_complete', eventId: requestInfo.id }).catch(() => {});
return signatureArray;
}

Expand All @@ -393,7 +396,7 @@ export const handleSolanaRequest = async (
// Return the fully signed transaction (vault replaces dummy sig at bytes 1-64)
const signedTxArray = fromBase64(txSignResult.serializedTx);

chrome.runtime.sendMessage({ action: 'signature_complete' }).catch(() => {});
chrome.runtime.sendMessage({ action: 'signature_complete', eventId: requestInfo.id }).catch(() => {});
return signedTxArray;
}

Expand All @@ -417,6 +420,7 @@ export const handleSolanaRequest = async (
chrome.runtime
.sendMessage({
action: 'transaction_complete',
eventId: requestInfo.id,
txHash: txSignature,
explorerTxLink: 'https://solscan.io/tx/',
networkId: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const handleThorchainRequest = async (
await requestStorage.updateEventById(requestInfo.id, response);
chrome.runtime.sendMessage({
action: 'transaction_complete',
eventId: requestInfo.id,
txHash,
explorerTxLink: 'https://runescan.io/tx/',
});
Expand Down
Loading
Loading