diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 0000000..2e08217
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,101 @@
+{
+ "env": {
+ "browser": true,
+ "es2021": true,
+ "node": true
+ },
+ "extends": [
+ "eslint:recommended",
+ "plugin:@typescript-eslint/recommended",
+ "plugin:react/recommended",
+ "plugin:react-hooks/recommended",
+ "plugin:import/recommended",
+ "plugin:import/typescript",
+ "plugin:react/jsx-runtime",
+ "airbnb",
+ "airbnb-typescript",
+ "airbnb/hooks",
+ "plugin:prettier/recommended",
+ "prettier"
+ ],
+ "overrides": [
+ {
+ "env": {
+ "node": true
+ },
+ "files": [".eslintrc.{js,cjs}"],
+ "parserOptions": {
+ "sourceType": "script"
+ }
+ }
+ ],
+ "parser": "@typescript-eslint/parser",
+ "parserOptions": {
+ "ecmaVersion": "latest",
+ "sourceType": "module",
+ "project": "./tsconfig.json"
+ },
+ "plugins": [
+ "@typescript-eslint",
+ "react",
+ "react-hooks",
+ "import",
+ "prettier"
+ ],
+ "rules": {
+ "import/no-named-as-default-member": "off",
+ "import/no-named-as-default": "off",
+ "no-console": [
+ "error",
+ {
+ "allow": ["warn", "error"]
+ }
+ ],
+ "quotes": ["error", "single"],
+ "prettier/prettier": "error",
+ "react/jsx-filename-extension": [
+ 1,
+ {
+ "extensions": [".jsx", ".tsx"]
+ }
+ ],
+ "import/prefer-default-export": "off",
+ "react/react-in-jsx-scope": "off",
+ "@typescript-eslint/no-unused-vars": "error",
+ "import/extensions": [
+ "error",
+ "ignorePackages",
+ {
+ "ts": "never",
+ "tsx": "never",
+ "jsx": "never",
+ "js": "never"
+ }
+ ],
+ "react/function-component-definition": [
+ 2,
+ {
+ "namedComponents": ["function-declaration", "arrow-function"],
+ "unnamedComponents": "function-expression"
+ }
+ ],
+ "react/require-default-props": "off",
+ "react/no-array-index-key": "off",
+ "jsx-a11y/click-events-have-key-events": "off",
+ "jsx-a11y/no-static-element-interactions": "off",
+ "no-plusplus": "off"
+ },
+ "ignorePatterns": [
+ "node_modules/",
+ "build/",
+ "__tests__/",
+ "jest.config.js",
+ "babel.config.js",
+ "rollup.config.js"
+ ],
+ "settings": {
+ "import/resolver": {
+ "typescript": {}
+ }
+ }
+}
diff --git a/.prettierignore b/.prettierignore
new file mode 100644
index 0000000..e69de29
diff --git a/.prettierrc b/.prettierrc
new file mode 100644
index 0000000..4a4d876
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1,9 @@
+{
+ "printWidth": 80,
+ "singleQuote": true,
+ "trailingComma": "es5",
+ "semi": true,
+ "tabWidth": 2,
+ "endOfLine": "auto"
+ }
+
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e9b277a..62a6655 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,50 +1,65 @@
# Changelog
+## [0.15.2] - 2024-09-05
+
+### Added Changes
+
+- Implementation of Prettier and EsLint to the code base
+
## [0.15.1] - 2024-08-09
### Added Changes
+
- Remove postinstall script
## [0.15.0] - 2024-08-08
### Breaking Changes
+
- Updated `@etherspot/modular-sdk` with new wallet factory contract address
- `IMPORTANT`: To access previous wallet factory contract address, please use 0.14.1 or below, and move assets from wallets before updating to 0.15.0+
## [0.14.1] - 2024-07-11
### Added Changes
+
- Added `MODULE_TYPE` enum and `ModuleInfo` type from `etherspot-modular`
## [0.14.0] - 2024-07-10
### Added Changes
+
- Version update of `etherspot-modular`
- Added Etherspot Modular SDK `getAllModules` and `isModuleInstalled` to hook `useEtherspotModules`
- Updated `uninstallModule` with Etherspot Modular SDK `generateModuleDeInitData` to hook `useEtherspotModules` which allows to install and uninstall several modules
### Breaking Changes
+
- Updated `getAssets` which accepts optional props `chainId` and `name`
## [0.13.0] - 2024-06-17
### Added Changes
+
- `getSDK` include a param to choose to instantiate the Prime SDK instead of the Modular SDK
- Added Etherspot Modular SDK `installModule` and `uninstallModule` to hook `useEtherspotModules`
- Added `isModular` to context `EtherspotContextProvider`
### Breaking Changes
+
- Etherspot Modular SDK implemented to TransactionKit as the default `accountTemplate`
- Changed the `etherspot-prime` wallet type to `etherspot` wallet type
## [0.12.1] - 2024-05-22
### Added Changes
+
- Links updated on README file
## [0.12.0] - 2024-05-21
### Added Changes
+
- Added Etherspot Prime SDK `getSupportedAssets` to hook `useEtherspotAssets`
- Added Etherspot Prime SDK `getQuotes` to hook `useEtherspotSwaps`
- Added Etherspot Prime SDK `getTransactionStatus` to hook `useEtherspotHistory`
@@ -54,93 +69,111 @@
## [0.11.0] - 2024-03-28
### Added Changes
+
- Added `chainId` param to `useEtherspotNfts` hook's `getTransactions` and `getTransaction` methods
- Fixed `useEtherspotNfts` hook's `getTransactions` method returned result to match back-end changes
### Breaking Changes
+
- Transactions returned by `useEtherspotNfts` hook's `getTransactions` method are now different type called `UserOpTransaction`
## [0.10.1] - 2024-03-20
### Added Changes
+
- Fixes and optimizations on SDK initialization
- Updated `@etherspot/prime-sdk` to version `1.6.4` with config changes
## [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
+
- Cast `chainId` to number throughout the library to make it failproof for string chain IDs
## [0.9.1] - 2024-03-16
### Breaking Changes
+
- Chore on Etherspot Prime project keys
## [0.9.0] - 2024-03-16
### Breaking Changes
+
- Updated `@etherspot/prime-sdk` to version `1.6.2` with data service changes
- Hook `useEtherspotSwaps` temporarily unavailable for `getOffers` method
## [0.8.0] - 2024-02-28
### Breaking Changes
+
- Updated `useEtherspotTransactions` hook's `estimate` and `send` methods to return actual gas cost on `estimated` key and nicer error messages on `errorMessage` key
- Changed return type to `JSX.Element` for `EtherspotApprovalTransaction`, `EtherspotContractTransaction` and `EtherspotTokenTransferTransaction` components
## [0.7.7] - 2024-02-22
### Added Changes
+
- Added `chainId` param to `useEtherspotNfts` hook's `getAccountNfts` method
## [0.7.6] - 2024-02-21
### Added Changes
+
- Added Etherspot Prime SDK computed account pull from SDK instance state
## [0.7.5] - 2024-02-21
### Added Changes
+
- Added missing `tokenDecimals` param to `` and `` components
## [0.7.4] - 2024-02-20
### Added Changes
+
- Added `chainId` param to `useEtherspotAssets` hook's `getAssets` method
## [0.7.3] - 2024-02-20
### Added Changes
+
- Fixed `` component's used transfer method
## [0.7.2] - 2024-02-07
### Added Changes
+
- Fixed `useEtherspotBalances` hook's `getAccountBalances` accepted params type
## [0.7.1] - 2024-02-06
### Added Changes
+
- Added `chainId` param to `useEtherspotBalances` hook's `getAccountBalances` method
## [0.7.0] - 2024-01-30
### Added Changes
+
- Added `isSending`, `isEstimating`, `containsSendingError`, `containsEstimatingError` to `useEtherspotTransactions` hook
## [0.6.12] - 2024-01-26
### Added Changes
+
- Added Etherspot Prime SDK `projectKey` to ``, it allows usage of SDK data services
## [0.6.11] - 2023-11-23
### Added Changes
+
- Removed `reflect-metadata` and `rxjs` dependencies
- Fixed `@etherspot/eip1271-verification-util` to version `0.1.3`
- Added Pull Request template
@@ -148,46 +181,55 @@
## [0.6.10] - 2023-11-23
### Breaking Changes
+
- Updated `@etherspot/prime-sdk` to version `1.3.112` that removes `api_key` param from `paymaster` prop, now it's passed via `url` param
## [0.6.9] - 2023-11-06
### Added Changes
+
- Updated `@etherspot/prime-sdk` to version `1.3.10` that includes better error message handling under the hood
## [0.6.8] - 2023-10-29
### Added Changes
+
- Fixed `` component `paymaster.context` issues
## [0.6.7] - 2023-10-28
### Added Changes
+
- Fixed `` component `paymaster` prop issues
## [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
+
- Updated `@etherspot/prime-sdk` to version `1.3.8` with `accountTemplate` (SDK `factoryWallet`) fixes
## [0.6.4] - 2023-10-25
### Added Changes
+
- Added `accountTemplate` to `` component that allows passing custom `factoryWallet` supported by Prime SDK
## [0.6.3] - 2023-10-25
### Added Changes
+
- Added missing `useEtherspotTransactions` hook tests for `send` method
## [0.6.2] - 2023-10-24
### Added Changes
+
- Added missing `useEtherspotTransactions` hook tests for `estimate` method
- Fixed `skip` prop to ignore batch group estimations
- Fixed batching for same chain ID SDK instance
@@ -195,10 +237,12 @@
## [0.6.1] - 2023-10-24
### Added Changes
+
- Updated `example` React code to latest changes
- Updated `@etherspot/prime-sdk` to version `1.3.4`
### Breaking Changes
+
- Removed `etherspot` dependency
- Removed `@etherspot/react-etherspot` dependency
- Updated `provider` prop as required for `` component
@@ -209,44 +253,52 @@
- Removed `etherspotSessionStorage` from `` component, session is now handled internally
### Pending Changes
+
- Method `getOffers` for same chain swaps on `useEtherspotSwaps` hook is not working on this release
- Methods `getAccountTransactions` and `getAccountTransaction` on `useEtherspotHistory` hook are not working on this release
## [0.6.0] - 2023-10-18
### Breaking Changes
+
- Removed `etherspot` wallet type from `useWalletAddress` hook
- Removed `via` prop from `` component
-- Default `useWalletAddress` and `` provider is set to `etherspot-prime`
+- Default `useWalletAddress` and `` provider is set to `etherspot-prime`
- Removed `gasTokenAddress` prop from `` component due being unsupported in default `etherspot-prime` provider
### Added
+
- Added `gasCost` to `etherspot-prime` estimations
## [0.5.1] - 2023-10-17
### Added
+
- `react` dependencies chore.
## [0.5.0] - 2023-10-17
### Breaking Changes
+
- Downgraded `react` peer dependency to version `>=16.13.0`
## [0.4.9] - 2023-09-29
### Added
+
- Updated `@etherspot/prime-sdk` to version `1.2.11`
- Added `paymaster` prop to `` which is used for setting custom `paymaster` sent via `etherspot-prime` provider
## [0.4.8] - 2023-09-27
### Added
+
- Updated `@etherspot/prime-sdk` to version `1.2.10`
## [0.4.7] - 2023-09-27
### Fixes
+
- Updated `@etherspot/prime-sdk` to version `1.2.9`
- Removed `ethereumjs-util` dependency
- Updated address `checksum` util and tests
@@ -255,89 +307,105 @@
## [0.4.6] - 2023-08-03
### Added
+
- Chore on `@etherspot/prime-sdk` version `1.1.1`
## [0.4.5] - 2023-07-27
### Added
+
- Updated `@etherspot/prime-sdk` to version `1.1.1`
## [0.4.4] - 2023-07-25
### Fixes
+
- Fixed transaction sending after recent `@etherspot/prime-sdk` update to version `1.1.0`
## [0.4.3] - 2023-07-25
### Added
+
- Updated `@etherspot/prime-sdk` to version `1.1.0`
## [0.4.2] - 2023-07-03
### Added
+
- Updated `@etherspot/react-etherspot` to version `1.2.0` with `provider` state update fixes
- Added Etherspot Prime SDK saved instances fix to support `provider` change
## [0.4.1] - 2023-06-26
### Added
+
- Added updated Etherspot Prime SDK that supports Arbitrum chain
- Added improvements how `chainId` is handled
## [0.4.0] - 2023-06-16
### Added
+
- Added updated Etherspot Prime SDK that solves multiple issues within their SDK
## [0.3.2] - 2023-06-14
### Added
+
- Added fixes and improvements how Etherspot Prime SDK is created and handled
- Added `userOpHash` and `via` type to `SentBatches` type to to able to tell if it is
-`etherspot` `batchHash` or `etherspot-prime` `userOpHash`
+ `etherspot` `batchHash` or `etherspot-prime` `userOpHash`
## [0.3.1] - 2023-06-13
### Added
+
- Updated `@etherspot/eip1271-verification-util` to version `0.1.2`
## [0.3.0] - 2023-06-06
### Added
+
- Added `via` prop to `` component that accepts default `etherspot` provider or newly added SDK
-provider `etherspot-prime` that can be used to send EIP-4337 (Account Abstraction / UserOperation) transactions
-via Etherspot bundler
+ provider `etherspot-prime` that can be used to send EIP-4337 (Account Abstraction / UserOperation) transactions
+ via Etherspot bundler
- Added `useWalletAddres` hook to get `etherspot`, `etherspot-prime` and connected `provider` wallet address by type
- Added deprecation warning for `useEtherspotAddresses` hook, `useWalletAddress('etherspot', chainId)` should
-be used instead
+ be used instead
### Fixes
+
- Fixed `batches` ordering issue that were affecting renders with few `` components rendered
-at the same time
+ at the same time
## [0.2.5] - 2023-06-02
### Added
+
- Added `useEtherspotSwaps` hook for cross chain and same chain asset swaps
## [0.2.4] - 2023-06-01
### Added
+
- Added `useEtherspotPrices` hook for asset prices
## [0.2.3] - 2023-05-30
### Added
+
- Updated `window` context to not be used within non-browser environments.
## [0.2.2] - 2023-05-30
### Added
-- Updated `@etherspot/eip1271-verification-util` to version `0.1.1`.
+
+- Updated `@etherspot/eip1271-verification-util` to version `0.1.1`.
## [0.2.1] - 2023-05-30
### Added
+
- Added `rimraf` to suport developers in `Windows` environment.
- Added provider wallet transaction component ``
- Added `useProviderWalletTransaction` hook for provider wallet transaction management
@@ -345,6 +413,7 @@ at the same time
## [0.2.0] - 2023-05-12
### Added
+
- Added `useEtherspotBalances` hook for Etherspot/EVM related contract
- Added `useEtherspotUtils` hook for Etherspot/EVM related utils
- Added `useEtherspotHistory` hook for Etherspot account transactions history
@@ -354,4 +423,5 @@ at the same time
- Added missing warning logs throughout the library
### Breaking Changes
+
- Removed current output of `useEtherspotAssets` and added method `getAssets: () => Promise` that returns a list of assets instead of putting asseets automatically into the state
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 67010ed..b8d6a44 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,4 +1,5 @@
+
## Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
@@ -10,4 +11,4 @@ Don't forget to give the project a star! Thanks again!
2. Create your Feature Branch (`git checkout -b feature`)
3. Commit your Changes (`git commit -m 'Add some newFeature'`)
4. Push to the Branch (`git push origin feature`)
-5. Open a Pull Request
\ No newline at end of file
+5. Open a Pull Request
diff --git a/README.md b/README.md
index 04ef79c..89d6a27 100644
--- a/README.md
+++ b/README.md
@@ -11,19 +11,18 @@
---------------
+---
->[!IMPORTANT]
->This repo/software is under active development.
+> [!IMPORTANT]
+> This repo/software is under active development.
>
->[![npm](https://img.shields.io/npm/v/@etherspot/transaction-kit)](https://www.npmjs.com/package/@etherspot/transaction-kit)
-
+> [![npm](https://img.shields.io/npm/v/@etherspot/transaction-kit)](https://www.npmjs.com/package/@etherspot/transaction-kit)
## 🧰 TransactionKit
TransactionKit is a React Library that lets developers, no matter how experienced, get going with web3 development with ease.
-It simplifies working with Account Abstraction so developers can focus on building a great User Experience and easily interact with their Smart Contracts
+It simplifies working with Account Abstraction so developers can focus on building a great User Experience and easily interact with their Smart Contracts
on a [large number of EVM based chains](https://etherspot.fyi/prime-sdk/chains-supported).
## âš™ Get started
@@ -34,8 +33,8 @@ You can either get started by installing the packages yourself here:
npm i @etherspot/transaction-kit
```
-Or follow our introductory guide on our docs [here](https://etherspot.fyi/transaction-kit/intro) which walk you through
-cloning down an example repo and setting up a dapp in your own environment.
+Or follow our introductory guide on our docs [here](https://etherspot.fyi/transaction-kit/intro) which walk you through
+cloning down an example repo and setting up a dapp in your own environment.
## 📖 Documentation
diff --git a/SECURITY.md b/SECURITY.md
index 35c94ba..86331e1 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -1,6 +1,6 @@
# Reporting security issues
-If you think you have found a security vulnerability, please submit a report to our [HackerOne program](https://hackerone.com/pillarproject) for assets in scope or send an email to [security@etherspot.io](mailto:security@etherspot.io). This address can be used for all of Etherspot's open source (including but not limited to SDK, BUIDler, React Etherspot Kit).
+If you think you have found a security vulnerability, please submit a report to our [HackerOne program](https://hackerone.com/pillarproject) for assets in scope or send an email to [security@etherspot.io](mailto:security@etherspot.io). This address can be used for all of Etherspot's open source (including but not limited to SDK, BUIDler, React Etherspot Kit).
Etherspot will send you a response indicating the next steps in handling your report. After the initial reply to your report, the security team will keep you informed of the progress towards a fix and full announcement, and may ask for additional information or guidance.
diff --git a/__mocks__/@etherspot/eip1271-verification-util.js b/__mocks__/@etherspot/eip1271-verification-util.js
index cd5c63b..dd16830 100644
--- a/__mocks__/@etherspot/eip1271-verification-util.js
+++ b/__mocks__/@etherspot/eip1271-verification-util.js
@@ -1,5 +1,12 @@
-export const isValidEip1271Signature = async (rpcUrls, address, hash, signature) => {
- return address === '0x7F30B1960D5556929B03a0339814fE903c55a347'
- && hash === '0x1'
- && signature === '0x222';
-}
+export const isValidEip1271Signature = async (
+ rpcUrls,
+ address,
+ hash,
+ signature
+) => {
+ return (
+ address === '0x7F30B1960D5556929B03a0339814fE903c55a347' &&
+ hash === '0x1' &&
+ signature === '0x222'
+ );
+};
diff --git a/__mocks__/@etherspot/modular-sdk.js b/__mocks__/@etherspot/modular-sdk.js
index 06c74c6..bffa08c 100644
--- a/__mocks__/@etherspot/modular-sdk.js
+++ b/__mocks__/@etherspot/modular-sdk.js
@@ -1,9 +1,12 @@
import * as EtherspotModular from '@etherspot/modular-sdk';
import { ethers } from 'ethers';
-export const defaultAccountAddressModular = '0x7F30B1960D5556929B03a0339814fE903c55a347';
-export const otherFactoryDefaultAccountAddressModular = '0xe383724e3bDC4753746dEC781809f8CD82010914';
-export const otherAccountAddressModular = '0xAb4C67d8D7B248B2fA6B638C645466065fE8F1F1';
+export const defaultAccountAddressModular =
+ '0x7F30B1960D5556929B03a0339814fE903c55a347';
+export const otherFactoryDefaultAccountAddressModular =
+ '0xe383724e3bDC4753746dEC781809f8CD82010914';
+export const otherAccountAddressModular =
+ '0xAb4C67d8D7B248B2fA6B638C645466065fE8F1F1';
export class ModularSdk {
sdkChainId;
@@ -78,7 +81,11 @@ export class ModularSdk {
};
}
- totalGasEstimated({ callGasLimit, verificationGasLimit, preVerificationGas }) {
+ totalGasEstimated({
+ callGasLimit,
+ verificationGasLimit,
+ preVerificationGas,
+ }) {
return callGasLimit.add(verificationGasLimit).add(preVerificationGas);
}
@@ -103,7 +110,7 @@ export class ModularSdk {
async generateModuleDeInitData() {
const deInitData = ethers.utils.defaultAbiCoder.encode(
- ["address", "bytes"],
+ ['address', 'bytes'],
['0x0000000000000000000000000000000000000001', '0x00']
);
return deInitData;
@@ -111,15 +118,15 @@ export class ModularSdk {
async installModule(moduleType, module, initData, accountAddress) {
if (!accountAddress && !defaultAccountAddressModular) {
- throw new Error('No account address provided!')
+ throw new Error('No account address provided!');
}
if (!moduleType || !module) {
- throw new Error('installModule props missing')
+ throw new Error('installModule props missing');
}
if (module === '0x222') {
- throw new Error('module is already installed')
+ throw new Error('module is already installed');
}
return '0x123';
@@ -127,15 +134,15 @@ export class ModularSdk {
async uninstallModule(moduleType, module, deinitData, accountAddress) {
if (module === '0x222') {
- throw new Error('module is not installed')
- }
+ throw new Error('module is not installed');
+ }
if (!accountAddress && !defaultAccountAddressModular) {
- throw new Error('No account address provided!')
+ throw new Error('No account address provided!');
}
if (!moduleType || !module || !deinitData) {
- throw new Error('uninstallModule props missing')
+ throw new Error('uninstallModule props missing');
}
return '0x456';
@@ -143,21 +150,21 @@ export class ModularSdk {
async getAllModules(pageSize, accountAddress) {
if (!accountAddress && !defaultAccountAddressModular) {
- throw new Error('No account address provided!')
+ throw new Error('No account address provided!');
}
return {
- validators: ['0x000', '0x111', '0x222']
+ validators: ['0x000', '0x111', '0x222'],
};
}
async isModuleInstalled(moduleType, module, accountAddress) {
if (!accountAddress && !defaultAccountAddressModular) {
- throw new Error('No account address provided!')
+ throw new Error('No account address provided!');
}
if (!moduleType || !module) {
- throw new Error('uninstallModule props missing')
+ throw new Error('uninstallModule props missing');
}
if (module === '0x111') {
diff --git a/__mocks__/@etherspot/prime-sdk.js b/__mocks__/@etherspot/prime-sdk.js
index f9a2d26..0cca03f 100644
--- a/__mocks__/@etherspot/prime-sdk.js
+++ b/__mocks__/@etherspot/prime-sdk.js
@@ -1,8 +1,10 @@
import * as EtherspotPrime from '@etherspot/prime-sdk';
import { ethers } from 'ethers';
-export const defaultAccountAddress = '0x7F30B1960D5556929B03a0339814fE903c55a347';
-export const otherFactoryDefaultAccountAddress = '0xe383724e3bDC4753746dEC781809f8CD82010914';
+export const defaultAccountAddress =
+ '0x7F30B1960D5556929B03a0339814fE903c55a347';
+export const otherFactoryDefaultAccountAddress =
+ '0xe383724e3bDC4753746dEC781809f8CD82010914';
export const otherAccountAddress = '0xAb4C67d8D7B248B2fA6B638C645466065fE8F1F1';
export class PrimeSdk {
@@ -78,7 +80,11 @@ export class PrimeSdk {
};
}
- totalGasEstimated({ callGasLimit, verificationGasLimit, preVerificationGas }) {
+ totalGasEstimated({
+ callGasLimit,
+ verificationGasLimit,
+ preVerificationGas,
+ }) {
return callGasLimit.add(verificationGasLimit).add(preVerificationGas);
}
@@ -103,65 +109,91 @@ export class PrimeSdk {
}
export class DataUtils {
- constructor() { }
-
- getQuotes({ fromAddress, toAddress, fromChainId, toChainId, fromToken, fromAmount, slippage }) {
- if (!fromAddress || !toAddress || !fromChainId || !toChainId || !fromToken || !fromAmount || !slippage) {
+ constructor() {}
+
+ getQuotes({
+ fromAddress,
+ toAddress,
+ fromChainId,
+ toChainId,
+ fromToken,
+ fromAmount,
+ slippage,
+ }) {
+ if (
+ !fromAddress ||
+ !toAddress ||
+ !fromChainId ||
+ !toChainId ||
+ !fromToken ||
+ !fromAmount ||
+ !slippage
+ ) {
return 'getQuotes: missing required props';
}
- if (fromAddress === '0x111' && toAddress === '0x222' && fromChainId === 1 && toChainId === 56 && fromToken == '0x123456' && fromAmount === '0x10000000000' && slippage === 1) {
+ if (
+ fromAddress === '0x111' &&
+ toAddress === '0x222' &&
+ fromChainId === 1 &&
+ toChainId === 56 &&
+ fromToken == '0x123456' &&
+ fromAmount === '0x10000000000' &&
+ slippage === 1
+ ) {
return {
transactions: [
{
- data: "0x111222333",
- to: "0x123",
- value: "0x00"
+ data: '0x111222333',
+ to: '0x123',
+ value: '0x00',
},
{
- value: "0xb2eed2c27ce6",
- data: "0x444555666",
- to: "0x456",
- chainId: 1
- }
- ]
- }
+ value: '0xb2eed2c27ce6',
+ data: '0x444555666',
+ to: '0x456',
+ chainId: 1,
+ },
+ ],
+ };
}
return { transactions: [] };
}
getSupportedAssets({ chainId, provider: bridgingProvider }) {
- const allSupportedAssets = [{
- address: "0x123",
- chainId: 1,
- name: "USDC",
- symbol: "USDC",
- },
- {
- address: "0x456",
- chainId: 1,
- name: "USDC",
- symbol: "USDC",
- },
- {
- address: "0x789",
- chainId: 137,
- name: "USDC",
- symbol: "USDC",
- },
+ const allSupportedAssets = [
+ {
+ address: '0x123',
+ chainId: 1,
+ name: 'USDC',
+ symbol: 'USDC',
+ },
+ {
+ address: '0x456',
+ chainId: 1,
+ name: 'USDC',
+ symbol: 'USDC',
+ },
+ {
+ address: '0x789',
+ chainId: 137,
+ name: 'USDC',
+ symbol: 'USDC',
+ },
];
if (!chainId) {
- return { tokens: allSupportedAssets }
+ return { tokens: allSupportedAssets };
}
- if (allSupportedAssets.some(asset => asset.chainId === chainId)) {
- return { tokens: allSupportedAssets.filter((asset) => asset.chainId === chainId) }
+ if (allSupportedAssets.some((asset) => asset.chainId === chainId)) {
+ return {
+ tokens: allSupportedAssets.filter((asset) => asset.chainId === chainId),
+ };
}
- return { tokens: [] }
-
+ return { tokens: [] };
}
getAccountBalances({ chainId, account }) {
@@ -169,8 +201,16 @@ export class DataUtils {
const tokenBalance = ethers.utils.parseEther('420');
const nativeAssetBalance = ethers.utils.parseEther('0');
- const token = { token: '0x', balance: tokenBalance, superBalance: tokenBalance };
- const nativeAsset = { token: null, balance: nativeAssetBalance, superBalance: nativeAssetBalance };
+ const token = {
+ token: '0x',
+ balance: tokenBalance,
+ superBalance: tokenBalance,
+ };
+ const nativeAsset = {
+ token: null,
+ balance: nativeAssetBalance,
+ superBalance: nativeAssetBalance,
+ };
if (chainId !== 1) {
return { items: [nativeAsset] };
@@ -181,7 +221,12 @@ export class DataUtils {
}
if (account === otherAccountAddress) {
- return { items: [nativeAsset, { ...token, balance: ethers.utils.parseEther('69') }] };
+ return {
+ items: [
+ nativeAsset,
+ { ...token, balance: ethers.utils.parseEther('69') },
+ ],
+ };
}
return { items: [] };
@@ -210,7 +255,7 @@ export class DataUtils {
getTransactionStatus({ fromChainId, toChainId, transactionHash, provider }) {
if (!fromChainId || !toChainId || !transactionHash) {
- return 'getTransactionStatus: missing required props'
+ return 'getTransactionStatus: missing required props';
}
if (fromChainId === 1 && toChainId === 137 && transactionHash === '0x123') {
@@ -232,8 +277,16 @@ export class DataUtils {
getNftList({ account, chainId }) {
const accountNfts = [
- { contractName: 'Collection Alpha', contractAddress: '0x2', items: [{ tokenId: 420 }] },
- { contractName: 'Collection Beta', contractAddress: '0x1', items: [{ tokenId: 6 }, { tokenId: 9 }] },
+ {
+ contractName: 'Collection Alpha',
+ contractAddress: '0x2',
+ items: [{ tokenId: 420 }],
+ },
+ {
+ contractName: 'Collection Beta',
+ contractAddress: '0x1',
+ items: [{ tokenId: 6 }, { tokenId: 9 }],
+ },
];
if (chainId !== 1) {
@@ -245,22 +298,49 @@ export class DataUtils {
}
if (account === otherAccountAddress) {
- return { items: [{ ...accountNfts[0], contractName: 'Collection Gama' }] };
+ return {
+ items: [{ ...accountNfts[0], contractName: 'Collection Gama' }],
+ };
}
return { items: [] };
}
getTokenListTokens({ name, chainId }) {
- const token1 = { address: '0x1', chainId, name: 'tk1', symbol: 'TK1', decimals: 18, logoURI: '' };
- const token2 = { address: '0x2', chainId, name: 'tk2', symbol: 'TK2', decimals: 18, logoURI: '' };
- const token3 = { address: '0x3', chainId, name: 'tk3', symbol: 'TK3', decimals: 18, logoURI: '' };
+ const token1 = {
+ address: '0x1',
+ chainId,
+ name: 'tk1',
+ symbol: 'TK1',
+ decimals: 18,
+ logoURI: '',
+ };
+ const token2 = {
+ address: '0x2',
+ chainId,
+ name: 'tk2',
+ symbol: 'TK2',
+ decimals: 18,
+ logoURI: '',
+ };
+ const token3 = {
+ address: '0x3',
+ chainId,
+ name: 'tk3',
+ symbol: 'TK3',
+ decimals: 18,
+ logoURI: '',
+ };
return chainId === 1 ? [token1, token2, token3] : [token1];
}
getExchangeOffers({ fromTokenAddress, toTokenAddress, fromChainId }) {
- if (fromChainId !== 1 || fromTokenAddress !== '0x111' || toTokenAddress !== '0x222') {
+ if (
+ fromChainId !== 1 ||
+ fromTokenAddress !== '0x111' ||
+ toTokenAddress !== '0x222'
+ ) {
return [];
}
@@ -279,8 +359,19 @@ export class DataUtils {
return [offer1, offer2];
}
- getAdvanceRoutesLiFi({ fromAmount, fromChainId, toChainId, fromTokenAddress, toTokenAddress }) {
- if (fromChainId !== 1 || toChainId !== 137 || fromTokenAddress !== '0x111' || toTokenAddress !== '0x222') {
+ getAdvanceRoutesLiFi({
+ fromAmount,
+ fromChainId,
+ toChainId,
+ fromTokenAddress,
+ toTokenAddress,
+ }) {
+ if (
+ fromChainId !== 1 ||
+ toChainId !== 137 ||
+ fromTokenAddress !== '0x111' ||
+ toTokenAddress !== '0x222'
+ ) {
return { items: [] };
}
diff --git a/__tests__/hooks/useEtherspotModules.test.js b/__tests__/hooks/useEtherspotModules.test.js
index e13a756..9ef4635 100644
--- a/__tests__/hooks/useEtherspotModules.test.js
+++ b/__tests__/hooks/useEtherspotModules.test.js
@@ -1,16 +1,22 @@
import { renderHook, waitFor } from '@testing-library/react';
import { ethers } from 'ethers';
-import { useEtherspotModules, EtherspotTransactionKit, MODULE_TYPE } from '../../src';
-
-
-const ethersProvider = new ethers.providers.JsonRpcProvider('http://localhost:8545', 'sepolia'); // replace with your node's RPC URL
+import {
+ EtherspotTransactionKit,
+ MODULE_TYPE,
+ useEtherspotModules,
+} from '../../src';
+
+const ethersProvider = new ethers.providers.JsonRpcProvider(
+ 'http://localhost:8545',
+ 'sepolia'
+); // replace with your node's RPC URL
const provider = new ethers.Wallet.createRandom().connect(ethersProvider);
const moduleAddress = '0x111';
const initData = ethers.utils.defaultAbiCoder.encode(
- ["address", "bytes"],
- ['0x0000000000000000000000000000000000000001', '0x00']
- );
+ ['address', 'bytes'],
+ ['0x0000000000000000000000000000000000000001', '0x00']
+);
describe('useEtherspotModules()', () => {
it('install one module', async () => {
@@ -20,31 +26,44 @@ describe('useEtherspotModules()', () => {
);
- const { result } = renderHook(({ chainId }) => useEtherspotModules(chainId), {
- initialProps: { chainId: 1 },
- wrapper,
- });
+ const { result } = renderHook(
+ ({ chainId }) => useEtherspotModules(chainId),
+ {
+ initialProps: { chainId: 1 },
+ wrapper,
+ }
+ );
// wait for balances to be fetched for chain ID 1
await waitFor(() => expect(result.current).not.toBeNull());
- const installModuleMissingProps = await result.current.installModule(MODULE_TYPE.VALIDATOR)
- .catch((e) => {
- console.error(e);
- return `${e}`
- })
- expect(installModuleMissingProps).toBe('Error: Failed to install module: Error: installModule props missing');
+ const installModuleMissingProps = await result.current
+ .installModule(MODULE_TYPE.VALIDATOR)
+ .catch((e) => {
+ console.error(e);
+ return `${e}`;
+ });
+ expect(installModuleMissingProps).toBe(
+ 'Error: Failed to install module: Error: installModule props missing'
+ );
- const installModuleAlreadyInstalled = await result.current.installModule(MODULE_TYPE.VALIDATOR, '0x222')
- .catch((e) => {
- console.error(e);
- return `${e}`
- })
+ const installModuleAlreadyInstalled = await result.current
+ .installModule(MODULE_TYPE.VALIDATOR, '0x222')
+ .catch((e) => {
+ console.error(e);
+ return `${e}`;
+ });
- expect(installModuleAlreadyInstalled).toBe('Error: Failed to install module: Error: module is already installed');
+ expect(installModuleAlreadyInstalled).toBe(
+ 'Error: Failed to install module: Error: module is already installed'
+ );
- const installOneModule = await result.current.installModule(MODULE_TYPE.VALIDATOR, moduleAddress, initData);
- expect(installOneModule).toBe('0x123')
+ const installOneModule = await result.current.installModule(
+ MODULE_TYPE.VALIDATOR,
+ moduleAddress,
+ initData
+ );
+ expect(installOneModule).toBe('0x123');
});
it('uninstall one module', async () => {
@@ -54,36 +73,50 @@ describe('useEtherspotModules()', () => {
);
- const { result } = renderHook(({ chainId }) => useEtherspotModules(chainId), {
- initialProps: { chainId: 1 },
- wrapper,
- });
+ const { result } = renderHook(
+ ({ chainId }) => useEtherspotModules(chainId),
+ {
+ initialProps: { chainId: 1 },
+ wrapper,
+ }
+ );
// wait for balances to be fetched for chain ID 1
await waitFor(() => expect(result.current).not.toBeNull());
- const uninstallModuleNotInstalled = await result.current.uninstallModule(MODULE_TYPE.VALIDATOR, '0x222')
- .catch((e) => {
- console.error(e);
- return `${e}`
- })
+ const uninstallModuleNotInstalled = await result.current
+ .uninstallModule(MODULE_TYPE.VALIDATOR, '0x222')
+ .catch((e) => {
+ console.error(e);
+ return `${e}`;
+ });
- expect(uninstallModuleNotInstalled).toBe('Error: Failed to uninstall module: Error: module is not installed');
+ expect(uninstallModuleNotInstalled).toBe(
+ 'Error: Failed to uninstall module: Error: module is not installed'
+ );
- const installOneModule = await result.current.installModule(MODULE_TYPE.VALIDATOR, moduleAddress, initData);
+ const installOneModule = await result.current.installModule(
+ MODULE_TYPE.VALIDATOR,
+ moduleAddress,
+ initData
+ );
expect(installOneModule).toBe('0x123');
- const uninstallModulePropsMissing = await result.current.uninstallModule(moduleAddress)
- .catch((e) => {
- console.error(e);
- return `${e}`
- })
- expect(uninstallModulePropsMissing).toBe('Error: Failed to uninstall module: Error: uninstallModule props missing');
-
-
- const uninstallOneModule = await result.current.uninstallModule(MODULE_TYPE.VALIDATOR, moduleAddress);
- expect(uninstallOneModule).toBe('0x456');
+ const uninstallModulePropsMissing = await result.current
+ .uninstallModule(moduleAddress)
+ .catch((e) => {
+ console.error(e);
+ return `${e}`;
+ });
+ expect(uninstallModulePropsMissing).toBe(
+ 'Error: Failed to uninstall module: Error: uninstallModule props missing'
+ );
+ const uninstallOneModule = await result.current.uninstallModule(
+ MODULE_TYPE.VALIDATOR,
+ moduleAddress
+ );
+ expect(uninstallOneModule).toBe('0x456');
});
it('list of modules for one wallet', async () => {
@@ -93,16 +126,23 @@ describe('useEtherspotModules()', () => {
);
- const { result } = renderHook(({ chainId }) => useEtherspotModules(chainId), {
- initialProps: { chainId: 1 },
- wrapper,
- });
+ const { result } = renderHook(
+ ({ chainId }) => useEtherspotModules(chainId),
+ {
+ initialProps: { chainId: 1 },
+ wrapper,
+ }
+ );
// wait for balances to be fetched for chain ID 1
await waitFor(() => expect(result.current).not.toBeNull());
- const installOneModule = await result.current.installModule(MODULE_TYPE.VALIDATOR, moduleAddress, initData);
- expect(installOneModule).toBe('0x123')
+ const installOneModule = await result.current.installModule(
+ MODULE_TYPE.VALIDATOR,
+ moduleAddress,
+ initData
+ );
+ expect(installOneModule).toBe('0x123');
const listOfModules = await result.current.listModules();
expect(listOfModules.validators).toContain('0x111');
@@ -116,21 +156,34 @@ describe('useEtherspotModules()', () => {
);
- const { result } = renderHook(({ chainId }) => useEtherspotModules(chainId), {
- initialProps: { chainId: 1 },
- wrapper,
- });
+ const { result } = renderHook(
+ ({ chainId }) => useEtherspotModules(chainId),
+ {
+ initialProps: { chainId: 1 },
+ wrapper,
+ }
+ );
// wait for balances to be fetched for chain ID 1
await waitFor(() => expect(result.current).not.toBeNull());
- const installOneModule = await result.current.installModule(MODULE_TYPE.VALIDATOR, moduleAddress, initData);
- expect(installOneModule).toBe('0x123')
+ const installOneModule = await result.current.installModule(
+ MODULE_TYPE.VALIDATOR,
+ moduleAddress,
+ initData
+ );
+ expect(installOneModule).toBe('0x123');
- const isModuleOneInstalled = await result.current.isModuleInstalled(MODULE_TYPE.VALIDATOR, moduleAddress);
+ const isModuleOneInstalled = await result.current.isModuleInstalled(
+ MODULE_TYPE.VALIDATOR,
+ moduleAddress
+ );
expect(isModuleOneInstalled).toBe(true);
- const isModuleTowInstalled = await result.current.isModuleInstalled(MODULE_TYPE.VALIDATOR, '0x222');
+ const isModuleTowInstalled = await result.current.isModuleInstalled(
+ MODULE_TYPE.VALIDATOR,
+ '0x222'
+ );
expect(isModuleTowInstalled).toBe(false);
});
-})
+});
diff --git a/babel.config.js b/babel.config.js
index cb755f8..286a34c 100644
--- a/babel.config.js
+++ b/babel.config.js
@@ -2,6 +2,6 @@ module.exports = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
['@babel/preset-react', { runtime: 'automatic' }],
- '@babel/preset-typescript'
+ '@babel/preset-typescript',
],
};
diff --git a/example/.eslintignore b/example/.eslintignore
new file mode 100644
index 0000000..c8740c5
--- /dev/null
+++ b/example/.eslintignore
@@ -0,0 +1 @@
+__tests__/
diff --git a/example/src/App.tsx b/example/src/App.tsx
index fb1fca9..b28aaf0 100644
--- a/example/src/App.tsx
+++ b/example/src/App.tsx
@@ -5,17 +5,27 @@ import {
EtherspotTransaction,
IEstimatedBatches,
ISentBatches,
+ MODULE_TYPE,
+ ModuleInfo,
SentBatch,
useEtherspot,
+ useEtherspotAssets,
+ useEtherspotModules,
useEtherspotTransactions,
useWalletAddress,
- useEtherspotModules,
- ModuleInfo,
- MODULE_TYPE,
} from '@etherspot/transaction-kit';
import TreeItem from '@mui/lab/TreeItem';
import TreeView from '@mui/lab/TreeView';
-import { Box, Button, Chip, Container, Paper, Tab, Tabs, Typography } from '@mui/material';
+import {
+ Box,
+ Button,
+ Chip,
+ Container,
+ Paper,
+ Tab,
+ Tabs,
+ Typography,
+} from '@mui/material';
import { ethers } from 'ethers';
import React, { useEffect, useState } from 'react';
import { AiFillCaretDown, AiFillCaretRight } from 'react-icons/ai';
@@ -71,7 +81,10 @@ const exampleCode = {
-
+
),
@@ -85,6 +98,7 @@ const App = () => {
const { getDataService, chainId: etherspotChainId } = useEtherspot();
const { installModule, uninstallModule, listModules } = useEtherspotModules();
const etherspotPrimeOrModularAddress = useWalletAddress();
+ const { getAssets } = useEtherspotAssets();
const [balancePerAddress, setBalancePerAddress] = useState({
[walletAddressByName.Alice]: '',
[walletAddressByName.Bob]: '',
@@ -109,18 +123,21 @@ const App = () => {
})),
}));
- const batchesTreeViewExpandedIds = batchesTreeView.reduce((ids: string[], batchGroup) => {
- let moreIds = [batchGroup.treeNodeId];
+ const batchesTreeViewExpandedIds = batchesTreeView.reduce(
+ (ids: string[], batchGroup) => {
+ let moreIds = [batchGroup.treeNodeId];
- batchGroup?.batches?.forEach((batch) => {
- moreIds = [...moreIds, batch.treeNodeId];
- batch?.transactions?.forEach((transaction) => {
- moreIds = [...moreIds, transaction.treeNodeId];
+ batchGroup?.batches?.forEach((batch) => {
+ moreIds = [...moreIds, batch.treeNodeId];
+ batch?.transactions?.forEach((transaction) => {
+ moreIds = [...moreIds, transaction.treeNodeId];
+ });
});
- });
- return [...ids, ...moreIds];
- }, []);
+ return [...ids, ...moreIds];
+ },
+ []
+ );
const [expanded, setExpanded] = React.useState([]);
@@ -129,7 +146,8 @@ const App = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [batches]);
- const handleToggle = (event: React.SyntheticEvent, nodeIds: string[]) => setExpanded(nodeIds);
+ const handleToggle = (event: React.SyntheticEvent, nodeIds: string[]) =>
+ setExpanded(nodeIds);
useEffect(() => {
setEstimated(null);
@@ -170,7 +188,11 @@ const App = () => {
};
const onUninstallModuleClick = async () => {
- await uninstallModule(MODULE_TYPE.VALIDATOR, testModuleSepoliaTestnet, deInitData);
+ await uninstallModule(
+ MODULE_TYPE.VALIDATOR,
+ testModuleSepoliaTestnet,
+ deInitData
+ );
await listModules().then((list) => setModulesList(list));
};
@@ -196,15 +218,21 @@ const App = () => {
account: address,
chainId: +(process.env.REACT_APP_CHAIN_ID as string),
});
- const balance = balances && balances.items.find(({ token }) => token === null);
- if (balance) updatedBalances[address] = ethers.utils.formatEther(balance.balance);
+ const balance =
+ balances && balances.items.find(({ token }) => token === null);
+ if (balance)
+ updatedBalances[address] = ethers.utils.formatEther(
+ balance.balance
+ );
})
);
if (expired) return;
setBalancePerAddress(updatedBalances);
- await listModules().then((list) => setModulesList(list)).catch((e) => setModulesList(undefined));
+ await listModules()
+ .then((list) => setModulesList(list))
+ .catch((e) => setModulesList(undefined));
};
refreshBalances();
@@ -216,20 +244,36 @@ const App = () => {
}, [etherspotPrimeOrModularAddress]);
const estimationFailed = estimated?.some((estimatedGroup) =>
- estimatedGroup.estimatedBatches?.some((estimatedBatch) => estimatedBatch.errorMessage)
+ estimatedGroup.estimatedBatches?.some(
+ (estimatedBatch) => estimatedBatch.errorMessage
+ )
);
+ const hey = async () => {
+ const prout = await getAssets(undefined, 'EtherspotPopularTokens');
+ return prout;
+ };
+
+ useEffect(() => {
+ hey().then((x) => console.log(x));
+ }, []);
+
return (
-
+
Sepolia ETH Faucet
{
style={{ marginRight: 10, marginTop: 10 }}
/>
{Object.keys(walletAddressByName).map((addressName: string) => {
- const address = walletAddressByName[addressName as keyof typeof walletAddressByName];
+ const address =
+ walletAddressByName[
+ addressName as keyof typeof walletAddressByName
+ ];
const balancePart = `balance: ${
- balancePerAddress[address] ? `${Number(balancePerAddress[address]).toFixed(4)} ETH` : 'Loading...'
+ balancePerAddress[address]
+ ? `${Number(balancePerAddress[address]).toFixed(4)} ETH`
+ : 'Loading...'
}`;
const chipLabel = `${addressName} ${balancePart}`;
return (
@@ -259,32 +308,44 @@ const App = () => {
{etherspotPrimeOrModularAddress}
)}
- {modulesList && (
-
-
-
Modules installed:
-
- {modulesList.validators?.map((module, i) => (
- -
- {module}
-
- ))}
-
-
-
-
-
- )}
+ {modulesList && (
+
+
+
Modules installed:
+
+ {modulesList.validators?.map((module, i) => (
+ -
+ {module}
+
+ ))}
+
+
+
+
+
+ )}
setActiveTab(id)}>
-
+
-