From 65cb737169ff1f340072ef868747c92e2a0d2e2f Mon Sep 17 00:00:00 2001 From: poocart <7067483+poocart@users.noreply.github.com> Date: Fri, 27 Oct 2023 17:39:05 +0300 Subject: [PATCH] updated main context wrapper provider prop --- CHANGELOG.md | 5 +++++ package-lock.json | 4 ++-- package.json | 2 +- src/providers/EtherspotContextProvider.tsx | 22 +++++++++++++++++----- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae95a01..fde91a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [0.6.6] - 2023-10-27 + +### Added Changes +- Added accepted `provider` to `` component that supports most of providers by Prime SDK + ## [0.6.5] - 2023-10-26 ### Added Changes diff --git a/package-lock.json b/package-lock.json index 1d00540..70917ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@etherspot/transaction-kit", - "version": "0.6.5", + "version": "0.6.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@etherspot/transaction-kit", - "version": "0.6.5", + "version": "0.6.6", "license": "MIT", "dependencies": { "@etherspot/eip1271-verification-util": "^0.1.2", diff --git a/package.json b/package.json index f997cb5..c985c7a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/providers/EtherspotContextProvider.tsx b/src/providers/EtherspotContextProvider.tsx index 8701753..d07dd0f 100644 --- a/src/providers/EtherspotContextProvider.tsx +++ b/src/providers/EtherspotContextProvider.tsx @@ -3,6 +3,7 @@ import { WalletProviderLike, isWalletProvider, Factory, + Web3WalletProvider, } from '@etherspot/prime-sdk'; import React, { ReactNode, @@ -37,10 +38,6 @@ const EtherspotContextProvider = ({ throw new Error(' has already been declared.') } - if (!isWalletProvider(provider)) { - throw new Error('Invalid provider!') - } - useEffect(() => { // reset on provider change sdkPerChain = {}; @@ -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,