Skip to content

Commit

Permalink
make methods wagmi version agnostic (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanmino committed May 13, 2024
1 parent 649c82f commit 23c3e31
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rainbow-me/provider",
"version": "0.0.12",
"version": "0.1.0",
"main": "dist/index.js",
"license": "MIT",
"files": [
Expand Down
6 changes: 3 additions & 3 deletions src/handleProviderRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ describe('handleProviderRequest', () => {
}
}
});
const getChainMock = vi.fn((chainId: number) => {
const getChainNativeCurrencyMock = vi.fn((chainId: number) => {
switch (chainId) {
case 1:
default:
return mainnet;
return mainnet.nativeCurrency;
}
});
const getProviderMock = vi.fn(({ chainId }: { chainId?: number }) => {
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('handleProviderRequest', () => {
checkRateLimit: checkRateLimitMock,
isSupportedChain: isSupportedChainMock,
getActiveSession: getActiveSessionMock,
getChain: getChainMock,
getChainNativeCurrency: getChainNativeCurrencyMock,
getProvider: getProviderMock,
messengerProviderRequest: messengerProviderRequestMock,
onAddEthereumChain: onAddEthereumChainMock,
Expand Down
13 changes: 8 additions & 5 deletions src/handleProviderRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { deriveChainIdByHostname, getDappHost, isValidUrl } from './utils/apps';
import { normalizeTransactionResponsePayload } from './utils/ethereum';
import { recoverPersonalSignature } from '@metamask/eth-sig-util';
import { AddEthereumChainProposedChain, Chain } from './references/chains';
import { AddEthereumChainProposedChain } from './references/chains';
import { Address, isAddress, isHex } from 'viem';
import {
CallbackOptions,
Expand All @@ -18,6 +18,7 @@ import {
import { ActiveSession } from './references/appSession';
import { toHex } from './utils/hex';
import { errorCodes } from './references/errorCodes';
import { ChainNativeCurrency } from 'viem/_types/types/chain';

const buildError = ({
id,
Expand Down Expand Up @@ -47,7 +48,7 @@ export const handleProviderRequest = ({
checkRateLimit,
isSupportedChain,
getActiveSession,
getChain,
getChainNativeCurrency,
getProvider,
messengerProviderRequest,
onAddEthereumChain,
Expand All @@ -67,7 +68,7 @@ export const handleProviderRequest = ({
}) => Promise<{ id: number; error: Error } | undefined>;
isSupportedChain: (chainId: number) => boolean;
getActiveSession: ({ host }: { host: string }) => ActiveSession;
getChain: (chainId: number) => Chain | undefined;
getChainNativeCurrency: (chainId: number) => ChainNativeCurrency | undefined;
getProvider: (options: { chainId?: number }) => Provider;
messengerProviderRequest: (
request: ProviderRequestPayload,
Expand Down Expand Up @@ -300,8 +301,10 @@ export const handleProviderRequest = ({
});
// Validate symbol against existing chains
} else if (isSupportedChain?.(Number(chainId))) {
const knownChain = getChain(Number(chainId));
if (knownChain?.nativeCurrency.symbol !== symbol) {
const knownChainNativeCurrency = getChainNativeCurrency(
Number(chainId),
);
if (knownChainNativeCurrency?.symbol !== symbol) {
return buildError({
id,
message: `nativeCurrency.symbol does not match currency symbol for a network the user already has added with the same chainId. Received: ${symbol}`,
Expand Down

0 comments on commit 23c3e31

Please sign in to comment.