Skip to content

Commit

Permalink
separate bundler and data services api keys
Browse files Browse the repository at this point in the history
  • Loading branch information
poocart committed Mar 20, 2024
1 parent 13b5028 commit 53def21
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 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.10.0] - 2024-03-20

### Breaking Changes
- Etherspot project keys are now split as `dataApiKey` and `bundlerApiKey` to support separation of bundler and data services, however `TransactionKit` still carries embedded keys with low frequency usage API calls support

## [0.9.2] - 2024-03-20

### Breaking 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.9.2",
"version": "0.10.0",
"main": "dist/cjs/index.js",
"scripts": {
"rollup:build": "NODE_OPTIONS=--max-old-space-size=8192 rollup -c",
Expand Down
3 changes: 2 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export default [
exclude: ['./example/**', './src/test/**']
}),
replace({
__ETHERSPOT_PROJECT_KEY__: process.env.ETHERSPOT_PROJECT_KEY ?? '',
__ETHERSPOT_DATA_API_KEY__: process.env.ETHERSPOT_DATA_API_KEY ?? '',
__ETHERSPOT_BUNDLER_API_KEY__: process.env.ETHERSPOT_BUNDLER_API_KEY ?? '',
preventAssignment: true,
}),
],
Expand Down
9 changes: 6 additions & 3 deletions src/components/EtherspotTransactionKit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ interface EtherspotTransactionKitProps extends React.PropsWithChildren {
provider: WalletProviderLike;
chainId?: number;
accountTemplate?: AccountTemplate;
projectKey?: string;
dataApiKey?: string;
bundlerApiKey?: string;
}

const EtherspotTransactionKit = ({
children,
provider,
chainId = 1,
accountTemplate = Factory.ETHERSPOT,
projectKey,
dataApiKey,
bundlerApiKey,
}: EtherspotTransactionKitProps) => (
<EtherspotContextProvider
provider={provider}
chainId={+chainId} // cast to make it less failproof when passed as string, i.e. from env file
accountTemplate={accountTemplate}
projectKey={projectKey}
dataApiKey={dataApiKey}
bundlerApiKey={bundlerApiKey}
>
<EtherspotTransactionKitContextProvider>
<ProviderWalletContextProvider>
Expand Down
14 changes: 8 additions & 6 deletions src/providers/EtherspotContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ const EtherspotContextProvider = ({
provider,
chainId,
accountTemplate,
projectKey,
dataApiKey,
bundlerApiKey,
}: {
children: ReactNode;
provider: WalletProviderLike;
chainId: number;
accountTemplate: AccountTemplate;
projectKey?: string;
dataApiKey?: string;
bundlerApiKey?: string;
}) => {
const context = useContext(EtherspotContext);

Expand Down Expand Up @@ -68,7 +70,7 @@ const EtherspotContextProvider = ({
// @ts-ignore
const sdkForChain = new PrimeSdk(mappedProvider ?? provider, {
chainId: +sdkChainId,
etherspotBundlerApiKey: projectKey ?? ('__ETHERSPOT_PROJECT_KEY__' || undefined),
etherspotBundlerApiKey: bundlerApiKey ?? ('__ETHERSPOT_BUNDLER_API_KEY__' || undefined),
factoryWallet: accountTemplate as Factory,
});

Expand All @@ -81,13 +83,13 @@ const EtherspotContextProvider = ({
await sdkForChain.getCounterFactualAddress();

return sdkForChain;
}, [provider, chainId, accountTemplate, projectKey]);
}, [provider, chainId, accountTemplate, bundlerApiKey]);

const getDataService = useCallback(() => {
if (dataService) return dataService;
dataService = new DataUtils(projectKey ?? ('__ETHERSPOT_PROJECT_KEY__' || undefined));
dataService = new DataUtils(dataApiKey ?? ('__ETHERSPOT_DATA_API_KEY__' || undefined));
return dataService;
}, [projectKey]);
}, [dataApiKey]);

const contextData = useMemo(() => ({
getSdk,
Expand Down

0 comments on commit 53def21

Please sign in to comment.