Skip to content

Commit

Permalink
updated main context wrapper provider prop (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
poocart authored Oct 27, 2023
1 parent d43f60b commit b6ad10f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
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

0 comments on commit b6ad10f

Please sign in to comment.