Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: treat BTC as known network #37

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -105,7 +105,30 @@ describe('background/services/network/handlers/wallet_addEthereumChain.ts', () =
},
],
};
openExtensionNewWindow;
const supportedNetwork = {
caipId: 'eip155:43113',
chainId: 43113,
chainName: 'Avalanche',
vmName: NetworkVMType.EVM,
primaryColor: 'black',
rpcUrl: 'https://api.avax.network/ext/bc/C/rpc',
explorerUrl: 'https://snowtrace.io/',
logoUri: '',
networkToken: {
symbol: 'AVAX',
decimals: 18,
description: '',
name: 'AVAX',
logoUri: '',
},
isTestnet: false,
};

jest
.mocked(mockNetworkService.getNetwork)
.mockResolvedValueOnce(mockActiveNetwork as any)
.mockResolvedValueOnce(supportedNetwork);

const result = await handler.handleUnauthenticated(buildRpcCall(request));

expect(openExtensionNewWindow).toHaveBeenCalledTimes(1);
Expand All @@ -118,24 +141,7 @@ describe('background/services/network/handlers/wallet_addEthereumChain.ts', () =
actionId: 'uuid',
scope: 'eip155:43113',
displayData: {
network: {
caipId: 'eip155:43113',
chainId: 43113,
chainName: 'Avalanche',
vmName: NetworkVMType.EVM,
primaryColor: 'black',
rpcUrl: 'https://api.avax.network/ext/bc/C/rpc',
explorerUrl: 'https://snowtrace.io/',
logoUri: '',
networkToken: {
symbol: 'AVAX',
decimals: 18,
description: '',
name: 'AVAX',
logoUri: '',
},
isTestnet: false,
},
network: supportedNetwork,
},
popupWindowId: 123,
});
Expand Down Expand Up @@ -536,26 +542,30 @@ describe('background/services/network/handlers/wallet_addEthereumChain.ts', () =
it('does not opens approval dialog and switch to a known network if the request is from core web', async () => {
jest.mocked(isCoreWeb).mockResolvedValue(true);

const supportedNetwork = {
chainId: '0xa869', // 43113
chainName: 'Avalanche',
nativeCurrency: { name: 'AVAX', symbol: 'AVAX', decimals: 18 },
rpcUrls: ['https://api.avax.network/ext/bc/C/rpc'],
blockExplorerUrls: ['https://snowtrace.io/'],
iconUrls: ['logo.png'],
};
const request = {
id: '852',
method: DAppProviderRequest.WALLET_ADD_CHAIN,
params: [
{
chainId: '0xa869', // 43113
chainName: 'Avalanche',
nativeCurrency: { name: 'AVAX', symbol: 'AVAX', decimals: 18 },
rpcUrls: ['https://api.avax.network/ext/bc/C/rpc'],
blockExplorerUrls: ['https://snowtrace.io/'],
iconUrls: ['logo.png'],
},
],
params: [supportedNetwork],
site: {
domain: 'core.app',
name: 'Core',
tabId: 123,
},
};

jest
.mocked(mockNetworkService.getNetwork)
.mockResolvedValueOnce(mockActiveNetwork as any)
.mockResolvedValueOnce(supportedNetwork as any);

const result = await handler.handleAuthenticated(buildRpcCall(request));

expect(result).toEqual({
Expand All @@ -568,9 +578,7 @@ describe('background/services/network/handlers/wallet_addEthereumChain.ts', () =
expect(mockNetworkService.setNetwork).toHaveBeenCalledTimes(1);
expect(mockNetworkService.setNetwork).toHaveBeenCalledWith(
'core.app',
expect.objectContaining({
chainId: 43113,
})
supportedNetwork
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,14 @@ export class WalletAddEthereumChainHandler extends DAppRequestHandler {
}
const skipApproval = await isCoreWeb(request);

const targetNetwork = chainRequestedIsSupported
gergelylovas marked this conversation as resolved.
Show resolved Hide resolved
? ((await this.networkService.getNetwork(
requestedChainId
)) as NetworkWithCaipId)
: customNetwork;

if (skipApproval) {
await this.actionHandler(chains, customNetwork, request.site.domain);
await this.actionHandler(chains, targetNetwork, request.site.domain);
return { ...request, result: null };
}

Expand All @@ -128,7 +134,7 @@ export class WalletAddEthereumChainHandler extends DAppRequestHandler {
...request,
scope,
displayData: {
network: customNetwork,
network: targetNetwork,
},
};

Expand Down
Loading