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

make methods wagmi version agnostic #16

Merged
merged 2 commits into from
May 13, 2024
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
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
Loading