Skip to content

Commit

Permalink
Merge pull request #2475 from Emurgo/Ahmed/fix-protocol
Browse files Browse the repository at this point in the history
[Dapp-connector]Get the right type of protocol
  • Loading branch information
vsubhuman committed Oct 28, 2021
2 parents 0c6169a + ed2adaf commit 5ea9285
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
6 changes: 4 additions & 2 deletions packages/yoroi-ergo-connector/src/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,14 @@ if (shouldInject()) {
}
// note: content scripts are subject to the same CORS policy as the website they are embedded in
// but since we are querying the website this script is injected into, it should be fine
const protocol = dataType.split('/')[1]
convertImgToBase64(getFavicon(location.origin))
.then(imgBase64Url => {
yoroiPort.postMessage({
imgBase64Url,
type: `yoroi_connect_request/${dataType.split('/')[1]}`,
url: location.hostname
type: `yoroi_connect_request/${protocol}`,
url: location.hostname,
protocol,
});
});
}
Expand Down
28 changes: 13 additions & 15 deletions packages/yoroi-extension/chrome/extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
GetConnectedSitesData,
Tx,
CardanoTx,
GetConnectionProtocolData,
} from './ergo-connector/types';
import {
APIErrorCodes,
Expand Down Expand Up @@ -107,6 +108,7 @@ type PendingSign = {|
|}

let imgBase64Url: string = '';
let connectionProtocol: string = '';

type ConnectedSite = {|
url: string,
Expand Down Expand Up @@ -319,13 +321,14 @@ async function withSelectedWallet<T>(
// messages from other parts of Yoroi (i.e. the UI for the connector)
chrome.runtime.onMessage.addListener(async (
request: (
ConnectResponseData |
ConfirmedSignData |
FailedSignData |
TxSignWindowRetrieveData |
ConnectRetrieveData |
RemoveWalletFromWhitelistData |
GetConnectedSitesData
ConnectResponseData
| ConfirmedSignData
| FailedSignData
| TxSignWindowRetrieveData
| ConnectRetrieveData
| RemoveWalletFromWhitelistData
| GetConnectedSitesData
| GetConnectionProtocolData
),
sender,
sendResponse
Expand Down Expand Up @@ -516,10 +519,9 @@ chrome.runtime.onMessage.addListener(async (
sendResponse(({
sites: activeSites.map(site => site.url),
}: ConnectedSites));
} else if (request.type === 'get_protocol') {
sendResponse({ type: connectionProtocol })
}
// else if (request.type === 'get_protocol') {
// sendResponse({pro: 'ergo'})
// }
});

async function removeWallet(
Expand Down Expand Up @@ -622,12 +624,8 @@ chrome.runtime.onConnectExternal.addListener(port => {
const tabId = port.sender.tab.id;
ports.set(tabId, port);
port.onMessage.addListener(async message => {
chrome.runtime.onMessage.addListener((request,sender, sendResponse) => {
if(request.type === 'get_protocol') {
sendResponse({ type: message.protocol })
}
})

connectionProtocol = message.protocol;
imgBase64Url = message.imgBase64Url;
function rpcResponse(response) {
port.postMessage({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ export type GetConnectedSitesData = {|
type: 'get_connected_sites',
|}

export type GetConnectionProtocolData = {|
type: 'get_protocol',
|}

// when a tx is submitted we mark those as potentially spent and filter
// utxo/balance/etc calls for them until they can be confirmed as spent or not
export type PendingTransaction = {|
Expand Down

0 comments on commit 5ea9285

Please sign in to comment.