-
Notifications
You must be signed in to change notification settings - Fork 161
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
feat: OnchainKitProvider
default dependencies
#1589
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6c46896
hello
0xAlec 367e1af
fix
0xAlec 147d8eb
lint
0xAlec 35688c1
fix
0xAlec 6c0a5f2
fix tests
0xAlec 4a51003
remove WagmiProvider and QueryClientProvider
0xAlec 463edb7
fix
0xAlec 82d355b
`smartWalletOnly` -> `all`
0xAlec e8d109e
fix tests
0xAlec 976f60e
Revert "remove WagmiProvider and QueryClientProvider"
0xAlec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import { createConfig } from 'wagmi'; | ||
import { http } from 'wagmi'; | ||
import { base, baseSepolia } from 'wagmi/chains'; | ||
import { coinbaseWallet } from 'wagmi/connectors'; | ||
import { createWagmiConfig } from './createWagmiConfig'; | ||
|
||
// Mock the imported modules | ||
vi.mock('wagmi', async () => { | ||
const actual = await vi.importActual('wagmi'); | ||
return { | ||
...actual, | ||
createConfig: vi.fn(), | ||
createStorage: vi.fn(), | ||
}; | ||
}); | ||
|
||
vi.mock('wagmi/chains', async () => { | ||
const actual = await vi.importActual('wagmi/chains'); | ||
return { | ||
...actual, | ||
base: { id: 8453 }, | ||
baseSepolia: { id: 84532 }, | ||
}; | ||
}); | ||
|
||
vi.mock('wagmi/connectors', async () => { | ||
const actual = await vi.importActual('wagmi/connectors'); | ||
return { | ||
...actual, | ||
coinbaseWallet: vi.fn(), | ||
}; | ||
}); | ||
|
||
describe('createWagmiConfig', () => { | ||
it('should create config with default values when no parameters are provided', () => { | ||
createWagmiConfig({}); | ||
expect(createConfig).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
chains: [base, baseSepolia], | ||
ssr: true, | ||
transports: { | ||
[base.id]: expect.any(Function), | ||
[baseSepolia.id]: expect.any(Function), | ||
}, | ||
}), | ||
); | ||
expect(coinbaseWallet).toHaveBeenCalledWith({ | ||
appName: undefined, | ||
appLogoUrl: undefined, | ||
preference: 'all', | ||
}); | ||
}); | ||
|
||
it('should create config with custom values when parameters are provided', () => { | ||
const customConfig = { | ||
appearance: { | ||
name: 'Custom App', | ||
logo: 'https://example.com/logo.png', | ||
}, | ||
}; | ||
createWagmiConfig({ | ||
apiKey: 'test-api-key', | ||
appName: customConfig.appearance.name, | ||
appLogoUrl: customConfig.appearance.logo, | ||
}); | ||
expect(createConfig).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
chains: [base, baseSepolia], | ||
ssr: true, | ||
transports: { | ||
[base.id]: expect.any(Function), | ||
[baseSepolia.id]: expect.any(Function), | ||
}, | ||
}), | ||
); | ||
expect(coinbaseWallet).toHaveBeenCalledWith({ | ||
appName: 'Custom App', | ||
appLogoUrl: 'https://example.com/logo.png', | ||
preference: 'all', | ||
}); | ||
}); | ||
|
||
it('should use API key in transports when provided', () => { | ||
const testApiKey = 'test-api-key'; | ||
const result = createWagmiConfig({ apiKey: testApiKey }); | ||
expect(result).toContain( | ||
http(`https://api.developer.coinbase.com/rpc/v1/base/${testApiKey}`), | ||
); | ||
expect(result).toContain( | ||
http( | ||
`https://api.developer.coinbase.com/rpc/v1/base-sepolia/${testApiKey}`, | ||
), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { http, cookieStorage, createConfig, createStorage } from 'wagmi'; | ||
import { base, baseSepolia } from 'wagmi/chains'; | ||
import { coinbaseWallet } from 'wagmi/connectors'; | ||
import type { CreateWagmiConfigParams } from './types'; | ||
|
||
// createWagmiConfig returns a WagmiConfig (https://wagmi.sh/react/api/createConfig) using OnchainKit provided settings. | ||
// This function should only be used if the user does not provide WagmiProvider as a parent in the React context. | ||
export const createWagmiConfig = ({ | ||
apiKey, | ||
appName, | ||
appLogoUrl, | ||
}: CreateWagmiConfigParams) => { | ||
return createConfig({ | ||
chains: [base, baseSepolia], | ||
connectors: [ | ||
coinbaseWallet({ | ||
appName, | ||
appLogoUrl, | ||
preference: 'all', | ||
}), | ||
], | ||
storage: createStorage({ | ||
storage: cookieStorage, | ||
}), | ||
ssr: true, | ||
transports: { | ||
[base.id]: apiKey | ||
? http(`https://api.developer.coinbase.com/rpc/v1/base/${apiKey}`) | ||
: http(), | ||
[baseSepolia.id]: apiKey | ||
? http( | ||
`https://api.developer.coinbase.com/rpc/v1/base-sepolia/${apiKey}`, | ||
) | ||
: http(), | ||
Comment on lines
+27
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uses Base networks by default and sets the RPC as the CDP Node |
||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since Wagmi requires QueryClient, the only time 1 dep is missing should be when there is a QueryClient, but no Wagmi? Seems like an edge case, but would be possible to support this usecase, no? or, should we adjust the console.errors at least to only state using default if both don't exist and otherwise prompt the user to fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if 1 dep is missing, we shouldn't modify the default behavior and allow the app to display the typical error message instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in my mind, if you provide 1 of the 2 deps then it should default to the same logic/behavior as before this PR which is
Unhandled Runtime Error