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

updated main context wrapper provider prop #67

Merged
merged 1 commit into from
Oct 27, 2023
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [0.6.6] - 2023-10-27

### Added Changes
- Added accepted `provider` to `<EtherspotTransactionKit />` component that supports most of providers by Prime SDK

## [0.6.5] - 2023-10-26

### Added Changes
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@etherspot/transaction-kit",
"description": "React Etherspot Transaction Kit",
"version": "0.6.5",
"version": "0.6.6",
"main": "dist/cjs/index.js",
"scripts": {
"rollup:build": "NODE_OPTIONS=--max-old-space-size=8192 rollup -c",
Expand Down
22 changes: 17 additions & 5 deletions src/providers/EtherspotContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
WalletProviderLike,
isWalletProvider,
Factory,
Web3WalletProvider,
} from '@etherspot/prime-sdk';
import React, {
ReactNode,
Expand Down Expand Up @@ -37,10 +38,6 @@ const EtherspotContextProvider = ({
throw new Error('<EtherspotContextProvider /> has already been declared.')
}

if (!isWalletProvider(provider)) {
throw new Error('Invalid provider!')
}

useEffect(() => {
// reset on provider change
sdkPerChain = {};
Expand All @@ -49,7 +46,22 @@ const EtherspotContextProvider = ({
const getSdk = useCallback(async (sdkChainId: number = chainId, forceNewInstance: boolean = false) => {
if (sdkPerChain[sdkChainId] && !forceNewInstance) return sdkPerChain[sdkChainId];

const sdkForChain = new PrimeSdk(provider, {
let mappedProvider;
if (!isWalletProvider(provider)) {
try {
// @ts-ignore
mappedProvider = new Web3WalletProvider(provider);
await mappedProvider.refresh();
} catch (e) {
// no need to log, this is an attempt
}

if (!mappedProvider) {
throw new Error('Invalid provider!');
}
}

const sdkForChain = new PrimeSdk(mappedProvider ?? provider, {
chainId: sdkChainId,
projectKey: '__ETHERSPOT_PROJECT_KEY__' || undefined,
factoryWallet: accountTemplate as Factory,
Expand Down