├── .commitlintrc.json ├── .eslintrc.js ├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.md │ ├── config.yml │ └── feature-request.md ├── PULL_REQUEST_TEMPLATE.md ├── dependabot.yml └── workflows │ ├── codeql-analysis.yml │ └── main.yml ├── .gitignore ├── .husky ├── .gitignore └── pre-commit ├── .prettierignore ├── .prettierrc ├── .vscode └── settings.json ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CODING_STYLE.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── babel.config.js ├── docs └── head.png ├── jest.config.ts ├── package.json ├── release.config.js ├── rollup.config.js ├── src ├── Errors.ts ├── components │ ├── ByMoralis │ │ ├── ByMoralis.tsx │ │ └── index.ts │ └── index.ts ├── config │ └── index.ts ├── context │ ├── MoralisContext │ │ ├── MoralisContext.ts │ │ └── index.ts │ ├── MoralisProvider │ │ ├── MoralisProvider.tsx │ │ └── index.ts │ └── index.ts ├── data │ ├── blockExplorers.ts │ └── chains.ts ├── functions │ ├── chains.ts │ ├── index.ts │ ├── resolveIPFS.test.ts │ └── resolveIPFS.ts ├── hooks │ ├── core │ │ ├── index.ts │ │ ├── useChain │ │ │ ├── index.ts │ │ │ └── useChain.ts │ │ ├── useMoralis │ │ │ ├── _useMoralisAuth.ts │ │ │ ├── _useMoralisInit.ts │ │ │ ├── _useMoralisUser.ts │ │ │ ├── _useMoralisWeb3.ts │ │ │ ├── index.ts │ │ │ ├── useMoralis.ts │ │ │ └── utils │ │ │ │ └── setUserData.ts │ │ ├── useMoralisCloudQuery │ │ │ ├── index.ts │ │ │ └── useMoralisCloudFunction.ts │ │ ├── useMoralisFile │ │ │ ├── index.ts │ │ │ └── useMoralisFile.ts │ │ ├── useMoralisObject │ │ │ ├── index.ts │ │ │ └── useNewMoralisObject.ts │ │ ├── useMoralisQuery │ │ │ ├── _useSafeUpdatedQuery.ts │ │ │ ├── index.ts │ │ │ └── useMoralisQuery.ts │ │ ├── useMoralisSolanaApi │ │ │ ├── index.ts │ │ │ └── useMoralisSolanaApi.ts │ │ ├── useMoralisSubscription │ │ │ ├── _useMoralisSubscriptionListener.ts │ │ │ ├── index.ts │ │ │ └── useMoralisSubscription.ts │ │ ├── useMoralisWeb3Api │ │ │ ├── index.ts │ │ │ └── useMoralisWeb3Api.ts │ │ ├── useWeb3Contract │ │ │ ├── index.ts │ │ │ └── useWeb3Contract.ts │ │ ├── useWeb3ExecuteFunction │ │ │ ├── index.ts │ │ │ └── useWeb3ExecuteFunction.ts │ │ └── useWeb3Transfer │ │ │ ├── index.ts │ │ │ └── useWeb3Transfer.ts │ ├── index.ts │ ├── internal │ │ ├── _useResolveAsyncCall │ │ │ ├── _useResolveAsyncCall.ts │ │ │ └── index.ts │ │ └── _useResolvePluginCall │ │ │ ├── _useResolvePluginCall.ts │ │ │ └── index.ts │ ├── plugins │ │ ├── index.ts │ │ ├── useFiat │ │ │ ├── index.ts │ │ │ └── useFiatBuy.ts │ │ ├── useOneInch │ │ │ ├── index.ts │ │ │ ├── types.ts │ │ │ ├── useOneInchQuote.ts │ │ │ ├── useOneInchSwap.ts │ │ │ └── useOneInchTokens.ts │ │ ├── useOpenSea │ │ │ ├── index.ts │ │ │ ├── types.ts │ │ │ ├── useOpenSeaAsset.ts │ │ │ ├── useOpenSeaBuyOrder.ts │ │ │ ├── useOpenSeaOrders.ts │ │ │ └── useOpenSeaSellOrder.ts │ │ └── useRarible │ │ │ ├── index.ts │ │ │ ├── types.ts │ │ │ ├── useRaribleLazyMint.ts │ │ │ └── useRaribleSellOrder.ts │ ├── utils │ │ ├── index.ts │ │ └── useEns │ │ │ ├── index.ts │ │ │ ├── useEnsAddress.ts │ │ │ └── useEnsName.ts │ └── web3ApiWrappers │ │ ├── index.ts │ │ ├── useApiContract │ │ ├── index.ts │ │ └── useApiContract.ts │ │ ├── useERC20Balances │ │ ├── index.ts │ │ └── useERC20Balances.ts │ │ ├── useERC20Transfers │ │ ├── index.ts │ │ └── useERC20Transfers.ts │ │ ├── useNFTBalances │ │ ├── index.ts │ │ └── useNFTBalances.ts │ │ ├── useNFTTransfers │ │ ├── index.ts │ │ └── useNFTTransfers.ts │ │ ├── useNativeBalance │ │ ├── index.ts │ │ └── useNativeBalance.ts │ │ ├── useNativeTransactions │ │ ├── index.ts │ │ └── useNativeTransactions.ts │ │ └── useTokenPrice │ │ ├── index.ts │ │ └── useTokenPrice.ts ├── index.ts └── utils │ ├── formatters.test.ts │ ├── formatters.ts │ ├── genericQuery.ts │ └── isValidApiChain.ts ├── tsconfig.json └── yarn.lock /.commitlintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["@commitlint/config-conventional"] 3 | } 4 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | node: true, 4 | browser: true, 5 | es2021: true, 6 | jest: true, 7 | }, 8 | extends: [ 9 | "eslint:recommended", 10 | "plugin:react/recommended", 11 | "plugin:@typescript-eslint/recommended", 12 | ], 13 | settings: { 14 | react: { 15 | version: "detect", 16 | }, 17 | }, 18 | parser: "@typescript-eslint/parser", 19 | parserOptions: { 20 | ecmaFeatures: { 21 | jsx: true, 22 | }, 23 | ecmaVersion: 12, 24 | sourceType: "module", 25 | }, 26 | plugins: ["react", "@typescript-eslint"], 27 | rules: { 28 | "@typescript-eslint/ban-types": "off", 29 | "@typescript-eslint/no-empty-interface": "off", 30 | "@typescript-eslint/explicit-module-boundary-types": "off", 31 | "@typescript-eslint/ban-ts-comment": "off", 32 | "@typescript-eslint/no-empty-function": "off", 33 | "@typescript-eslint/no-non-null-assertion": "off", 34 | "react/prop-types": "off", 35 | "no-empty-pattern": "off", 36 | "no-console": "error", 37 | }, 38 | }; 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "Bug report" 3 | about: A feature is not working as expected. 4 | --- 5 | 6 | ## New Bug Report 7 | 8 | ### Checklist 9 | 10 | 15 | 16 | - [ ] I am not disclosing a [vulnerability](https://github.com/MoralisWeb3/react-moralis/blob/main/SECURITY.md). 17 | - [ ] I have searched through [existing issues](https://github.com/MoralisWeb3/react-moralis/issues?q=is%3Aissue) and the [Moralis Forum](https://forum.moralis.io/). 18 | - [ ] I can reproduce the issue with the [latest react-moralis release](https://github.com/MoralisWeb3/react-moralis/releases), [latest SDK release](https://github.com/MoralisWeb3/Moralis-JS-SDK/releases), and my server is updated to the latest version. 19 | 20 | ### Issue Description 21 | 22 | 23 | 24 | ### Steps + code to reproduce 25 | 26 | 27 | 28 | ### Actual Outcome 29 | 30 | 31 | 32 | ### Expected Outcome 33 | 34 | 35 | 36 | ### Environment 37 | 38 | 39 | 40 | Server 41 | 42 | - Moralis server version: `FILL_THIS_OUT` 43 | 44 | Client 45 | 46 | - react-moralis version: `FILL_THIS_OUT` 47 | - Moralis SDK version: `FILL_THIS_OUT` 48 | - Operating system: `FILL_THIS_OUT` 49 | - Browser: `FILL_THIS_OUT` 50 | 51 | ### Logs 52 | 53 | 54 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Getting help 4 | url: https://forum.moralis.io/ 5 | about: Get help with any questions on our Moralis Forum 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "Feature request" 3 | about: Suggest new functionality or an enhancement of existing functionality. 4 | --- 5 | 6 | ## New Feature Request 7 | 8 | ### Checklist 9 | 10 | 15 | 16 | - [ ] I am not disclosing a [vulnerability](https://github.com/MoralisWeb3/react-moralis/blob/main/SECURITY.md). 17 | - [ ] I have searched through [existing issues](https://github.com/MoralisWeb3/react-moralis/issues?q=is%3Aissue) and the [Moralis Forum](https://forum.moralis.io/). 18 | 19 | ### Current Limitation 20 | 21 | 22 | 23 | ### Feature / Enhancement Description 24 | 25 | 26 | 27 | ### Example Use Case 28 | 29 | 30 | 31 | ### Alternatives / Workarounds 32 | 33 | 34 | 35 | ### 3rd Party References 36 | 37 | 38 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "Pull request" 3 | about: A new pull request 4 | --- 5 | 6 | ## New Pull Request 7 | 8 | ### Checklist 9 | 10 | 15 | 16 | - [ ] I am not disclosing a [vulnerability](https://github.com/MoralisWeb3/react-moralis/blob/main/SECURITY.md). 17 | - [ ] My code is conform the [code style](https://github.com/MoralisWeb3/react-moralis/blob/main/CODE_STYLE.md) 18 | - [ ] I have made corresponding changes to the documentation 19 | - [ ] I have updated Typescript definitions when needed 20 | 21 | ### Issue Description 22 | 23 | 24 | 25 | Related issue: #`FILL_THIS_OUT` 26 | 27 | ### Solution Description 28 | 29 | 30 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | # Enable version updates for npm 4 | - package-ecosystem: "npm" 5 | # Look for `package.json` and `lock` files in the `root` directory 6 | directory: "/" 7 | # Check the npm registry for updates every day (weekdays) 8 | schedule: 9 | interval: "daily" 10 | commit-message: 11 | prefix: fix 12 | prefix-development: chore 13 | include: scope 14 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | # The branches below must be a subset of the branches above 8 | branches: [main] 9 | schedule: 10 | - cron: "15 19 * * 1" 11 | 12 | jobs: 13 | analyze: 14 | name: Analyze 15 | runs-on: ubuntu-latest 16 | permissions: 17 | actions: read 18 | contents: read 19 | security-events: write 20 | 21 | strategy: 22 | fail-fast: false 23 | matrix: 24 | language: ["javascript"] 25 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 26 | # Learn more: 27 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 28 | 29 | steps: 30 | - name: Checkout repository 31 | uses: actions/checkout@v2 32 | 33 | # Initializes the CodeQL tools for scanning. 34 | - name: Initialize CodeQL 35 | uses: github/codeql-action/init@v1 36 | with: 37 | languages: ${{ matrix.language }} 38 | # If you wish to specify custom queries, you can do so here or in a config file. 39 | # By default, queries listed here will override any specified in a config file. 40 | # Prefix the list here with "+" to use these queries and those in the config file. 41 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 42 | 43 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 44 | # If this step fails, then you should remove it and run the build manually (see below) 45 | - name: Autobuild 46 | uses: github/codeql-action/autobuild@v1 47 | 48 | # ℹ️ Command-line programs to run using the OS shell. 49 | # 📚 https://git.io/JvXDl 50 | 51 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 52 | # and modify them (or add more) to build your code if your project 53 | # uses a compiled language 54 | 55 | #- run: | 56 | # make bootstrap 57 | # make release 58 | 59 | - name: Perform CodeQL Analysis 60 | uses: github/codeql-action/analyze@v1 61 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | pull_request: 4 | branches: 5 | - main 6 | - beta 7 | push: 8 | branches: 9 | - main 10 | - beta 11 | jobs: 12 | setup: 13 | name: Build dependencies 14 | runs-on: ${{matrix.os}} 15 | strategy: 16 | matrix: 17 | os: [ubuntu-latest] 18 | node: [14] 19 | steps: 20 | - uses: actions/checkout@v2 21 | with: 22 | fetch-depth: 0 23 | - uses: actions/setup-node@v2 24 | with: 25 | node-version: "14" 26 | - name: Use cache dependencies 27 | uses: actions/cache@v2 28 | id: cache 29 | with: 30 | path: "**/node_modules" 31 | key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}s 32 | - name: Install packages 33 | if: steps.cache.outputs.cache-hit != 'true' 34 | run: yarn install:clean 35 | 36 | lint: 37 | name: Eslint 38 | runs-on: ${{matrix.os}} 39 | strategy: 40 | matrix: 41 | os: [ubuntu-latest] 42 | node: [14] 43 | needs: setup 44 | steps: 45 | - uses: actions/checkout@v2 46 | with: 47 | fetch-depth: 0 48 | - uses: actions/setup-node@v2 49 | with: 50 | node-version: "14" 51 | - name: Use cache dependencies 52 | uses: actions/cache@v2 53 | id: cache 54 | with: 55 | path: "**/node_modules" 56 | key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}s 57 | - name: ESLint 58 | run: yarn lint:ci 59 | continue-on-error: true 60 | - name: Annotate Code Linting Results 61 | uses: ataylorme/eslint-annotate-action@1.2.0 62 | if: always() 63 | continue-on-error: true 64 | with: 65 | repo-token: "${{ secrets.GITHUB_TOKEN }}" 66 | report-json: "eslint_report.json" 67 | 68 | format: 69 | name: Prettier 70 | runs-on: ${{matrix.os}} 71 | strategy: 72 | matrix: 73 | os: [ubuntu-latest] 74 | node: [14] 75 | needs: setup 76 | steps: 77 | - uses: actions/checkout@v2 78 | with: 79 | fetch-depth: 0 80 | - uses: actions/setup-node@v2 81 | with: 82 | node-version: "14" 83 | - name: Use cache dependencies 84 | uses: actions/cache@v2 85 | id: cache 86 | with: 87 | path: "**/node_modules" 88 | key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}s 89 | - name: Prettier 90 | run: yarn format:check 91 | 92 | typecheck: 93 | name: Typescript 94 | runs-on: ${{matrix.os}} 95 | strategy: 96 | matrix: 97 | os: [ubuntu-latest] 98 | node: [14] 99 | needs: setup 100 | steps: 101 | - uses: actions/checkout@v2 102 | with: 103 | fetch-depth: 0 104 | - uses: actions/setup-node@v2 105 | with: 106 | node-version: "14" 107 | - name: Use cache dependencies 108 | uses: actions/cache@v2 109 | id: cache 110 | with: 111 | path: "**/node_modules" 112 | key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}s 113 | - name: Typecheck 114 | run: yarn tsc 115 | 116 | test: 117 | name: Tests 118 | runs-on: ${{matrix.os}} 119 | strategy: 120 | matrix: 121 | os: [ubuntu-latest] 122 | node: [14] 123 | needs: setup 124 | steps: 125 | - uses: actions/checkout@v2 126 | with: 127 | fetch-depth: 0 128 | - uses: actions/setup-node@v2 129 | with: 130 | node-version: "14" 131 | - name: Use cache dependencies 132 | uses: actions/cache@v2 133 | id: cache 134 | with: 135 | path: "**/node_modules" 136 | key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}s 137 | - name: Jest 138 | run: yarn test:ci 139 | 140 | publish: 141 | name: Publish 142 | if: | 143 | (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/beta') 144 | && !contains(github.event.commits[0].message, '[skip ci]') 145 | env: 146 | GH_TOKEN: ${{ secrets.GH_TOKEN }} 147 | GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} 148 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 149 | runs-on: ${{matrix.os}} 150 | strategy: 151 | matrix: 152 | os: [ubuntu-latest] 153 | node: [14] 154 | needs: [setup, lint, typecheck, test, format] 155 | steps: 156 | - uses: actions/checkout@v2 157 | with: 158 | fetch-depth: 0 159 | persist-credentials: false 160 | token: ${{ env.GH_TOKEN }} 161 | - uses: actions/setup-node@v2 162 | with: 163 | node-version: "14" 164 | - name: Use cache dependencies 165 | uses: actions/cache@v2 166 | id: cache 167 | with: 168 | path: "**/node_modules" 169 | key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}s 170 | - run: npx semantic-release 171 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea/* 3 | .nyc_output 4 | node_modules 5 | test 6 | src/**.js 7 | coverage 8 | *.log 9 | lib 10 | yarn-error.log 11 | .env 12 | tsconfig.tsbuildinfo -------------------------------------------------------------------------------- /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npm run pre-commit 5 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # package.json is formatted by package managers, so we ignore it here 2 | package.json 3 | CHANGELOG.md 4 | README.md 5 | *.d.ts 6 | lib 7 | eslint_report.json 8 | coverage -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 80, 3 | "trailingComma": "all" 4 | } 5 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true 3 | } 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [1.4.2](https://github.com/MoralisWeb3/react-moralis/compare/v1.4.1...v1.4.2) (2022-09-04) 2 | 3 | 4 | ### Bug Fixes 5 | 6 | * moralis dependency ([1aeb4fe](https://github.com/MoralisWeb3/react-moralis/commit/1aeb4fe9d01d7d649f88d21749388f7d9bf78a1f)) 7 | * moralis references ([ccfb51a](https://github.com/MoralisWeb3/react-moralis/commit/ccfb51af669fe12a1e451db66890070fe1cf0089)) 8 | * useNFTTransfers param type ([e551a3f](https://github.com/MoralisWeb3/react-moralis/commit/e551a3f672d95bd1abfce188efb20cd009a90813)) 9 | 10 | ## [1.4.1](https://github.com/MoralisWeb3/react-moralis/compare/v1.4.0...v1.4.1) (2022-08-10) 11 | 12 | 13 | ### Bug Fixes 14 | 15 | * updated moralis-v1 peerDependency ([#268](https://github.com/MoralisWeb3/react-moralis/issues/268)) ([37d26d9](https://github.com/MoralisWeb3/react-moralis/commit/37d26d9f8b0fa218261ac82bdec8a63747ed59a2)) 16 | 17 | # [1.4.0](https://github.com/MoralisWeb3/react-moralis/compare/v1.3.5...v1.4.0) (2022-05-29) 18 | 19 | 20 | ### Features 21 | 22 | * add Cronos support ([#251](https://github.com/MoralisWeb3/react-moralis/issues/251)) ([4cd48f7](https://github.com/MoralisWeb3/react-moralis/commit/4cd48f775a785f7f238693ba93363b0c89e2edf4)) 23 | 24 | ## [1.3.5](https://github.com/MoralisWeb3/react-moralis/compare/v1.3.4...v1.3.5) (2022-03-29) 25 | 26 | 27 | ### Bug Fixes 28 | 29 | * add repository url for semantic release ([#226](https://github.com/MoralisWeb3/react-moralis/issues/226)) ([3c73676](https://github.com/MoralisWeb3/react-moralis/commit/3c736769dc55ba0e1f8ea7f79d68c43ea9afa50f)) 30 | 31 | ## [1.3.4](https://github.com/MoralisWeb3/react-moralis/compare/v1.3.3...v1.3.4) (2022-03-21) 32 | 33 | 34 | ### Bug Fixes 35 | 36 | * typo in RaribleNetwork type ([#201](https://github.com/MoralisWeb3/react-moralis/issues/201)) ([0d7c608](https://github.com/MoralisWeb3/react-moralis/commit/0d7c6086f4c7675137ccb5f90b74c623694f7770)) 37 | 38 | ## [1.3.3](https://github.com/MoralisWeb3/react-moralis/compare/v1.3.2...v1.3.3) (2022-03-21) 39 | 40 | 41 | ### Bug Fixes 42 | 43 | * **deps:** bump follow-redirects from 1.14.7 to 1.14.8 ([#202](https://github.com/MoralisWeb3/react-moralis/issues/202)) ([e823213](https://github.com/MoralisWeb3/react-moralis/commit/e82321318cc3f183698ba688fb4e781ae579f6bd)) 44 | 45 | ## [1.3.2](https://github.com/MoralisWeb3/react-moralis/compare/v1.3.1...v1.3.2) (2022-03-01) 46 | 47 | 48 | ### Bug Fixes 49 | 50 | * types for connector options on authenticate ([#212](https://github.com/MoralisWeb3/react-moralis/issues/212)) ([8b6badb](https://github.com/MoralisWeb3/react-moralis/commit/8b6badb66764942887ede4deeefcf7055a1e1c69)) 51 | 52 | ## [1.3.1](https://github.com/MoralisWeb3/react-moralis/compare/v1.3.0...v1.3.1) (2022-02-09) 53 | 54 | 55 | ### Bug Fixes 56 | 57 | * isLoading check for array responses ([#200](https://github.com/MoralisWeb3/react-moralis/issues/200)) ([b0d8e7c](https://github.com/MoralisWeb3/react-moralis/commit/b0d8e7c73f3c19ebf47bf287c5c8851c8b7ae9ff)) 58 | 59 | # [1.3.0](https://github.com/MoralisWeb3/react-moralis/compare/v1.2.5...v1.3.0) (2022-02-09) 60 | 61 | 62 | ### Bug Fixes 63 | 64 | * import of AuthError from src ([#199](https://github.com/MoralisWeb3/react-moralis/issues/199)) ([f82057a](https://github.com/MoralisWeb3/react-moralis/commit/f82057ae682e0b0144e01b49201b107bb59a506d)) 65 | 66 | 67 | ### Features 68 | 69 | * resolve ens ([#197](https://github.com/MoralisWeb3/react-moralis/issues/197)) ([0c0ebd4](https://github.com/MoralisWeb3/react-moralis/commit/0c0ebd48c8ed05fe8fc7e8d6d5bb06a88c122a9d)) 70 | * return results on async requests ([#198](https://github.com/MoralisWeb3/react-moralis/issues/198)) ([ef53c48](https://github.com/MoralisWeb3/react-moralis/commit/ef53c48d8b8af2c4f6ea7317c3006b0701ef4527)) 71 | 72 | ## [1.2.5](https://github.com/MoralisWeb3/react-moralis/compare/v1.2.4...v1.2.5) (2022-02-07) 73 | 74 | 75 | ### Bug Fixes 76 | 77 | * add "sol" to AuthType (Typescript) ([#194](https://github.com/MoralisWeb3/react-moralis/issues/194)) ([21670cb](https://github.com/MoralisWeb3/react-moralis/commit/21670cb97c8b0ab208106339be8eda9c1a531b26)) 78 | 79 | ## [1.2.4](https://github.com/MoralisWeb3/react-moralis/compare/v1.2.3...v1.2.4) (2022-02-07) 80 | 81 | 82 | ### Bug Fixes 83 | 84 | * types for anyNetwork in enableWeb3 ([#192](https://github.com/MoralisWeb3/react-moralis/issues/192)) ([b053018](https://github.com/MoralisWeb3/react-moralis/commit/b053018b38d5fa1177ceaa2555e4c179838e0f37)) 85 | 86 | ## [1.2.3](https://github.com/MoralisWeb3/react-moralis/compare/v1.2.2...v1.2.3) (2022-02-07) 87 | 88 | 89 | ### Bug Fixes 90 | 91 | * optional initializeOnMount type ([6c5e4f0](https://github.com/MoralisWeb3/react-moralis/commit/6c5e4f0572973a9637f6ea69ba26ca4c4e92776b)) 92 | 93 | ## [1.2.2](https://github.com/MoralisWeb3/react-moralis/compare/v1.2.1...v1.2.2) (2022-02-04) 94 | 95 | 96 | ### Bug Fixes 97 | 98 | * setting chainId onChanChanged ([#189](https://github.com/MoralisWeb3/react-moralis/issues/189)) ([825f7ae](https://github.com/MoralisWeb3/react-moralis/commit/825f7ae0a4dc6c0953dcdb1763c841975ed02ba9)) 99 | 100 | ## [1.2.1](https://github.com/MoralisWeb3/react-moralis/compare/v1.2.0...v1.2.1) (2022-01-29) 101 | 102 | 103 | ### Bug Fixes 104 | 105 | * **deps:** bump node-fetch from 2.6.6 to 2.6.7 ([#182](https://github.com/MoralisWeb3/react-moralis/issues/182)) ([b0280a6](https://github.com/MoralisWeb3/react-moralis/commit/b0280a66251f53845946782407a6ba87a6d98cb2)) 106 | 107 | # [1.2.0](https://github.com/MoralisWeb3/react-moralis/compare/v1.1.1...v1.2.0) (2022-01-28) 108 | 109 | 110 | ### Features 111 | 112 | * optionally initialize Moralis on mount ([94d32c0](https://github.com/MoralisWeb3/react-moralis/commit/94d32c0530c2f4f5c3d27156aa1d538e63a184f2)) 113 | 114 | ## [1.1.1](https://github.com/MoralisWeb3/react-moralis/compare/v1.1.0...v1.1.1) (2022-01-28) 115 | 116 | 117 | ### Bug Fixes 118 | 119 | * update web3 on chain change ([#181](https://github.com/MoralisWeb3/react-moralis/issues/181)) ([f354c05](https://github.com/MoralisWeb3/react-moralis/commit/f354c05aebb72c72b92a1c067aaa01bcd7969477)) 120 | 121 | # [1.1.0](https://github.com/MoralisWeb3/react-moralis/compare/v1.0.4...v1.1.0) (2022-01-21) 122 | 123 | 124 | ### Features 125 | 126 | * support for Moralis.SolanaAPI ([efd9d12](https://github.com/MoralisWeb3/react-moralis/commit/efd9d1218460ff81b67a661706c78bd234763a20)) 127 | 128 | ## [1.0.4](https://github.com/MoralisWeb3/react-moralis/compare/v1.0.3...v1.0.4) (2022-01-20) 129 | 130 | 131 | ### Bug Fixes 132 | 133 | * support ethers web3 type ([#176](https://github.com/MoralisWeb3/react-moralis/issues/176)) ([5e5d09c](https://github.com/MoralisWeb3/react-moralis/commit/5e5d09c1fec2ec0287f0af6ae4ac918ba9e3cc04)) 134 | 135 | ## [1.0.3](https://github.com/MoralisWeb3/react-moralis/compare/v1.0.2...v1.0.3) (2022-01-20) 136 | 137 | 138 | ### Bug Fixes 139 | 140 | * typescript fixes support for Moralis v.1.0.6 ([#174](https://github.com/MoralisWeb3/react-moralis/issues/174)) ([9e3f574](https://github.com/MoralisWeb3/react-moralis/commit/9e3f574f4a15b27547089ba0de96aa7b74399890)) 141 | 142 | ## [1.0.2](https://github.com/MoralisWeb3/react-moralis/compare/v1.0.1...v1.0.2) (2022-01-19) 143 | 144 | 145 | ### Bug Fixes 146 | 147 | * **deps:** bump follow-redirects from 1.14.4 to 1.14.7 ([#150](https://github.com/MoralisWeb3/react-moralis/issues/150)) ([d1e1166](https://github.com/MoralisWeb3/react-moralis/commit/d1e116642fefe2283b12e8ea197c61af781b2d89)) 148 | 149 | ## [1.0.1](https://github.com/MoralisWeb3/react-moralis/compare/v1.0.0...v1.0.1) (2022-01-19) 150 | 151 | 152 | ### Bug Fixes 153 | 154 | * typings after ethers support ([989186a](https://github.com/MoralisWeb3/react-moralis/commit/989186a9d311edc9e20db40c53509a44fc7eee6f)) 155 | 156 | # [1.0.0](https://github.com/MoralisWeb3/react-moralis/compare/v0.3.11...v1.0.0) (2022-01-17) 157 | 158 | 159 | ### Bug Fixes 160 | 161 | * remove unused web3Library ([e83c2fa](https://github.com/MoralisWeb3/react-moralis/commit/e83c2fa60199f60c667fa329257d116546f0dc90)) 162 | * update provider on enableWeb3 ([76f3837](https://github.com/MoralisWeb3/react-moralis/commit/76f38371a9b53815a49e9433c4232135f4155fa4)) 163 | 164 | 165 | * feat!: bump version ([ae8d86b](https://github.com/MoralisWeb3/react-moralis/commit/ae8d86be071a7536b909b1fe5a9bf263f6875467)) 166 | * feat!: support for ethers refactor in moralis sdk ([32df645](https://github.com/MoralisWeb3/react-moralis/commit/32df64580bc93bd8a180fc44d45a3b7a9a0b78d4)) 167 | 168 | 169 | ### Features 170 | 171 | * add hooks for fiat plugin ([c1cfe24](https://github.com/MoralisWeb3/react-moralis/commit/c1cfe245a754c7c81b29d9302146174089a03d95)) 172 | * add hooks for opensea plugin ([998589b](https://github.com/MoralisWeb3/react-moralis/commit/998589b691efbb44a301f28e1b5c608d4701e171)) 173 | * add hooks for rarible plugin ([3d248ce](https://github.com/MoralisWeb3/react-moralis/commit/3d248ce14ae93c59114ba9f619c52e6b7f457811)) 174 | * remove obsolete awaitReceipt ([e1f55b5](https://github.com/MoralisWeb3/react-moralis/commit/e1f55b519bd13c2f86a66496622b8242881e279a)) 175 | 176 | 177 | ### BREAKING CHANGES 178 | 179 | * Support for Moralis.Web3 refactor 180 | * changes to accommodate for the breaking changes in the SDK, where web3 has been replaced for ethers 181 | 182 | # [1.0.0-beta.3](https://github.com/MoralisWeb3/react-moralis/compare/v1.0.0-beta.2...v1.0.0-beta.3) (2022-01-14) 183 | 184 | 185 | ### Bug Fixes 186 | 187 | * remove unused web3Library ([e83c2fa](https://github.com/MoralisWeb3/react-moralis/commit/e83c2fa60199f60c667fa329257d116546f0dc90)) 188 | 189 | # [1.0.0-beta.2](https://github.com/MoralisWeb3/react-moralis/compare/v1.0.0-beta.1...v1.0.0-beta.2) (2022-01-14) 190 | 191 | 192 | ### Bug Fixes 193 | 194 | * update provider on enableWeb3 ([76f3837](https://github.com/MoralisWeb3/react-moralis/commit/76f38371a9b53815a49e9433c4232135f4155fa4)) 195 | 196 | 197 | ### Features 198 | 199 | * remove obsolete awaitReceipt ([e1f55b5](https://github.com/MoralisWeb3/react-moralis/commit/e1f55b519bd13c2f86a66496622b8242881e279a)) 200 | 201 | # [1.0.0-beta.1](https://github.com/MoralisWeb3/react-moralis/compare/v0.4.0-beta.1...v1.0.0-beta.1) (2022-01-05) 202 | 203 | 204 | * feat!: support for ethers refactor in moralis sdk ([32df645](https://github.com/MoralisWeb3/react-moralis/commit/32df64580bc93bd8a180fc44d45a3b7a9a0b78d4)) 205 | 206 | 207 | ### BREAKING CHANGES 208 | 209 | * changes to accommodate for the breaking changes in the SDK, where web3 has been replaced for ethers 210 | 211 | # [0.4.0-beta.1](https://github.com/MoralisWeb3/react-moralis/compare/v0.3.11...v0.4.0-beta.1) (2021-12-22) 212 | 213 | 214 | ### Features 215 | 216 | * add hooks for fiat plugin ([c1cfe24](https://github.com/MoralisWeb3/react-moralis/commit/c1cfe245a754c7c81b29d9302146174089a03d95)) 217 | * add hooks for opensea plugin ([998589b](https://github.com/MoralisWeb3/react-moralis/commit/998589b691efbb44a301f28e1b5c608d4701e171)) 218 | * add hooks for rarible plugin ([3d248ce](https://github.com/MoralisWeb3/react-moralis/commit/3d248ce14ae93c59114ba9f619c52e6b7f457811)) 219 | 220 | ## [0.3.11](https://github.com/MoralisWeb3/react-moralis/compare/v0.3.10...v0.3.11) (2021-12-20) 221 | 222 | 223 | ### Bug Fixes 224 | 225 | * check for params in useOneInchQuote ([874176b](https://github.com/MoralisWeb3/react-moralis/commit/874176b89d61b98ed948b257c748dd6b8fd45e67)) 226 | 227 | ## [0.3.10](https://github.com/MoralisWeb3/react-moralis/compare/v0.3.9...v0.3.10) (2021-12-20) 228 | 229 | 230 | ### Bug Fixes 231 | 232 | * call to deprecated moralis.enable method ([#102](https://github.com/MoralisWeb3/react-moralis/issues/102)) ([e0f02e4](https://github.com/MoralisWeb3/react-moralis/commit/e0f02e4cf27602e4678e6abd81fc8c2c861a5e4f)) 233 | 234 | ## [0.3.9](https://github.com/MoralisWeb3/react-moralis/compare/v0.3.8...v0.3.9) (2021-12-20) 235 | 236 | 237 | ### Bug Fixes 238 | 239 | * update dependencies ([#115](https://github.com/MoralisWeb3/react-moralis/issues/115)) ([b4f2e91](https://github.com/MoralisWeb3/react-moralis/commit/b4f2e9175dfdf630c298d324c956a571df98802c)) 240 | 241 | # Changelog 242 | 243 | ### [0.3.8](https://github.com/MoralisWeb3/react-moralis/compare/v0.3.7...v0.3.8) (2021-12-18) 244 | 245 | ### [0.3.7](https://github.com/MoralisWeb3/react-moralis/compare/v0.3.6...v0.3.7) (2021-12-18) 246 | 247 | ### [0.3.6](https://github.com/MoralisWeb3/react-moralis/compare/v0.3.5...v0.3.6) (2021-12-18) 248 | 249 | ### [0.3.5](https://github.com/MoralisWeb3/react-moralis/compare/v0.3.2...v0.3.5) (2021-12-18) 250 | 251 | ### [0.3.2](https://github.com/MoralisWeb3/react-moralis/compare/v0.3.1...v0.3.2) (2021-12-17) 252 | 253 | 254 | ### Features 255 | 256 | * add blockexplorer for 0xa869 ([b22c0b7](https://github.com/MoralisWeb3/react-moralis/commits/b22c0b70d92a64ce7db843c320277a4c3279c102)) 257 | 258 | ### [0.3.1](https://github.com/MoralisWeb3/react-moralis/compare/v0.3.0...v0.3.1) (2021-12-06) 259 | 260 | ## [0.3.0](https://github.com/MoralisWeb3/react-moralis/compare/v0.2.8...v0.3.0) (2021-11-17) 261 | 262 | 263 | ### Features 264 | 265 | * add additional hooks ([a3a1e9e](https://github.com/MoralisWeb3/react-moralis/commits/a3a1e9e3cb662984b902d850a73f550cc47d40c9)) 266 | 267 | 268 | ### Bug Fixes 269 | 270 | * error logic in useChain ([fe74e06](https://github.com/MoralisWeb3/react-moralis/commits/fe74e06adc0f05d9f522c24f8f89ef1d8c5b160a)) 271 | * moralis dependency version ([4f1512d](https://github.com/MoralisWeb3/react-moralis/commits/4f1512d03f9b0e681a98d86937e95d9823cfa291)) 272 | 273 | ### [0.2.8](https://github.com/MoralisWeb3/react-moralis/compare/v0.2.7...v0.2.8) (2021-10-25) 274 | 275 | 276 | ### Features 277 | 278 | * update dependencies ([e6c46d1](https://github.com/MoralisWeb3/react-moralis/commits/e6c46d130acc1509901db485fa952710ec8ffb27)) 279 | 280 | 281 | ### Bug Fixes 282 | 283 | * linting errors ([de5e88a](https://github.com/MoralisWeb3/react-moralis/commits/de5e88ae92576d03dea0f51e5a9f4d22bb9d139c)) 284 | * make moralis import dynamic ([e3651d5](https://github.com/MoralisWeb3/react-moralis/commits/e3651d535dd8d178c926e85a59c2272b8e595c4f)) 285 | * remove circular dependencies ([1876130](https://github.com/MoralisWeb3/react-moralis/commits/1876130e409da55e9d557363932f5e6a1926f6b4)) 286 | 287 | ### [0.2.7](https://github.com/MoralisWeb3/react-moralis/compare/v0.2.6...v0.2.7) (2021-10-21) 288 | 289 | 290 | ### Features 291 | 292 | * support for react-native environment ([92a68bb](https://github.com/MoralisWeb3/react-moralis/commits/92a68bbeb476703c3af90cc7cf86220f07cc4229)) 293 | 294 | ### [0.2.6](https://github.com/MoralisWeb3/react-moralis/compare/v0.2.5...v0.2.6) (2021-10-12) 295 | 296 | 297 | ### Features 298 | 299 | * initialize moralis via start function ([2969060](https://github.com/MoralisWeb3/react-moralis/commits/296906032c11f32a25e2ad8ae1fdd222f9358bfe)) 300 | 301 | ### [0.2.5](https://github.com/MoralisWeb3/react-moralis/compare/v0.2.4...v0.2.5) (2021-10-12) 302 | 303 | ### [0.2.4](https://github.com/MoralisWeb3/react-moralis/compare/v0.2.3...v0.2.4) (2021-09-30) 304 | 305 | 306 | ### Features 307 | 308 | * add transfer and executefucnction hooks ([db3c5d9](https://github.com/MoralisWeb3/react-moralis/commits/db3c5d9a7545cd46e2607e07d76fc4c4e1770e89)) 309 | 310 | ### [0.2.3](https://github.com/MoralisWeb3/react-moralis/compare/v0.2.2...v0.2.3) (2021-09-13) 311 | 312 | 313 | ### Features 314 | 315 | * add signingMessage as authentication option ([9158b71](https://github.com/MoralisWeb3/react-moralis/commits/9158b71ee3546ba05900643d9e64b5a57c6824a7)) 316 | 317 | ### [0.2.2](https://github.com/MoralisWeb3/react-moralis/compare/v0.2.1...v0.2.2) (2021-09-08) 318 | 319 | 320 | ### Features 321 | 322 | * add chainId option for auth and enable ([01694cf](https://github.com/MoralisWeb3/react-moralis/commits/01694cfed0454b5d1449326a1270a609faab7aab)) 323 | * add refetchUserData ([a94198a](https://github.com/MoralisWeb3/react-moralis/commits/a94198a65c5f611f219b8bc0a53c7e03c94c51d7)) 324 | 325 | ### [0.2.1](https://github.com/MoralisWeb3/react-moralis/compare/v0.2.0...v0.2.1) (2021-08-26) 326 | 327 | 328 | ### Features 329 | 330 | * add moralisWeb3 api calls ([da9ec38](https://github.com/MoralisWeb3/react-moralis/commits/da9ec389f27c1e9fcb86493e847c32c5c5ae7bf4)) 331 | * update dependencies and use native TS ([c4b3146](https://github.com/MoralisWeb3/react-moralis/commits/c4b3146672cca45ea6e3e4aa970957e17d36114b)) 332 | 333 | 334 | ### Bug Fixes 335 | 336 | * use native typescript from moralis ([36c1e3b](https://github.com/MoralisWeb3/react-moralis/commits/36c1e3b671442144a79855370b2d2e9bfc302967)) 337 | 338 | ## [0.2.0](https://github.com/MoralisWeb3/react-moralis/compare/v0.1.10...v0.2.0) (2021-07-09) 339 | 340 | ### [0.1.10](https://github.com/MoralisWeb3/react-moralis/compare/v0.1.9...v0.1.10) (2021-07-09) 341 | 342 | 343 | ### Features 344 | 345 | * add walletconnect as provider ([4364d7c](https://github.com/MoralisWeb3/react-moralis/commits/4364d7c9ce6b5b4d1a466cfbc0469e817f2fc447)) 346 | 347 | 348 | ### Bug Fixes 349 | 350 | * isLoading state when no data ([97b549b](https://github.com/MoralisWeb3/react-moralis/commits/97b549b01538adf89383973e81c99c6df6744eba)) 351 | 352 | ### [0.1.9](https://github.com/MoralisWeb3/react-moralis/compare/v0.1.8...v0.1.9) (2021-05-21) 353 | 354 | 355 | ### Bug Fixes 356 | 357 | * typo authtype ([574e45c](https://github.com/MoralisWeb3/react-moralis/commits/574e45c3fcc69cbf848d6d3385899a34df7b68c3)) 358 | 359 | ### [0.1.8](https://github.com/MoralisWeb3/react-moralis/compare/v0.1.7...v0.1.8) (2021-05-20) 360 | 361 | 362 | ### Features 363 | 364 | * remove automatic enable of web3 ([af7bdac](https://github.com/MoralisWeb3/react-moralis/commits/af7bdac094dc9bb0adf6f6c5abe1f7b9f595897e)) 365 | * update dependency moralis 0.021 ([3db629f](https://github.com/MoralisWeb3/react-moralis/commits/3db629fc29f6b2a37ba5b9ef9cf283487e3ca70f)) 366 | 367 | ### [0.1.7](https://github.com/MoralisWeb3/react-moralis/compare/v0.1.6...v0.1.7) (2021-05-19) 368 | 369 | 370 | ### Features 371 | 372 | * enable elrond authentication ([23811b8](https://github.com/MoralisWeb3/react-moralis/commits/23811b8465a66ecb04f8b0ac5754aec5292e34a8)) 373 | 374 | ### [0.1.6](https://github.com/MoralisWeb3/react-moralis/compare/v0.1.6-alpha.0...v0.1.6) (2021-04-28) 375 | 376 | ### [0.1.6-alpha.0](https://github.com/MoralisWeb3/react-moralis/compare/v0.1.5...v0.1.6-alpha.0) (2021-04-28) 377 | 378 | 379 | ### Bug Fixes 380 | 381 | * reset local user on logout ([fce4730](https://github.com/MoralisWeb3/react-moralis/commits/fce4730f0a3d2655470ebc3e6789901c03ba0945)) 382 | 383 | ### [0.1.5](https://github.com/MoralisWeb3/react-moralis/compare/v0.1.4...v0.1.5) (2021-04-28) 384 | 385 | 386 | ### Bug Fixes 387 | 388 | * revert user changes on failed save ([f45d4df](https://github.com/MoralisWeb3/react-moralis/commits/f45d4dfe23b51fc064701bb3bd44f95c2276c5d5)) 389 | 390 | ### [0.1.4](https://github.com/MoralisWeb3/react-moralis/compare/v0.1.3...v0.1.4) (2021-04-28) 391 | 392 | ### [0.1.3](https://github.com/MoralisWeb3/react-moralis/compare/v0.1.2...v0.1.3) (2021-04-28) 393 | 394 | 395 | ### Bug Fixes 396 | 397 | * save local user state only after successfull Moralis save ([f788947](https://github.com/MoralisWeb3/react-moralis/commits/f7889473880c38a880f1834173a322db4387f064)) 398 | 399 | ### [0.1.2](https://github.com/MoralisWeb3/react-moralis/compare/v0.1.1...v0.1.2) (2021-04-27) 400 | 401 | 402 | ### Bug Fixes 403 | 404 | * account for non-window environment ([169e5a1](https://github.com/MoralisWeb3/react-moralis/commits/169e5a178d2e3bc36119600fe0f3e44f70b39039)) 405 | * prevent authenticated without an user state ([96b4fcb](https://github.com/MoralisWeb3/react-moralis/commits/96b4fcb6a0f96a75c85d1535b09a1096984e800c)) 406 | 407 | ### [0.1.1](https://github.com/MoralisWeb3/react-moralis/compare/v0.1.0...v0.1.1) (2021-04-19) 408 | 409 | ## [0.1.0](https://github.com/MoralisWeb3/react-moralis/compare/v0.0.4...v0.1.0) (2021-04-19) 410 | 411 | 412 | ### Features 413 | 414 | * add optional params to cloud function directly ([b2092bd](https://github.com/MoralisWeb3/react-moralis/commits/b2092bdcf3e3673cd3ebcef3d8e7ddf68ff0e715)) 415 | 416 | 417 | ### Bug Fixes 418 | 419 | * reset errors consistently ([49e90d3](https://github.com/MoralisWeb3/react-moralis/commits/49e90d3806d96d64eb34702ec1e02e7122e8bc92)) 420 | 421 | ### [0.0.4](https://github.com/MoralisWeb3/react-moralis/compare/v0.0.4-alpha.0...v0.0.4) (2021-04-17) 422 | 423 | ### [0.0.4-alpha.0](https://github.com/MoralisWeb3/react-moralis/compare/v0.0.3...v0.0.4-alpha.0) (2021-04-17) 424 | 425 | 426 | ### Features 427 | 428 | * add callbacks on async requests ([a34a5e1](https://github.com/MoralisWeb3/react-moralis/commits/a34a5e1bda56df5bcbe34bc3e277a70e595f9bfe)) 429 | * add useNewMoralisObject hook ([705d070](https://github.com/MoralisWeb3/react-moralis/commits/705d0700e1a609a2c3df43d40b875493826b9f3a)) 430 | * allow throwing errors on async functions ([01f0dc9](https://github.com/MoralisWeb3/react-moralis/commits/01f0dc99acddb99df127505d8b58f6114bee5dbd)) 431 | 432 | 433 | ### Bug Fixes 434 | 435 | * correctly unsubscribe for subscription listeners ([71b0481](https://github.com/MoralisWeb3/react-moralis/commits/71b0481edd5449874ccaf5ed89cf95e02f45ad38)) 436 | * sync user state correctly after authenticating ([ddacc91](https://github.com/MoralisWeb3/react-moralis/commits/ddacc91bb610cf80d830357b819a3213baddfb18)) 437 | 438 | ### [0.0.3](https://github.com/MoralisWeb3/react-moralis/compare/v0.0.2...v0.0.3) (2021-04-15) 439 | 440 | ### [0.0.2](https://github.com/MoralisWeb3/react-moralis/compare/v0.0.1...v0.0.2) (2021-04-15) 441 | 442 | ### [0.0.1](https://github.com/MoralisWeb3/react-moralis/compare/v0.0.1-alpha.0...v0.0.1) (2021-04-15) 443 | 444 | ### [0.0.1-alpha.0](https://github.com/MoralisWeb3/react-moralis/compare/v0.0.1-0...v0.0.1-alpha.0) (2021-04-15) 445 | 446 | ### 0.0.1-0 (2021-04-15) 447 | 448 | 449 | ### Features 450 | 451 | * :tada: Initial commit ([e596595](https://github.com/MoralisWeb3/react-moralis/commits/e596595b0c96f6e624e0c69303b99e26c6d74e9e)) 452 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | - Using welcoming and inclusive language 12 | - Being respectful of differing viewpoints and experiences 13 | - Gracefully accepting constructive criticism 14 | - Focusing on what is best for the community 15 | - Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | - The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | - Trolling, insulting/derogatory comments, and personal or political attacks 21 | - Public or private harassment 22 | - Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | - Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at hello@moralis.io. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CODING_STYLE.md: -------------------------------------------------------------------------------- 1 | # Coding Style 2 | 3 | - Most importantly, match the existing code style as much as possible. 4 | - Follow the ESlint rules for code-styling and Prettier rules for formatting 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to react-moralis 2 | 3 | ## Setting up the project for debugging and contributing 4 | 5 | ### Setting up you local machine: 6 | 7 | - [Fork](https://github.com/MoralisWeb3/react-moralis) this project and clone the fork on your local machine: 8 | 9 | ```sh 10 | git clone https://github.com/MoralisWeb3/react-moralis.git 11 | cd react-moralis # go into the clone directory 12 | npm install # install all the node dependencies 13 | ``` 14 | 15 | Make sure to have a ESlint and Prettier plugin installed to check for code-smells and auto-formatting. 16 | 17 | ### Building the repo 18 | 19 | When developing react-moralis you can use `yarn build:watch` in order to rebuild your changes upon each save. 20 | 21 | ### Pull Requests 22 | 23 | 1. Fork the repo and create your branch from `main`. 24 | 2. If you've changed APIs, update the documentation. 25 | 3. Make sure your code lints and is correctly formatted. 26 | 27 | ### Known Issues 28 | 29 | We use GitHub issues to track public bugs. We will keep a close eye on this and try to make it clear when we have an internal fix in progress. Before filing a new issue, try to make sure your problem doesn't already exist. 30 | 31 | ### Coding Style 32 | 33 | Please follow the [Coding Style](https://github.com/MoralisWeb3/react-moralis/blob/main/CODING_STYLE.md). 34 | 35 | ### Code of Conduct 36 | 37 | This project adheres to the [Contributor Covenant Code of Conduct](https://github.com/MoralisWeb3/react-moralis/blob/main/CODE_OF_CONDUCT.md). By participating, you are expected to honor this code. 38 | 39 | ## License 40 | 41 | By contributing to react-moralis, you agree that your contributions will be licensed under its license. 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Moralis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Moralis Responsible Disclosure Policy 2 | 3 | If you have found a security vulnerability in any of the systems provided by Moralis we encourage you to report it to us ASAP. 4 | We will investigate all legitimate reports and do our best to quickly fix the problem. 5 | 6 | Before making a report, please review this page to understand our disclosure policy and how to communicate with us. 7 | 8 | # Responsible Disclosure Policy 9 | 10 | If you comply with the policies below when reporting a security issue to Moralis, we will not initiate a lawsuit or law enforcement investigation against you in response to your report. 11 | 12 | We ask that: 13 | 14 | - You give us reasonable time to investigate and mitigate an issue you report before making public any information about the report or sharing such information with others. This means we request _at least_ **7 days** to get back to you with an initial response and _at least_ **30 days** from initial contact (made by you) to apply a patch. 15 | - You do not interact with an individual account (which includes modifying or accessing data from the account) if the account owner has not consented to such actions. 16 | - You make a good faith effort to avoid privacy violations and disruptions to others, including (but not limited to) destruction of data and interruption or degradation of our services. 17 | 18 | # Communicating with us 19 | 20 | All vulnerabilities should be privately reported to us by going to [Moralis Vulnerability Disclosure Program](https://app.intigriti.com/programs/moralis/moralisio/detail). 21 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | ["@babel/preset-env", { targets: { node: "current" } }], 4 | "@babel/preset-typescript", 5 | ], 6 | }; 7 | -------------------------------------------------------------------------------- /docs/head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoralisWeb3/react-moralis/d80b1cf556a0f2b151a8944e45d1ad1efc02275d/docs/head.png -------------------------------------------------------------------------------- /jest.config.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * For a detailed explanation regarding each configuration property and type check, visit: 3 | * https://jestjs.io/docs/configuration 4 | */ 5 | 6 | export default { 7 | // All imported modules in your tests should be mocked automatically 8 | // automock: false, 9 | 10 | // Stop running tests after `n` failures 11 | // bail: 0, 12 | 13 | // The directory where Jest should store its cached dependency information 14 | // cacheDirectory: "/private/var/folders/p0/h33hcp_57_76zkbgrg602_sc0000gn/T/jest_dx", 15 | 16 | // Automatically clear mock calls and instances between every test 17 | clearMocks: true, 18 | 19 | // Indicates whether the coverage information should be collected while executing the test 20 | collectCoverage: true, 21 | 22 | // An array of glob patterns indicating a set of files for which coverage information should be collected 23 | // collectCoverageFrom: undefined, 24 | 25 | // The directory where Jest should output its coverage files 26 | coverageDirectory: "coverage", 27 | 28 | // An array of regexp pattern strings used to skip coverage collection 29 | // coveragePathIgnorePatterns: [ 30 | // "/node_modules/" 31 | // ], 32 | 33 | // Indicates which provider should be used to instrument code for coverage 34 | // coverageProvider: "babel", 35 | 36 | // A list of reporter names that Jest uses when writing coverage reports 37 | // coverageReporters: [ 38 | // "json", 39 | // "text", 40 | // "lcov", 41 | // "clover" 42 | // ], 43 | 44 | // An object that configures minimum threshold enforcement for coverage results 45 | // coverageThreshold: undefined, 46 | 47 | // A path to a custom dependency extractor 48 | // dependencyExtractor: undefined, 49 | 50 | // Make calling deprecated APIs throw helpful error messages 51 | // errorOnDeprecated: false, 52 | 53 | // Force coverage collection from ignored files using an array of glob patterns 54 | // forceCoverageMatch: [], 55 | 56 | // A path to a module which exports an async function that is triggered once before all test suites 57 | // globalSetup: undefined, 58 | 59 | // A path to a module which exports an async function that is triggered once after all test suites 60 | // globalTeardown: undefined, 61 | 62 | // A set of global variables that need to be available in all test environments 63 | // globals: {}, 64 | 65 | // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers. 66 | // maxWorkers: "50%", 67 | 68 | // An array of directory names to be searched recursively up from the requiring module's location 69 | // moduleDirectories: [ 70 | // "node_modules" 71 | // ], 72 | 73 | // An array of file extensions your modules use 74 | // moduleFileExtensions: [ 75 | // "js", 76 | // "jsx", 77 | // "ts", 78 | // "tsx", 79 | // "json", 80 | // "node" 81 | // ], 82 | 83 | // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module 84 | // moduleNameMapper: {}, 85 | 86 | // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader 87 | // modulePathIgnorePatterns: [], 88 | 89 | // Activates notifications for test results 90 | // notify: false, 91 | 92 | // An enum that specifies notification mode. Requires { notify: true } 93 | // notifyMode: "failure-change", 94 | 95 | // A preset that is used as a base for Jest's configuration 96 | // preset: undefined, 97 | 98 | // Run tests from one or more projects 99 | // projects: undefined, 100 | 101 | // Use this configuration option to add custom reporters to Jest 102 | // reporters: undefined, 103 | 104 | // Automatically reset mock state between every test 105 | // resetMocks: false, 106 | 107 | // Reset the module registry before running each individual test 108 | // resetModules: false, 109 | 110 | // A path to a custom resolver 111 | // resolver: undefined, 112 | 113 | // Automatically restore mock state between every test 114 | // restoreMocks: false, 115 | 116 | // The root directory that Jest should scan for tests and modules within 117 | // rootDir: undefined, 118 | 119 | // A list of paths to directories that Jest should use to search for files in 120 | // roots: [ 121 | // "" 122 | // ], 123 | 124 | // Allows you to use a custom runner instead of Jest's default test runner 125 | // runner: "jest-runner", 126 | 127 | // The paths to modules that run some code to configure or set up the testing environment before each test 128 | // setupFiles: [], 129 | 130 | // A list of paths to modules that run some code to configure or set up the testing framework before each test 131 | // setupFilesAfterEnv: [], 132 | 133 | // The number of seconds after which a test is considered as slow and reported as such in the results. 134 | // slowTestThreshold: 5, 135 | 136 | // A list of paths to snapshot serializer modules Jest should use for snapshot testing 137 | // snapshotSerializers: [], 138 | 139 | // The test environment that will be used for testing 140 | testEnvironment: "jsdom", 141 | 142 | // Options that will be passed to the testEnvironment 143 | // testEnvironmentOptions: {}, 144 | 145 | // Adds a location field to test results 146 | // testLocationInResults: false, 147 | 148 | // The glob patterns Jest uses to detect test files 149 | // testMatch: [ 150 | // "**/__tests__/**/*.[jt]s?(x)", 151 | // "**/?(*.)+(spec|test).[tj]s?(x)" 152 | // ], 153 | 154 | // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped 155 | // testPathIgnorePatterns: [ 156 | // "/node_modules/" 157 | // ], 158 | 159 | // The regexp pattern or array of patterns that Jest uses to detect test files 160 | // testRegex: [], 161 | 162 | // This option allows the use of a custom results processor 163 | // testResultsProcessor: undefined, 164 | 165 | // This option allows use of a custom test runner 166 | // testRunner: "jest-circus/runner", 167 | 168 | // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href 169 | // testURL: "http://localhost", 170 | 171 | // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout" 172 | // timers: "real", 173 | 174 | // A map from regular expressions to paths to transformers 175 | // transform: undefined, 176 | 177 | // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation 178 | // transformIgnorePatterns: [ 179 | // "/node_modules/", 180 | // "\\.pnp\\.[^\\/]+$" 181 | // ], 182 | 183 | // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them 184 | // unmockedModulePathPatterns: undefined, 185 | 186 | // Indicates whether each individual test should be reported during the run 187 | // verbose: undefined, 188 | 189 | // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode 190 | // watchPathIgnorePatterns: [], 191 | 192 | // Whether to use watchman for file crawling 193 | // watchman: true, 194 | }; 195 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-moralis", 3 | "version": "1.4.2", 4 | "description": "Hooks and components to use Moralis in a React app", 5 | "keywords": [ 6 | "moralis-v1", 7 | "react", 8 | "react-hooks", 9 | "web3", 10 | "ethereum", 11 | "dapp", 12 | "frontend", 13 | "javascript", 14 | "typescript", 15 | "metamask" 16 | ], 17 | "homepage": "https://github.com/MoralisWeb3/react-moralis", 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/MoralisWeb3/react-moralis.git" 21 | }, 22 | "bugs": { 23 | "url": "https://github.com/MoralisWeb3/react-moralis/issues" 24 | }, 25 | "license": "MIT", 26 | "author": "Erno Wever ", 27 | "main": "lib/index.cjs.js", 28 | "module": "lib/index.esm.js", 29 | "types": "lib/index.d.ts", 30 | "files": [ 31 | "/lib" 32 | ], 33 | "engines": { 34 | "node": ">=v12.22.0" 35 | }, 36 | "devDependencies": { 37 | "@babel/core": "^7.16.5", 38 | "@babel/preset-env": "^7.16.5", 39 | "@babel/preset-typescript": "^7.16.5", 40 | "@commitlint/cli": "^16.0.1", 41 | "@commitlint/config-conventional": "^16.0.0", 42 | "@commitlint/prompt": "^15.0.0", 43 | "@rollup/plugin-commonjs": "^21.0.1", 44 | "@rollup/plugin-json": "^4.1.0", 45 | "@rollup/plugin-node-resolve": "^13.1.1", 46 | "@rollup/plugin-typescript": "^8.3.0", 47 | "@semantic-release/changelog": "^6.0.1", 48 | "@semantic-release/commit-analyzer": "^9.0.2", 49 | "@semantic-release/git": "^10.0.1", 50 | "@semantic-release/github": "^8.0.2", 51 | "@semantic-release/npm": "^8.0.3", 52 | "@semantic-release/release-notes-generator": "^10.0.3", 53 | "@types/jest": "^27.0.3", 54 | "@types/react": "^17.0.37", 55 | "@types/react-dom": "^17.0.11", 56 | "@typescript-eslint/eslint-plugin": "^5.7.0", 57 | "@typescript-eslint/parser": "^5.7.0", 58 | "babel-jest": "^27.4.5", 59 | "babel-loader": "8.2.3", 60 | "commitizen": "^4.2.4", 61 | "dotenv": "^10.0.0", 62 | "eslint": "8.5.0", 63 | "eslint-plugin-react": "^7.27.1", 64 | "husky": "^7.0.4", 65 | "jest": "^27.4.5", 66 | "lint-staged": "^12.1.2", 67 | "moralis-v1": "^1.11.0", 68 | "prettier": "^2.5.1", 69 | "rollup": "^2.61.1", 70 | "rollup-plugin-cleaner": "^1.0.0", 71 | "rollup-plugin-peer-deps-external": "^2.2.4", 72 | "rollup-plugin-typescript2": "^0.31.1", 73 | "rollup-watch": "^4.3.1", 74 | "semantic-release": "^18.0.1", 75 | "ts-loader": "^9.2.6", 76 | "tslib": "^2.3.1", 77 | "typescript": "^4.5.4" 78 | }, 79 | "peerDependencies": { 80 | "moralis-v1": ">=1.11.0", 81 | "react": ">=17.0.0", 82 | "react-dom": ">=17.0.0" 83 | }, 84 | "scripts": { 85 | "build": "rollup -c", 86 | "build:watch": "rollup -cw", 87 | "prepublishOnly": "yarn run build", 88 | "install:clean": "rm -rf node_modules && yarn install", 89 | "lint": "eslint ./src", 90 | "test": "jest", 91 | "test:ci": "jest", 92 | "lint:ci": "eslint --output-file eslint_report.json --format json ./src", 93 | "commit": "npm run git-cz", 94 | "format": "yarn prettier --write .", 95 | "format:check": "yarn prettier --check .", 96 | "tsc": "tsc", 97 | "prepare": "husky install", 98 | "pre-commit": "lint-staged", 99 | "semantic-release": "semantic-release" 100 | }, 101 | "lint-staged": { 102 | "*.js": [ 103 | "eslint" 104 | ], 105 | "*.{js,ts,html,css,md,json}": [ 106 | "prettier --write" 107 | ] 108 | }, 109 | "dependencies": { 110 | "fast-deep-equal": "^3.1.3", 111 | "immer": "^9.0.7", 112 | "use-immer": "^0.6.0" 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /release.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | repositoryUrl: "https://github.com/MoralisWeb3/react-moralis", 3 | branches: [ 4 | "main", 5 | { 6 | name: "beta", 7 | prerelease: true, 8 | }, 9 | ], 10 | plugins: [ 11 | "@semantic-release/commit-analyzer", 12 | "@semantic-release/release-notes-generator", 13 | [ 14 | "@semantic-release/changelog", 15 | { 16 | changelogFile: "CHANGELOG.md", 17 | }, 18 | ], 19 | "@semantic-release/npm", 20 | "@semantic-release/github", 21 | [ 22 | "@semantic-release/git", 23 | { 24 | assets: ["CHANGELOG.md", "package.json", "yarn.lock"], 25 | message: 26 | "chore(release): set `package.json` to ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}", 27 | }, 28 | ], 29 | ], 30 | }; 31 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import typescript from "rollup-plugin-typescript2"; 2 | import packageJson from "./package.json"; 3 | import peerDepsExternal from "rollup-plugin-peer-deps-external"; 4 | import cleaner from "rollup-plugin-cleaner"; 5 | import resolve from "@rollup/plugin-node-resolve"; 6 | import commonjs from "@rollup/plugin-commonjs"; 7 | import json from "@rollup/plugin-json"; 8 | 9 | export default { 10 | input: "src/index.ts", 11 | output: [ 12 | { 13 | file: packageJson.main, 14 | format: "cjs", 15 | sourcemap: true, 16 | }, 17 | { 18 | file: packageJson.module, 19 | format: "es", 20 | sourcemap: true, 21 | }, 22 | ], 23 | plugins: [ 24 | cleaner({ 25 | targets: ["./lib"], 26 | }), 27 | peerDepsExternal(), 28 | json(), 29 | resolve(), 30 | commonjs(), 31 | typescript({ useTsconfigDeclarationDir: true }), 32 | ], 33 | }; 34 | -------------------------------------------------------------------------------- /src/Errors.ts: -------------------------------------------------------------------------------- 1 | export class ReactMoralisError extends Error { 2 | static isReactMoraliserrpr = true; 3 | 4 | constructor(message: string) { 5 | super(`[react-moralis]: ${message}`); 6 | this.name = "ReactMoralisError"; 7 | this.message = message; 8 | } 9 | } 10 | 11 | export class NoMoralisContextProviderError extends ReactMoralisError { 12 | constructor(message: string) { 13 | super(message); 14 | this.name = "NoMoralisContextProviderError"; 15 | } 16 | } 17 | 18 | export class NotAuthenticatedError extends ReactMoralisError { 19 | constructor(message: string) { 20 | super(message); 21 | this.name = "NotAuthenticatedError"; 22 | } 23 | } 24 | 25 | export class ValidationError extends ReactMoralisError { 26 | constructor(message: string) { 27 | super(message); 28 | this.name = "ValidationError"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/components/ByMoralis/ByMoralis.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | const white = "#fff"; 4 | const brand = "#b7e803"; 5 | 6 | const PoweredByColour = ({ style }: { style?: React.CSSProperties }) => ( 7 | 8 | 12 | 13 | 17 | 21 | 22 | 23 | ); 24 | 25 | const PoweredByLight = ({ style }: { style?: React.CSSProperties }) => ( 26 | 27 | 31 | 32 | 33 | 37 | 38 | 39 | 40 | ); 41 | 42 | const PoweredByDark = ({ style }: { style?: React.CSSProperties }) => ( 43 | 44 | 45 | 49 | 53 | 57 | 61 | 62 | ); 63 | 64 | interface ByMoralisProps { 65 | width?: number; 66 | variant?: "colour" | "dark" | "light"; 67 | style?: React.CSSProperties; 68 | } 69 | 70 | export const ByMoralis = ({ 71 | variant = "colour", 72 | width = 250, 73 | style, 74 | }: ByMoralisProps) => { 75 | if (variant === "light") { 76 | return ; 77 | } 78 | if (variant === "dark") { 79 | return ; 80 | } 81 | return ; 82 | }; 83 | -------------------------------------------------------------------------------- /src/components/ByMoralis/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ByMoralis"; 2 | -------------------------------------------------------------------------------- /src/components/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ByMoralis"; 2 | -------------------------------------------------------------------------------- /src/config/index.ts: -------------------------------------------------------------------------------- 1 | import { components } from "moralis-v1/types/generated/web3Api"; 2 | export type ApiChain = components["schemas"]["chainList"]; 3 | 4 | export const DEFAULT_API_CHAIN: ApiChain = "eth"; 5 | 6 | export enum Plugin { 7 | ONE_INCH = "oneInch", 8 | OPEN_SEA = "opensea", 9 | FIAT = "fiat", 10 | RARIBLE = "rarible", 11 | } 12 | 13 | export const supportedChains = [ 14 | "0x1", 15 | "0x3", 16 | "0x4", 17 | "0x5", 18 | "0x2a", 19 | "0x38", 20 | "0x61", 21 | "0x89", 22 | "0x13881", 23 | "0xfa", 24 | "0xa86a", 25 | "0xa869", 26 | "0x539", 27 | "0x19", 28 | ]; 29 | -------------------------------------------------------------------------------- /src/context/MoralisContext/MoralisContext.ts: -------------------------------------------------------------------------------- 1 | import { createContext } from "react"; 2 | import MoralisType from "moralis-v1"; 3 | import { 4 | AuthenticateOptions, 5 | Authentication, 6 | Login, 7 | Signup, 8 | } from "../../hooks/core/useMoralis/_useMoralisAuth"; 9 | import { SetUserData } from "../../hooks/core/useMoralis/utils/setUserData"; 10 | import { Web3EnableOptions } from "../../hooks/core/useMoralis/_useMoralisWeb3"; 11 | import { Environment } from "../../hooks/core/useMoralis/_useMoralisInit"; 12 | 13 | export interface AuthError extends Error { 14 | code: number; 15 | } 16 | 17 | export interface MoralisContextValue { 18 | Moralis: MoralisType; 19 | environment: Environment; 20 | 21 | appId: string | null; 22 | serverUrl: string | null; 23 | 24 | isInitialized: boolean; 25 | isInitializing: boolean; 26 | initialize: (options?: { serverUrl?: string; appId?: string }) => void; 27 | 28 | authenticate: ( 29 | options?: AuthenticateOptions, 30 | ) => Promise; 31 | logout: () => Promise; 32 | signup: Signup; 33 | login: Login; 34 | 35 | auth: Authentication; 36 | authError: AuthError | null; 37 | isAuthenticated: boolean; 38 | isUnauthenticated: boolean; 39 | isAuthenticating: boolean; 40 | hasAuthError: boolean; 41 | isLoggingOut: boolean; 42 | isAuthUndefined: boolean; 43 | 44 | setUserData: (data: SetUserData) => Promise; 45 | user: MoralisType.User | null; 46 | _setUser: (user: MoralisType.User) => void; 47 | userError: null | Error; 48 | isUserUpdating: boolean; 49 | refetchUserData: () => Promise; 50 | 51 | enableWeb3: ( 52 | options?: Web3EnableOptions, 53 | ) => Promise; 54 | deactivateWeb3: () => Promise; 55 | web3: MoralisType.MoralisWeb3Provider | null; 56 | isWeb3Enabled: boolean; 57 | web3EnableError: Error | null; 58 | isWeb3EnableLoading: boolean; 59 | 60 | chainId: string | null; 61 | account: string | null; 62 | network: string | null; 63 | connector: unknown | null; 64 | connectorType: string | null; 65 | provider: unknown | null; 66 | } 67 | 68 | export const MoralisContext = createContext(null); 69 | -------------------------------------------------------------------------------- /src/context/MoralisContext/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./MoralisContext"; 2 | -------------------------------------------------------------------------------- /src/context/MoralisProvider/MoralisProvider.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { MoralisContext } from "../MoralisContext"; 3 | import { 4 | OnAccountChanged, 5 | _useMoralisAuth, 6 | } from "../../hooks/core/useMoralis/_useMoralisAuth"; 7 | import { 8 | Environment, 9 | GetMoralis, 10 | PluginSpecs, 11 | _useMoralisInit, 12 | } from "../../hooks/core/useMoralis/_useMoralisInit"; 13 | import { _useMoralisUser } from "../../hooks/core/useMoralis/_useMoralisUser"; 14 | import { _useMoralisWeb3 } from "../../hooks/core/useMoralis/_useMoralisWeb3"; 15 | 16 | interface MoralisProviderOptions { 17 | onAccountChanged?: OnAccountChanged; 18 | } 19 | 20 | export interface MoralisProviderCommonProps { 21 | children: React.ReactNode; 22 | jsKey?: string; 23 | dangerouslyUseOfMasterKey?: string; 24 | plugins?: PluginSpecs[]; 25 | options?: MoralisProviderOptions; 26 | environment?: Environment; 27 | getMoralis?: GetMoralis; 28 | } 29 | export interface MoralisProviderInitializedProps 30 | extends MoralisProviderCommonProps { 31 | appId: string; 32 | serverUrl: string; 33 | initializeOnMount?: true; 34 | } 35 | 36 | export interface MoralisProviderNonInitializedProps 37 | extends MoralisProviderCommonProps { 38 | appId?: null | string; 39 | serverUrl?: null | string; 40 | initializeOnMount: false; 41 | } 42 | 43 | type MoralisProviderProps = 44 | | MoralisProviderNonInitializedProps 45 | | MoralisProviderInitializedProps; 46 | 47 | export const MoralisProvider = ({ 48 | children, 49 | appId: _appId, 50 | serverUrl: _serverUrl, 51 | jsKey, 52 | dangerouslyUseOfMasterKey, 53 | plugins, 54 | environment, 55 | getMoralis, 56 | options: { onAccountChanged } = {}, 57 | initializeOnMount = true, 58 | }: MoralisProviderProps) => { 59 | const [appId, setAppId] = useState(_appId ?? null); 60 | const [serverUrl, setServerUrl] = useState(_serverUrl ?? null); 61 | 62 | const moralisInit = _useMoralisInit({ 63 | appId, 64 | serverUrl, 65 | jsKey, 66 | dangerouslyUseOfMasterKey, 67 | plugins, 68 | environment, 69 | getMoralis, 70 | initializeOnMount, 71 | setAppId, 72 | setServerUrl, 73 | }); 74 | const { _setIsWeb3Enabled, _setIsWeb3EnableLoading, ...moralisWeb3 } = 75 | _useMoralisWeb3(moralisInit.Moralis); 76 | const { setUser, ...moralisUser } = _useMoralisUser(moralisInit.Moralis); 77 | const moralisAuth = _useMoralisAuth({ 78 | onAccountChanged, 79 | setUser, 80 | Moralis: moralisInit.Moralis, 81 | environment: moralisInit.environment, 82 | _setIsWeb3Enabled, 83 | _setIsWeb3EnableLoading, 84 | }); 85 | 86 | return ( 87 | 97 | {children} 98 | 99 | ); 100 | }; 101 | -------------------------------------------------------------------------------- /src/context/MoralisProvider/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./MoralisProvider"; 2 | -------------------------------------------------------------------------------- /src/context/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./MoralisContext"; 2 | export * from "./MoralisProvider"; 3 | -------------------------------------------------------------------------------- /src/data/blockExplorers.ts: -------------------------------------------------------------------------------- 1 | export const blockExplorers: Record = { 2 | "0x1": "https://etherscan.io/", 3 | "0x3": "https://ropsten.etherscan.io/", 4 | "0x4": "https://rinkeby.etherscan.io/", 5 | "0x2a": "https://kovan.etherscan.io/", 6 | "0x5": "https://goerli.etherscan.io/", 7 | "0x539": null, 8 | "0xa86a": "https://cchain.explorer.avax.network/", 9 | "0xa869": "https://explorer.avax-test.network/", 10 | "0x38": "https://bscscan.com/", 11 | "0x61": "https://testnet.bscscan.com", 12 | "0x89": "https://explorer-mainnet.maticvigil.com", 13 | "0x13881": "https://mumbai.polygonscan.com", 14 | "0xfa": "https://ftmscan.com/", 15 | "0x19": "https://cronoscan.com/", 16 | }; 17 | -------------------------------------------------------------------------------- /src/functions/chains.ts: -------------------------------------------------------------------------------- 1 | import { supportedChains } from "../config"; 2 | import { blockExplorers } from "../data/blockExplorers"; 3 | import chains from "../data/chains"; 4 | import { decimalToHexString } from "../utils/formatters"; 5 | 6 | export const getSupportedChains = () => { 7 | return chains 8 | .filter((chain) => 9 | supportedChains.includes(decimalToHexString(chain.chainId)), 10 | ) 11 | .map((chainData) => ({ 12 | ...chainData, 13 | chainId: decimalToHexString(chainData.chainId), 14 | blockExplorerUrl: blockExplorers[decimalToHexString(chainData.chainId)], 15 | })); 16 | }; 17 | 18 | export const getChain = (chainId: string) => { 19 | return getSupportedChains().find((chain) => chain.chainId === chainId); 20 | }; 21 | -------------------------------------------------------------------------------- /src/functions/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./resolveIPFS"; 2 | export * from "./chains"; 3 | -------------------------------------------------------------------------------- /src/functions/resolveIPFS.test.ts: -------------------------------------------------------------------------------- 1 | import { resolveIPFS } from "./resolveIPFS"; 2 | 3 | describe("resolveLink", () => { 4 | test.each` 5 | value | expected 6 | ${"ipfs://QmTy8w65yBXgyfG2ZBg5TrfB2hPjrDQH3RCQFJGkARStJb"} | ${"https://gateway.ipfs.io/ipfs/QmTy8w65yBXgyfG2ZBg5TrfB2hPjrDQH3RCQFJGkARStJb"} 7 | ${"https://gateway.ipfs.io/ipfs/QmTy8w65yBXgyfG2ZBg5TrfB2hPjrDQH3RCQFJGkARStJb"} | ${"https://gateway.ipfs.io/ipfs/QmTy8w65yBXgyfG2ZBg5TrfB2hPjrDQH3RCQFJGkARStJb"} 8 | ${null} | ${null} 9 | ${undefined} | ${undefined} 10 | `("resolves link $value to $expected", ({ value, expected }) => { 11 | expect(resolveIPFS(value)).toBe(expected); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /src/functions/resolveIPFS.ts: -------------------------------------------------------------------------------- 1 | const IPFS_ROOT = "https://gateway.ipfs.io/ipfs/"; 2 | 3 | export const resolveIPFS = (url?: string | null) => { 4 | if (!url) { 5 | return url; 6 | } 7 | 8 | if (!url.includes("ipfs://") || !url) { 9 | return url; 10 | } 11 | 12 | return url.replace("ipfs://", IPFS_ROOT); 13 | }; 14 | -------------------------------------------------------------------------------- /src/hooks/core/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useChain"; 2 | export * from "./useMoralis"; 3 | export * from "./useMoralisCloudQuery"; 4 | export * from "./useMoralisFile"; 5 | export * from "./useMoralisObject"; 6 | export * from "./useMoralisQuery"; 7 | export * from "./useMoralisSubscription"; 8 | export * from "./useMoralisWeb3Api"; 9 | export * from "./useMoralisSolanaApi"; 10 | export * from "./useWeb3Contract"; 11 | export * from "./useWeb3ExecuteFunction"; 12 | export * from "./useWeb3Transfer"; 13 | -------------------------------------------------------------------------------- /src/hooks/core/useChain/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useChain"; 2 | -------------------------------------------------------------------------------- /src/hooks/core/useChain/useChain.ts: -------------------------------------------------------------------------------- 1 | import { useMemo } from "react"; 2 | import { getChain } from "../../../functions/chains"; 3 | import { useMoralis } from "../useMoralis"; 4 | 5 | export const useChain = () => { 6 | const { 7 | Moralis, 8 | chainId, 9 | account, 10 | network, 11 | provider, 12 | connector, 13 | connectorType, 14 | } = useMoralis(); 15 | 16 | const switchNetwork = async (providedChainId: string) => { 17 | try { 18 | await Moralis.switchNetwork(providedChainId); 19 | } catch (error) { 20 | if (error.code === 4902) { 21 | const chainData = getChain(providedChainId); 22 | 23 | if (!chainData) { 24 | throw new Error( 25 | `Chain ${providedChainId} not supported or is not specified`, 26 | ); 27 | } 28 | const { chainId, name, nativeCurrency, rpc, blockExplorerUrl } = 29 | chainData; 30 | 31 | await Moralis.addNetwork( 32 | chainId, 33 | name, 34 | nativeCurrency.name, 35 | nativeCurrency.symbol, 36 | rpc[0], 37 | blockExplorerUrl ?? null, 38 | ); 39 | } else { 40 | throw error; 41 | } 42 | } 43 | }; 44 | 45 | const chain = useMemo(() => { 46 | if (!chainId) { 47 | return null; 48 | } 49 | return getChain(chainId); 50 | }, [chainId]); 51 | 52 | return { 53 | switchNetwork, 54 | chainId, 55 | chain, 56 | account, 57 | network, 58 | provider, 59 | connector, 60 | connectorType, 61 | }; 62 | }; 63 | 64 | export default useChain; 65 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralis/_useMoralisAuth.ts: -------------------------------------------------------------------------------- 1 | import { useState, useCallback, useEffect } from "react"; 2 | import { setMultipleDataToUser, SetUserData } from "./utils/setUserData"; 3 | import { AuthError } from "../../../context/MoralisContext/MoralisContext"; 4 | import MoralisType from "moralis-v1"; 5 | import { Environment } from "./_useMoralisInit"; 6 | 7 | export enum AuthenticationState { 8 | UNDEFINED = "undefined", 9 | UNAUTHENTICATED = "unauthenticated", 10 | AUTHENTICATED = "authenticated", 11 | AUTHENTICATING = "authenticating", 12 | LOGGING_OUT = "logging_out", 13 | ERROR = "error", 14 | } 15 | 16 | export type Authentication = 17 | | { 18 | state: AuthenticationState.UNDEFINED; 19 | error: null; 20 | } 21 | | { 22 | state: AuthenticationState.UNAUTHENTICATED; 23 | error: null; 24 | } 25 | | { 26 | state: AuthenticationState.AUTHENTICATED; 27 | error: null; 28 | } 29 | | { 30 | state: AuthenticationState.AUTHENTICATING; 31 | error: null; 32 | } 33 | | { 34 | state: AuthenticationState.ERROR; 35 | error: Error; 36 | } 37 | | { 38 | state: AuthenticationState.LOGGING_OUT; 39 | error: null; 40 | }; 41 | 42 | const initialAuth: Authentication = { 43 | state: AuthenticationState.UNDEFINED, 44 | error: null, 45 | }; 46 | 47 | export type AuthenticateOptions = MoralisType.AuthenticationOptions & { 48 | onError?: (error: Error) => void; 49 | onSuccess?: (user: MoralisType.User) => void; 50 | onComplete?: () => void; 51 | throwOnError?: boolean; 52 | }; 53 | export interface SignupOptions { 54 | onError?: (error: Error) => void; 55 | onSuccess?: (user: MoralisType.User) => void; 56 | onComplete?: () => void; 57 | throwOnError?: boolean; 58 | } 59 | export interface LoginOptions { 60 | onError?: (error: Error) => void; 61 | onSuccess?: (user: MoralisType.User) => void; 62 | onComplete?: () => void; 63 | throwOnError?: boolean; 64 | usePost?: boolean; 65 | } 66 | 67 | export interface LogoutOptions { 68 | onError?: (error: Error) => void; 69 | onSuccess?: () => void; 70 | onComplete?: () => void; 71 | throwOnError?: boolean; 72 | } 73 | 74 | export type Login = ( 75 | username: string, 76 | password: string, 77 | options?: LoginOptions, 78 | ) => Promise | undefined>; 79 | 80 | export type Signup = ( 81 | username: string, 82 | password: string, 83 | email?: string, 84 | otherFields?: SetUserData, 85 | options?: SignupOptions, 86 | ) => Promise | undefined>; 87 | 88 | export type OnAccountChanged = (account: string) => void; 89 | 90 | export interface UseMoralisAuthOptions { 91 | onAccountChanged?: OnAccountChanged; 92 | setUser?: (user: MoralisType.User | null) => void; 93 | Moralis: MoralisType; 94 | environment: Environment; 95 | _setIsWeb3Enabled?: (value: boolean) => void; 96 | _setIsWeb3EnableLoading?: (value: boolean) => void; 97 | } 98 | 99 | const defaultUseMoralisAuthOptions = ( 100 | moralis: MoralisType, 101 | ): UseMoralisAuthOptions => ({ 102 | // We will override this right away, we just want to 103 | setUser: () => {}, 104 | Moralis: moralis, 105 | environment: "browser", 106 | }); 107 | 108 | /** 109 | * Hook that handles all authentication logic and returns the correct auth state 110 | * and its functions 111 | */ 112 | export const _useMoralisAuth = (options: UseMoralisAuthOptions) => { 113 | const { 114 | onAccountChanged, 115 | Moralis, 116 | environment, 117 | _setIsWeb3Enabled, 118 | _setIsWeb3EnableLoading, 119 | } = { 120 | ...defaultUseMoralisAuthOptions(options.Moralis), 121 | ...options, 122 | }; 123 | 124 | const setUser = options.setUser!; 125 | const [auth, setAuth] = useState(initialAuth); 126 | const [hasOnAccountChangeListener, setHasOnAccountChangeListener] = 127 | useState(false); 128 | 129 | /** 130 | * Authenticates the user by calling the Moralis.authenticate function 131 | * The auth state will update upon successful/error 132 | * For direct feedback, a callback can be provided 133 | */ 134 | const authenticate = useCallback( 135 | async ({ 136 | onComplete, 137 | onError, 138 | onSuccess, 139 | throwOnError, 140 | ...rest 141 | }: AuthenticateOptions = {}) => { 142 | setAuth({ 143 | state: AuthenticationState.AUTHENTICATING, 144 | error: null, 145 | }); 146 | 147 | if (_setIsWeb3EnableLoading) { 148 | _setIsWeb3EnableLoading(true); 149 | } 150 | 151 | try { 152 | // TODO: fix typechecking when passing ...rest 153 | const user = await Moralis.authenticate(rest); 154 | 155 | setUser(user); 156 | if (_setIsWeb3Enabled) { 157 | _setIsWeb3Enabled(true); 158 | } 159 | 160 | setAuth({ 161 | state: AuthenticationState.AUTHENTICATED, 162 | error: null, 163 | }); 164 | 165 | if (onSuccess) { 166 | onSuccess(user); 167 | } 168 | return user; 169 | } catch (error) { 170 | setAuth({ state: AuthenticationState.ERROR, error }); 171 | setUser(null); 172 | if (onError) { 173 | onError(error); 174 | } 175 | if (throwOnError) { 176 | throw error; 177 | } 178 | } finally { 179 | if (_setIsWeb3EnableLoading) { 180 | _setIsWeb3EnableLoading(false); 181 | } 182 | if (onComplete) { 183 | onComplete(); 184 | } 185 | } 186 | }, 187 | [_setIsWeb3Enabled, _setIsWeb3EnableLoading], 188 | ); 189 | 190 | /** 191 | * signup the user in with provided credentials 192 | */ 193 | const signup = useCallback( 194 | async ( 195 | username: string, 196 | password: string, 197 | email?: string, 198 | otherFields = {}, 199 | { throwOnError, onSuccess, onError, onComplete } = {}, 200 | ) => { 201 | setAuth({ 202 | state: AuthenticationState.AUTHENTICATING, 203 | error: null, 204 | }); 205 | 206 | const newUser = new Moralis.User(); 207 | 208 | setMultipleDataToUser( 209 | { 210 | username, 211 | password, 212 | email, 213 | ...otherFields, 214 | }, 215 | newUser, 216 | ); 217 | 218 | try { 219 | const user = await newUser.signUp(); 220 | setAuth({ 221 | state: AuthenticationState.AUTHENTICATED, 222 | error: null, 223 | }); 224 | setUser(user); 225 | if (onSuccess) { 226 | onSuccess(user); 227 | } 228 | return user; 229 | } catch (error) { 230 | setAuth({ state: AuthenticationState.ERROR, error }); 231 | if (throwOnError) { 232 | throw error; 233 | } 234 | if (onError) { 235 | onError(error); 236 | } 237 | } finally { 238 | if (onComplete) { 239 | onComplete(); 240 | } 241 | } 242 | }, 243 | [], 244 | ); 245 | /** 246 | * Logs the user in with provided credentials 247 | */ 248 | const login = useCallback( 249 | async ( 250 | username, 251 | password, 252 | { usePost, throwOnError, onError, onSuccess, onComplete } = {}, 253 | ) => { 254 | setAuth({ 255 | state: AuthenticationState.AUTHENTICATING, 256 | error: null, 257 | }); 258 | 259 | try { 260 | const user = await Moralis.User.logIn(username, password, { 261 | // @ts-ignore: missing types 262 | usePost, 263 | }); 264 | setAuth({ 265 | state: AuthenticationState.AUTHENTICATED, 266 | error: null, 267 | }); 268 | setUser(user); 269 | if (onSuccess) { 270 | onSuccess(user); 271 | } 272 | return user; 273 | } catch (error) { 274 | setAuth({ state: AuthenticationState.ERROR, error }); 275 | if (throwOnError) { 276 | throw error; 277 | } 278 | if (onError) { 279 | onError(error); 280 | } 281 | } finally { 282 | if (onComplete) { 283 | onComplete(); 284 | } 285 | } 286 | }, 287 | [], 288 | ); 289 | 290 | /** 291 | * Logs the user out via Moralis.User.logOut and handles the internal state 292 | */ 293 | const logout = useCallback( 294 | async ({ 295 | throwOnError, 296 | onError, 297 | onSuccess, 298 | onComplete, 299 | }: LogoutOptions = {}) => { 300 | setAuth({ 301 | state: AuthenticationState.AUTHENTICATING, 302 | error: null, 303 | }); 304 | 305 | try { 306 | await Moralis.User.logOut(); 307 | setAuth({ state: AuthenticationState.UNAUTHENTICATED, error: null }); 308 | setUser(null); 309 | if (onSuccess) { 310 | onSuccess(); 311 | } 312 | } catch (error) { 313 | setAuth({ state: AuthenticationState.ERROR, error }); 314 | // Set user to the currentUser (we don't know if the logout was successfull) 315 | setUser(Moralis.User.current() ?? null); 316 | if (throwOnError) { 317 | throw error; 318 | } 319 | if (onError) { 320 | onError(error); 321 | } 322 | } finally { 323 | if (onComplete) { 324 | onComplete(); 325 | } 326 | } 327 | }, 328 | [], 329 | ); 330 | 331 | /** 332 | * Update the auth state if the user already ahs authenticated before 333 | */ 334 | useEffect(() => { 335 | try { 336 | const currentUser = Moralis.User.current(); 337 | if (currentUser) { 338 | setAuth({ 339 | state: AuthenticationState.AUTHENTICATED, 340 | error: null, 341 | }); 342 | setUser(currentUser); 343 | } else { 344 | throw new Error("Let it catch"); 345 | } 346 | } catch (error) { 347 | setAuth({ 348 | state: AuthenticationState.UNAUTHENTICATED, 349 | error: null, 350 | }); 351 | setUser(null); 352 | } 353 | }, []); 354 | 355 | /** 356 | * Assign web3 Listener to handle change of accounts 357 | * 358 | * Important!: these eventListeners cannot be cleaned up, so don't reassign it 359 | * See https://github.com/MetaMask/metamask-extension/issues/10873 360 | * 361 | * The drawback of this is that we cannot update these function via a React state 362 | * // TODO: find a way to work around this 363 | */ 364 | useEffect(() => { 365 | if (hasOnAccountChangeListener) { 366 | return; 367 | } 368 | 369 | if (environment !== "browser") { 370 | // Currently only support browser environment 371 | return; 372 | } 373 | 374 | if (!window) { 375 | // eslint-disable-next-line no-console 376 | console.warn("No window object found"); 377 | return; 378 | } 379 | 380 | try { 381 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 382 | const ethereum = (window as any).ethereum; 383 | 384 | if (!ethereum) { 385 | // eslint-disable-next-line no-console 386 | console.warn("No window.ethereum found"); 387 | return; 388 | } 389 | ethereum.on("accountsChanged", async (accounts: string[]) => { 390 | const account = accounts[0]; 391 | 392 | if (onAccountChanged) { 393 | onAccountChanged(account); 394 | } 395 | }); 396 | } catch (error) { 397 | // eslint-disable-next-line no-console 398 | console.warn(error.message); 399 | } 400 | 401 | setHasOnAccountChangeListener(true); 402 | }, [hasOnAccountChangeListener]); 403 | 404 | const isAuthenticated = auth.state === AuthenticationState.AUTHENTICATED; 405 | const isUnauthenticated = auth.state === AuthenticationState.UNAUTHENTICATED; 406 | const isAuthenticating = auth.state === AuthenticationState.AUTHENTICATING; 407 | const hasAuthError = auth.state === AuthenticationState.ERROR; 408 | const isLoggingOut = auth.state === AuthenticationState.LOGGING_OUT; 409 | const isAuthUndefined = auth.state === AuthenticationState.UNDEFINED; 410 | 411 | return { 412 | auth, 413 | authenticate, 414 | signup, 415 | login, 416 | logout, 417 | authError: auth.error as AuthError, 418 | isAuthenticated, 419 | isUnauthenticated, 420 | isAuthenticating, 421 | hasAuthError, 422 | isLoggingOut, 423 | isAuthUndefined, 424 | }; 425 | }; 426 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralis/_useMoralisInit.ts: -------------------------------------------------------------------------------- 1 | import { useCallback, useEffect, useRef, useState } from "react"; 2 | import MoralisImport from "moralis-v1"; 3 | import { ReactMoralisError } from "../../../Errors"; 4 | 5 | export type Environment = "browser" | "native"; 6 | // TODO: get type from moralis-sdk 7 | export interface PluginSpecs { 8 | name: string; 9 | functions: string[]; 10 | } 11 | 12 | // TODO: fix any import (error: Types have separate declarations of a private property '_address) 13 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 14 | export type GetMoralis = () => any; 15 | 16 | /** 17 | * Hook that handles the initialization of Moralis 18 | */ 19 | export const _useMoralisInit = ({ 20 | appId, 21 | serverUrl, 22 | jsKey, 23 | dangerouslyUseOfMasterKey, 24 | plugins, 25 | environment = "browser", 26 | getMoralis = () => MoralisImport, 27 | initializeOnMount, 28 | setAppId, 29 | setServerUrl, 30 | }: { 31 | appId?: string | null; 32 | serverUrl?: string | null; 33 | jsKey?: string; 34 | dangerouslyUseOfMasterKey?: string; 35 | plugins?: PluginSpecs[]; 36 | environment?: "browser" | "native"; 37 | getMoralis?: GetMoralis; 38 | initializeOnMount: boolean; 39 | setAppId: (appId: string) => void; 40 | setServerUrl: (serverUrl: string) => void; 41 | }) => { 42 | const [isInitialized, setIsInitialized] = useState(false); 43 | const [isInitializing, setIsInitializing] = useState(false); 44 | const [shouldInitialize, setShouldInitialize] = useState(false); 45 | const Moralis = useRef(getMoralis()); 46 | 47 | const _initialize = useCallback( 48 | async ({ 49 | serverUrl, 50 | appId, 51 | javascriptKey, 52 | masterKey, 53 | plugins, 54 | }: { 55 | serverUrl?: null | string; 56 | appId?: null | string; 57 | javascriptKey?: string; 58 | masterKey?: string; 59 | plugins?: PluginSpecs[]; 60 | }) => { 61 | if (isInitialized) { 62 | return; 63 | } 64 | 65 | if (!appId) { 66 | throw new ReactMoralisError( 67 | `Provide a "appId" provided to `, 68 | ); 69 | } 70 | 71 | if (!serverUrl) { 72 | throw new ReactMoralisError( 73 | `Provide a "serverUrl" provided to `, 74 | ); 75 | } 76 | 77 | setIsInitializing(true); 78 | await Moralis.current.start({ 79 | serverUrl, 80 | appId, 81 | javascriptKey, 82 | masterKey, 83 | plugins, 84 | }); 85 | setIsInitializing(false); 86 | setIsInitialized(true); 87 | }, 88 | [], 89 | ); 90 | 91 | useEffect(() => { 92 | if (isInitialized) { 93 | return; 94 | } 95 | 96 | if (!initializeOnMount && !shouldInitialize) { 97 | return; 98 | } 99 | 100 | _initialize({ 101 | appId, 102 | serverUrl, 103 | masterKey: dangerouslyUseOfMasterKey, 104 | javascriptKey: jsKey, 105 | plugins, 106 | }); 107 | 108 | setIsInitialized(true); 109 | }, [ 110 | appId, 111 | serverUrl, 112 | dangerouslyUseOfMasterKey, 113 | jsKey, 114 | plugins, 115 | isInitialized, 116 | initializeOnMount, 117 | shouldInitialize, 118 | ]); 119 | 120 | const initialize = useCallback( 121 | ({ 122 | appId: newAppId, 123 | serverUrl: newServerUrl, 124 | }: { 125 | appId?: string; 126 | serverUrl?: string; 127 | } = {}) => { 128 | if (newAppId) { 129 | setAppId(newAppId); 130 | } 131 | if (newServerUrl) { 132 | setServerUrl(newServerUrl); 133 | } 134 | 135 | if (!newAppId && !appId) { 136 | throw new Error( 137 | "No appId is provided. Please provide an appId to the Moralis.Provider or as argument in initialize()", 138 | ); 139 | } 140 | if (!newServerUrl && !serverUrl) { 141 | throw new Error( 142 | "No serverUrl is provided. Please provide an serverUrl to the Moralis.Provider or as argument in initialize()", 143 | ); 144 | } 145 | setShouldInitialize(true); 146 | }, 147 | [appId, serverUrl], 148 | ); 149 | 150 | return { 151 | isInitialized, 152 | isInitializing, 153 | initialize, 154 | Moralis: Moralis.current, 155 | environment, 156 | }; 157 | }; 158 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralis/_useMoralisUser.ts: -------------------------------------------------------------------------------- 1 | import MoralisType from "moralis-v1"; 2 | import { useCallback, useState } from "react"; 3 | import { NotAuthenticatedError, ReactMoralisError } from "../../../Errors"; 4 | import { setMultipleDataToUser, SetUserData } from "./utils/setUserData"; 5 | 6 | export interface MoralisSetUserDataOptions { 7 | onError?: (error: Error) => void; 8 | onSuccess?: (user: MoralisType.User) => void; 9 | onComplete?: () => void; 10 | throwOnError?: boolean; 11 | } 12 | 13 | export interface RefetchUserOptions { 14 | onError?: (error: Error) => void; 15 | onSuccess?: (user: MoralisType.User) => void; 16 | onComplete?: () => void; 17 | throwOnError?: boolean; 18 | } 19 | 20 | export const _useMoralisUser = (Moralis: MoralisType) => { 21 | const [user, setUser] = useState(null); 22 | const [isUpdating, setIsUpdating] = useState(false); 23 | const [error, setError] = useState(null); 24 | 25 | /** 26 | * Function to change the userData, any changes made via this function will sync to Moralis AND the local state 27 | */ 28 | const setUserData = useCallback( 29 | async ( 30 | data: SetUserData, 31 | { 32 | throwOnError, 33 | onComplete, 34 | onError, 35 | onSuccess, 36 | }: MoralisSetUserDataOptions = {}, 37 | ) => { 38 | if (!user) { 39 | throw new NotAuthenticatedError( 40 | "User needs to be authenticated before setting new data", 41 | ); 42 | } 43 | 44 | setIsUpdating(true); 45 | setError(null); 46 | 47 | let userHasLocallyUpdated = false; 48 | 49 | try { 50 | setMultipleDataToUser(data, user); 51 | userHasLocallyUpdated = true; 52 | 53 | await user.save(); 54 | 55 | const currentUser = Moralis.User.current(); 56 | 57 | if (!currentUser) { 58 | throw new ReactMoralisError("No user data found after save"); 59 | } 60 | 61 | setUser(currentUser); 62 | 63 | if (onSuccess) { 64 | onSuccess(user); 65 | } 66 | return user; 67 | } catch (error) { 68 | if (userHasLocallyUpdated) { 69 | user.revert(); 70 | } 71 | 72 | setError(error); 73 | if (throwOnError) { 74 | throw error; 75 | } 76 | if (onError) { 77 | onError(error); 78 | } 79 | } finally { 80 | setIsUpdating(false); 81 | if (onComplete) { 82 | onComplete(); 83 | } 84 | } 85 | }, 86 | [user], 87 | ); 88 | 89 | /** 90 | * Function to refetch the user and update the user object 91 | */ 92 | const refetchUserData = useCallback( 93 | async ({ 94 | throwOnError, 95 | onComplete, 96 | onError, 97 | onSuccess, 98 | }: RefetchUserOptions = {}) => { 99 | if (!user) { 100 | throw new NotAuthenticatedError( 101 | "User needs to be authenticated before refetching", 102 | ); 103 | } 104 | 105 | setIsUpdating(true); 106 | setError(null); 107 | 108 | try { 109 | const newUserData = await user.fetch(); 110 | 111 | if (!newUserData) { 112 | throw new ReactMoralisError("No user data found after refetch"); 113 | } 114 | 115 | setUser(newUserData); 116 | 117 | if (onSuccess) { 118 | onSuccess(newUserData); 119 | } 120 | return newUserData; 121 | } catch (error) { 122 | setError(error); 123 | if (throwOnError) { 124 | throw error; 125 | } 126 | if (onError) { 127 | onError(error); 128 | } 129 | } finally { 130 | setIsUpdating(false); 131 | if (onComplete) { 132 | onComplete(); 133 | } 134 | } 135 | }, 136 | [user], 137 | ); 138 | 139 | return { 140 | setUserData, 141 | setUser, 142 | refetchUserData, 143 | user, 144 | _setUser: setUser, 145 | isUserUpdating: isUpdating, 146 | userError: error, 147 | }; 148 | }; 149 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralis/_useMoralisWeb3.ts: -------------------------------------------------------------------------------- 1 | import { useState, useCallback, useEffect, useMemo } from "react"; 2 | import MoralisType from "moralis-v1"; 3 | 4 | export type Web3EnableOptions = MoralisType.EnableOptions & { 5 | onError?: (error: Error) => void; 6 | onSuccess?: (web3: unknown) => void; 7 | onComplete?: () => void; 8 | throwOnError?: boolean; 9 | }; 10 | 11 | type EnableWeb3 = ( 12 | options?: Web3EnableOptions | undefined, 13 | ) => Promise; 14 | 15 | /** 16 | * Handles enabling of web3 and providing it, as soon as the user is authenticated 17 | */ 18 | export const _useMoralisWeb3 = ( 19 | Moralis: MoralisType, 20 | ): { 21 | enableWeb3: EnableWeb3; 22 | web3: null | MoralisType.MoralisWeb3Provider; 23 | isWeb3Enabled: boolean; 24 | web3EnableError: Error | null; 25 | isWeb3EnableLoading: boolean; 26 | _setIsWeb3Enabled: (value: boolean) => void; 27 | _setIsWeb3EnableLoading: (value: boolean) => void; 28 | chainId: null | string; 29 | account: null | string; 30 | network: null | string; 31 | connector: null | MoralisType.Connector; 32 | connectorType: null | string; 33 | deactivateWeb3: () => Promise; 34 | provider: null | MoralisType.Provider; 35 | } => { 36 | const [isWeb3Enabled, _setIsWeb3Enabled] = useState(false); 37 | const [web3EnableError, setEnableWeb3Error] = useState(null); 38 | const [isWeb3EnableLoading, _setIsWeb3EnableLoading] = useState(false); 39 | const [web3, setWeb3] = useState( 40 | null, 41 | ); 42 | const [chainId, setChainId] = useState(null); 43 | const [account, setAccount] = useState(null); 44 | const [connector, setConnector] = useState( 45 | null, 46 | ); 47 | const [provider, setProvider] = useState(null); 48 | 49 | useEffect(() => { 50 | const handleConnect = ({ 51 | web3, 52 | chainId, 53 | account, 54 | connector, 55 | provider, 56 | }: { 57 | web3: MoralisType.MoralisWeb3Provider; 58 | chainId: string | null; 59 | account: string | null; 60 | provider: MoralisType.Provider; 61 | connector: MoralisType.Connector; 62 | }) => { 63 | setWeb3(web3); 64 | setChainId(chainId); 65 | setAccount(account); 66 | setConnector(connector); 67 | setProvider(provider); 68 | }; 69 | 70 | const handleDisconnect = () => { 71 | setWeb3(null); 72 | _setIsWeb3Enabled(false); 73 | setChainId(null); 74 | setAccount(null); 75 | setConnector(null); 76 | setProvider(null); 77 | }; 78 | 79 | const handleChainChanged = (chainId: string | null) => { 80 | setChainId(chainId); 81 | setWeb3(Moralis.web3); 82 | }; 83 | 84 | const unsubChainChanged = Moralis.onChainChanged(handleChainChanged); 85 | const unsubAccountChanged = Moralis.onAccountChanged(setAccount); 86 | const unsubEnable = Moralis.onWeb3Enabled(handleConnect); 87 | const unsubDeactivate = Moralis.onWeb3Deactivated(handleDisconnect); 88 | const unsubDisconnect = Moralis.onDisconnect(handleDisconnect); 89 | 90 | return () => { 91 | unsubChainChanged(); 92 | unsubAccountChanged(); 93 | unsubEnable(); 94 | unsubDeactivate(); 95 | unsubDisconnect(); 96 | }; 97 | }, [Moralis]); 98 | 99 | /** 100 | * Enable web3 with the browsers web3Provider (only available when a user has been authenticated) 101 | */ 102 | const enableWeb3 = useCallback( 103 | async ({ 104 | throwOnError, 105 | onComplete, 106 | onError, 107 | onSuccess, 108 | ...rest 109 | }: Web3EnableOptions = {}) => { 110 | _setIsWeb3EnableLoading(true); 111 | setEnableWeb3Error(null); 112 | 113 | try { 114 | // TODO: fix typechecking when passing ...rest 115 | // @ts-ignore 116 | const currentWeb3: MoralisType.Web3Provider = await Moralis.enableWeb3( 117 | rest, 118 | ); 119 | 120 | _setIsWeb3Enabled(true); 121 | 122 | if (onSuccess) { 123 | onSuccess(currentWeb3); 124 | } 125 | return currentWeb3; 126 | } catch (error) { 127 | setEnableWeb3Error(error); 128 | if (throwOnError) { 129 | throw error; 130 | } 131 | if (onError) { 132 | onError(error); 133 | } 134 | } finally { 135 | _setIsWeb3EnableLoading(false); 136 | if (onComplete) { 137 | onComplete(); 138 | } 139 | } 140 | }, 141 | [], 142 | ); 143 | 144 | // TODO: resolver errors/loading state 145 | const deactivateWeb3 = useCallback(async () => { 146 | await Moralis.deactivateWeb3(); 147 | }, []); 148 | 149 | const network = useMemo(() => connector?.network ?? null, [connector]); 150 | const connectorType = useMemo(() => connector?.type ?? null, [connector]); 151 | 152 | return { 153 | enableWeb3, 154 | web3, 155 | isWeb3Enabled, 156 | web3EnableError, 157 | isWeb3EnableLoading, 158 | _setIsWeb3Enabled, 159 | _setIsWeb3EnableLoading, 160 | chainId, 161 | account, 162 | network, 163 | connector, 164 | connectorType, 165 | deactivateWeb3, 166 | provider, 167 | }; 168 | }; 169 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralis/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useMoralis"; 2 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralis/useMoralis.ts: -------------------------------------------------------------------------------- 1 | import { useContext } from "react"; 2 | import { MoralisContext } from "../../../context/MoralisContext"; 3 | import { NoMoralisContextProviderError } from "../../../Errors"; 4 | 5 | export const useMoralis = () => { 6 | const moralisContext = useContext(MoralisContext); 7 | 8 | if (!moralisContext) { 9 | throw new NoMoralisContextProviderError( 10 | "Make sure to only call useMoralis within a ", 11 | ); 12 | } 13 | 14 | return moralisContext; 15 | }; 16 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralis/utils/setUserData.ts: -------------------------------------------------------------------------------- 1 | import MoralisType from "moralis-v1"; 2 | import { ValidationError } from "../../../../Errors"; 3 | 4 | // UserData can accept all these types 5 | // undefined values will be filtered, null values will be set to null 6 | export type UserDataValue = 7 | | string 8 | | number 9 | | boolean 10 | | MoralisType.File 11 | | undefined 12 | | null; 13 | 14 | export type SetUserData = Record; 15 | 16 | export const setMultipleDataToUser = ( 17 | data: SetUserData, 18 | user: MoralisType.User, 19 | ) => { 20 | // We use the specified functions to set password, email, and username 21 | const { password, email, username, ...restData } = data; 22 | 23 | if (password !== undefined) { 24 | if (typeof password !== "string") { 25 | throw new ValidationError("password can only be a string type"); 26 | } 27 | user.setPassword(password); 28 | } 29 | 30 | if (email !== undefined) { 31 | if (typeof email !== "string") { 32 | throw new ValidationError("email can only be a string type"); 33 | } 34 | user.setEmail(email); 35 | } 36 | 37 | if (username !== undefined) { 38 | if (typeof username !== "string") { 39 | throw new ValidationError("username can only be a string type"); 40 | } 41 | user.setUsername(username); 42 | } 43 | 44 | Object.entries(restData) 45 | .filter(([, value]) => value !== undefined) 46 | .forEach(([key, value]) => { 47 | user.set(key, value); 48 | }); 49 | }; 50 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralisCloudQuery/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useMoralisCloudFunction"; 2 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralisCloudQuery/useMoralisCloudFunction.ts: -------------------------------------------------------------------------------- 1 | import { useCallback } from "react"; 2 | import { useMoralis } from "../useMoralis"; 3 | import { 4 | UseResolveCallOptions, 5 | _useResolveCall, 6 | } from "../../internal/_useResolveAsyncCall"; 7 | 8 | export type MoralisCloudResult = unknown; 9 | 10 | export interface UseMoralisCloudFunctionOptions extends UseResolveCallOptions {} 11 | 12 | export type MoralisCloudFunctionParameters = Record; 13 | 14 | export interface MoralisCloudFetchOptions { 15 | onError?: (error: Error) => void; 16 | onSuccess?: (results: MoralisCloudResult) => void; 17 | onComplete?: () => void; 18 | throwOnError?: boolean; 19 | params?: MoralisCloudFunctionParameters; 20 | } 21 | 22 | export const useMoralisCloudFunction = ( 23 | name: string, 24 | params?: MoralisCloudFunctionParameters, 25 | options?: UseMoralisCloudFunctionOptions, 26 | ) => { 27 | const { Moralis } = useMoralis(); 28 | const call = useCallback( 29 | (callParams?: MoralisCloudFunctionParameters) => 30 | Moralis.Cloud.run(name, callParams), 31 | [name], 32 | ); 33 | 34 | return _useResolveCall( 35 | call, 36 | null, 37 | params, 38 | options, 39 | ); 40 | }; 41 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralisFile/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useMoralisFile"; 2 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralisFile/useMoralisFile.ts: -------------------------------------------------------------------------------- 1 | import MoralisType from "moralis-v1"; 2 | import { useCallback, useState } from "react"; 3 | import { useMoralis } from "../useMoralis"; 4 | 5 | export type ValidFileInput = 6 | | number[] 7 | | { base64: string } 8 | | { size: number; type: string } 9 | | { uri: string }; 10 | 11 | export interface MoralisFileSaveOptions { 12 | type?: string; 13 | metadata?: Record; 14 | tags?: Record; 15 | saveIPFS?: boolean; 16 | onError?: (error: Error) => void; 17 | onSuccess?: (result: MoralisType.File) => void; 18 | onComplete?: () => void; 19 | throwOnError?: boolean; 20 | } 21 | 22 | export const useMoralisFile = () => { 23 | const { Moralis } = useMoralis(); 24 | const [error, setError] = useState(null); 25 | const [isUploading, setIsUploading] = useState(false); 26 | const [moralisFile, setMoralisFile] = useState(null); 27 | /** 28 | * Save the provided file 29 | */ 30 | const saveFile = useCallback( 31 | async ( 32 | name: string, 33 | file: ValidFileInput, 34 | { 35 | type, 36 | metadata, 37 | tags, 38 | saveIPFS, 39 | throwOnError, 40 | onComplete, 41 | onError, 42 | onSuccess, 43 | }: MoralisFileSaveOptions = {}, 44 | ) => { 45 | try { 46 | setIsUploading(true); 47 | setError(null); 48 | 49 | const moralisFile = new Moralis.File( 50 | name, 51 | file, 52 | type, 53 | //@ts-ignore type is different than documentation (it should accept metadata and tags) 54 | metadata, 55 | tags, 56 | ); 57 | 58 | if (saveIPFS) { 59 | await moralisFile.saveIPFS(); 60 | } else { 61 | await moralisFile.save(); 62 | } 63 | 64 | setMoralisFile(moralisFile); 65 | 66 | if (onSuccess) { 67 | onSuccess(moralisFile); 68 | } 69 | 70 | return moralisFile; 71 | } catch (error) { 72 | setError(error); 73 | if (throwOnError) { 74 | throw error; 75 | } 76 | if (onError) { 77 | onError(error); 78 | } 79 | } finally { 80 | setIsUploading(false); 81 | if (onComplete) { 82 | onComplete(); 83 | } 84 | } 85 | }, 86 | [], 87 | ); 88 | 89 | return { 90 | error, 91 | saveFile, 92 | isUploading, 93 | moralisFile, 94 | }; 95 | }; 96 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralisObject/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useNewMoralisObject"; 2 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralisObject/useNewMoralisObject.ts: -------------------------------------------------------------------------------- 1 | import MoralisType from "moralis-v1"; 2 | import { useCallback, useState } from "react"; 3 | import { useMoralis } from "../useMoralis"; 4 | 5 | export interface MoralisObjectSaveOptions { 6 | cascadeSave?: boolean; 7 | context?: unknown; 8 | onError?: (error: Error) => void; 9 | onSuccess?: (result: MoralisType.Object) => void; 10 | onComplete?: () => void; 11 | throwOnError?: boolean; 12 | } 13 | 14 | export type MoralisObjectSaveData = Record; 15 | 16 | /** 17 | * A hook for making/saving new Moralis Objects 18 | */ 19 | export const useNewMoralisObject = (objectClassName: string) => { 20 | const { Moralis } = useMoralis(); 21 | const [isSaving, setIsSaving] = useState(false); 22 | const [error, setError] = useState(null); 23 | const [object, setObject] = useState(null); 24 | 25 | /** 26 | * Save function to save data to the object 27 | */ 28 | const save = useCallback( 29 | async ( 30 | data: MoralisObjectSaveData = {}, 31 | { 32 | cascadeSave, 33 | throwOnError, 34 | context, 35 | onSuccess, 36 | onComplete, 37 | onError, 38 | }: MoralisObjectSaveOptions = {}, 39 | ) => { 40 | setIsSaving(true); 41 | setError(null); 42 | 43 | try { 44 | const Object = Moralis.Object.extend(objectClassName); 45 | const object = new Object(); 46 | 47 | // TODO: support saving of nested objects more easy? 48 | 49 | // @ts-ignore (context does not exist in the save options type) 50 | await object.save(data, { cascadeSave, context }); 51 | setObject(object); 52 | 53 | if (onSuccess) { 54 | onSuccess(object); 55 | } 56 | return object; 57 | } catch (error) { 58 | setError(error); 59 | if (throwOnError) { 60 | throw error; 61 | } 62 | if (onError) { 63 | onError(error); 64 | } 65 | } finally { 66 | setIsSaving(false); 67 | if (onComplete) { 68 | onComplete(); 69 | } 70 | } 71 | }, 72 | [objectClassName], 73 | ); 74 | 75 | return { 76 | isSaving, 77 | object, 78 | error, 79 | save, 80 | }; 81 | }; 82 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralisQuery/_useSafeUpdatedQuery.ts: -------------------------------------------------------------------------------- 1 | import MoralisType from "moralis-v1"; 2 | import { useMemo } from "react"; 3 | import { useMoralis } from "../useMoralis"; 4 | import { Query } from "../../../utils/genericQuery"; 5 | 6 | /** 7 | * Wrapper hook for using with queries. 8 | * It accepts a valid query (string or Moralis.Object), 9 | * and a mapping to filter the query 10 | * 11 | * It will only update when the provided dependencies change 12 | */ 13 | export const _useSafeUpdatedQuery = < 14 | Entity extends MoralisType.Attributes = MoralisType.Attributes, 15 | >( 16 | nameOrObject: string | MoralisType.Object, 17 | queryMap: (q: Query) => Query = (q) => q, 18 | dependencies: unknown[] = [], 19 | isInitialized: boolean, 20 | ) => { 21 | const { Moralis } = useMoralis(); 22 | // Cached version of the queruMap to prevent unwantedUpdates 23 | const currentQueryMap = useMemo(() => { 24 | return queryMap; 25 | }, dependencies); 26 | const currentNameOrObject = useMemo(() => { 27 | return nameOrObject; 28 | }, dependencies); 29 | 30 | const query = useMemo(() => { 31 | const q = new Moralis.Query>( 32 | // Explicit cast to any to prevent ts-error, because Moralis.Query should accept a Moralis.object 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | currentNameOrObject as any, 35 | ); 36 | return currentQueryMap(q); 37 | }, [isInitialized, currentNameOrObject, currentQueryMap]); 38 | 39 | return query; 40 | }; 41 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralisQuery/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useMoralisQuery"; 2 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralisQuery/useMoralisQuery.ts: -------------------------------------------------------------------------------- 1 | import { WritableDraft } from "immer/dist/internal"; 2 | import MoralisType from "moralis-v1"; 3 | import { useCallback } from "react"; 4 | import { DefaultQueryAttribute, Query } from "../../../utils/genericQuery"; 5 | import { useMoralis } from "../useMoralis"; 6 | import { useMoralisSubscription } from "../useMoralisSubscription"; 7 | import { 8 | UseResolveCallOptions, 9 | _useResolveCall, 10 | } from "../../internal/_useResolveAsyncCall"; 11 | import { _useSafeUpdatedQuery } from "./_useSafeUpdatedQuery"; 12 | 13 | export interface MoralisQueryFetchOptions { 14 | onError?: (error: Error) => void; 15 | onSuccess?: (result: MoralisType.Object[]) => void; 16 | onComplete?: () => void; 17 | throwOnError?: boolean; 18 | } 19 | 20 | export type OnLiveHandler = ( 21 | entity: MoralisType.Object, 22 | all: 23 | | MoralisType.Object[] 24 | | WritableDraft>[], 25 | ) => MoralisType.Object[]; 26 | 27 | export interface UseMoralisQueryOptions 28 | extends UseResolveCallOptions { 29 | live?: boolean; 30 | onLiveCreate?: OnLiveHandler; 31 | onLiveEnter?: OnLiveHandler; 32 | onLiveLeave?: OnLiveHandler; 33 | onLiveUpdate?: OnLiveHandler; 34 | onLiveDelete?: OnLiveHandler; 35 | } 36 | 37 | const defaultUseMoralisQueryOptions: UseMoralisQueryOptions = { 38 | autoFetch: true, 39 | live: false, 40 | onLiveEnter: (entity, all) => [...all, entity], 41 | onLiveCreate: (entity, all) => [...all, entity], 42 | onLiveDelete: (entity, all) => all.filter((e) => e.id !== entity.id), 43 | onLiveLeave: (entity, all) => all.filter((e) => e.id !== entity.id), 44 | onLiveUpdate: (entity, all) => 45 | all.map((e) => (e.id === entity.id ? entity : e)), 46 | }; 47 | 48 | export const useMoralisQuery = < 49 | Entity extends MoralisType.Attributes = MoralisType.Attributes, 50 | >( 51 | nameOrObject: string | MoralisType.Object, 52 | queryMap: (q: Query) => Query = (q) => q, 53 | dependencies: unknown[] = [], 54 | options: UseMoralisQueryOptions = {}, 55 | ) => { 56 | const { isInitialized } = useMoralis(); 57 | const { 58 | live, 59 | onLiveCreate, 60 | onLiveDelete, 61 | onLiveEnter, 62 | onLiveLeave, 63 | onLiveUpdate, 64 | } = { 65 | ...defaultUseMoralisQueryOptions, 66 | ...options, 67 | }; 68 | const query = _useSafeUpdatedQuery( 69 | nameOrObject, 70 | queryMap, 71 | dependencies, 72 | isInitialized, 73 | ); 74 | 75 | const call = useCallback(() => query.find(), [query]); 76 | 77 | const { data, error, fetch, isFetching, isLoading, setData } = 78 | _useResolveCall[], object>( 79 | call, 80 | [], 81 | undefined, 82 | options, 83 | ); 84 | 85 | const handleOnCreate = useCallback( 86 | (entity) => { 87 | if (onLiveCreate) { 88 | setData((data) => onLiveCreate(entity, data)); 89 | } 90 | }, 91 | [onLiveCreate], 92 | ); 93 | 94 | const handleOnEnter = useCallback( 95 | (entity) => { 96 | if (onLiveEnter) { 97 | setData((data) => onLiveEnter(entity, data)); 98 | } 99 | }, 100 | [onLiveEnter], 101 | ); 102 | 103 | const handleOnUpdate = useCallback( 104 | (entity) => { 105 | if (onLiveUpdate) { 106 | setData((data) => onLiveUpdate(entity, data)); 107 | } 108 | }, 109 | [onLiveUpdate], 110 | ); 111 | 112 | const handleOnDelete = useCallback( 113 | (entity) => { 114 | if (onLiveDelete) { 115 | setData((data) => onLiveDelete(entity, data)); 116 | } 117 | }, 118 | [onLiveDelete], 119 | ); 120 | 121 | const handleOnLeave = useCallback( 122 | (entity) => { 123 | if (onLiveLeave) { 124 | setData((data) => onLiveLeave(entity, data)); 125 | } 126 | }, 127 | [onLiveLeave], 128 | ); 129 | 130 | // Update the data upon updated 131 | useMoralisSubscription(nameOrObject, queryMap, dependencies, { 132 | enabled: live, 133 | onCreate: handleOnCreate, 134 | onEnter: handleOnEnter, 135 | onUpdate: handleOnUpdate, 136 | onDelete: handleOnDelete, 137 | onLeave: handleOnLeave, 138 | }); 139 | 140 | return { fetch, isFetching, isLoading, error, data }; 141 | }; 142 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralisSolanaApi/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useMoralisSolanaApi"; 2 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralisSolanaApi/useMoralisSolanaApi.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ResolveCallParams, 3 | UseResolveCallOptions, 4 | _useResolveCall, 5 | } from "../../internal/_useResolveAsyncCall"; 6 | import { useMoralis } from "../useMoralis"; 7 | 8 | export interface UseMoralisSolanaApiCallOptions extends UseResolveCallOptions {} 9 | 10 | export const useMoralisSolanaCall = ( 11 | call: (params: Params) => Promise, 12 | params?: Params, 13 | options?: UseMoralisSolanaApiCallOptions, 14 | ) => { 15 | const result = _useResolveCall( 16 | call, 17 | null, 18 | params, 19 | options, 20 | false, 21 | ); 22 | 23 | return result; 24 | }; 25 | 26 | export const useMoralisSolanaApi = () => { 27 | const { Moralis } = useMoralis(); 28 | 29 | return { SolanaAPI: Moralis.SolanaAPI, ...Moralis.SolanaAPI }; 30 | }; 31 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralisSubscription/_useMoralisSubscriptionListener.ts: -------------------------------------------------------------------------------- 1 | import MoralisType from "moralis-v1"; 2 | import { useEffect } from "react"; 3 | import { useMoralis } from "../useMoralis"; 4 | 5 | export type MoralisListenerHandler = ( 6 | entity: MoralisType.Object, 7 | ) => void; 8 | 9 | export const _useSubscriptionListener = ({ 10 | name, 11 | handler, 12 | enable, 13 | subscription, 14 | }: { 15 | name: "open" | "create" | "update" | "enter" | "leave" | "delete" | "close"; 16 | handler?: MoralisListenerHandler; 17 | enable: boolean; 18 | subscription?: MoralisType.LiveQuerySubscription; 19 | }) => { 20 | const { isInitialized } = useMoralis(); 21 | 22 | /** 23 | * Assign listeners subscription 24 | */ 25 | useEffect(() => { 26 | if (!enable || !isInitialized || !subscription || !handler) { 27 | return; 28 | } 29 | 30 | subscription.on(name, handler); 31 | 32 | return () => { 33 | if (subscription) { 34 | subscription.off(name, handler); 35 | } 36 | }; 37 | }, [isInitialized, handler, enable, name]); 38 | }; 39 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralisSubscription/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useMoralisSubscription"; 2 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralisSubscription/useMoralisSubscription.ts: -------------------------------------------------------------------------------- 1 | import MoralisType from "moralis-v1"; 2 | import { useContext, useEffect, useRef, useState } from "react"; 3 | import { MoralisContext } from "../../../context"; 4 | import { Query } from "../../../utils/genericQuery"; 5 | import { _useSafeUpdatedQuery } from "../useMoralisQuery/_useSafeUpdatedQuery"; 6 | import { 7 | MoralisListenerHandler, 8 | _useSubscriptionListener, 9 | } from "./_useMoralisSubscriptionListener"; 10 | 11 | export interface UseSubscriptionQueryOptions { 12 | enabled?: boolean; 13 | onCreate?: MoralisListenerHandler; 14 | onUpdate?: MoralisListenerHandler; 15 | onEnter?: MoralisListenerHandler; 16 | onLeave?: MoralisListenerHandler; 17 | onDelete?: MoralisListenerHandler; 18 | } 19 | 20 | const defaultUseSubscriptionQueryOptions: UseSubscriptionQueryOptions = { 21 | enabled: true, 22 | }; 23 | 24 | export const useMoralisSubscription = < 25 | Entity extends MoralisType.Attributes = MoralisType.Attributes, 26 | >( 27 | nameOrObject: string | MoralisType.Object, 28 | queryMap: (q: Query) => Query = (q) => q, 29 | dependencies: unknown[] = [], 30 | options: UseSubscriptionQueryOptions = {}, 31 | ) => { 32 | const { enabled, onCreate, onDelete, onEnter, onLeave, onUpdate } = { 33 | ...defaultUseSubscriptionQueryOptions, 34 | ...options, 35 | }; 36 | const moralisContext = useContext(MoralisContext); 37 | const isInitialized = moralisContext?.isInitialized ?? false; 38 | const subscriptionRef = useRef(); 39 | const [isReady, setIsReady] = useState(false); 40 | 41 | const query = _useSafeUpdatedQuery( 42 | nameOrObject, 43 | queryMap, 44 | dependencies, 45 | isInitialized, 46 | ); 47 | 48 | /** 49 | * Subscribe (and cleanup) to this query 50 | */ 51 | useEffect(() => { 52 | setIsReady(false); 53 | if (!enabled || !isInitialized) { 54 | return; 55 | } 56 | 57 | query.subscribe().then((sub) => { 58 | subscriptionRef.current = sub; 59 | setIsReady(true); 60 | }); 61 | 62 | return () => { 63 | if (subscriptionRef.current) { 64 | subscriptionRef.current.unsubscribe(); 65 | } 66 | }; 67 | }, [enabled, isInitialized, query]); 68 | 69 | _useSubscriptionListener({ 70 | name: "create", 71 | handler: onCreate, 72 | subscription: subscriptionRef.current, 73 | enable: (enabled && isReady) ?? false, 74 | }); 75 | 76 | _useSubscriptionListener({ 77 | name: "update", 78 | handler: onUpdate, 79 | subscription: subscriptionRef.current, 80 | enable: (enabled && isReady) ?? false, 81 | }); 82 | 83 | _useSubscriptionListener({ 84 | name: "enter", 85 | handler: onEnter, 86 | subscription: subscriptionRef.current, 87 | enable: (enabled && isReady) ?? false, 88 | }); 89 | 90 | _useSubscriptionListener({ 91 | name: "leave", 92 | handler: onLeave, 93 | subscription: subscriptionRef.current, 94 | enable: (enabled && isReady) ?? false, 95 | }); 96 | 97 | _useSubscriptionListener({ 98 | name: "delete", 99 | handler: onDelete, 100 | subscription: subscriptionRef.current, 101 | enable: (enabled && isReady) ?? false, 102 | }); 103 | }; 104 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralisWeb3Api/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useMoralisWeb3Api"; 2 | -------------------------------------------------------------------------------- /src/hooks/core/useMoralisWeb3Api/useMoralisWeb3Api.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ResolveCallParams, 3 | UseResolveCallOptions, 4 | _useResolveCall, 5 | } from "../../internal/_useResolveAsyncCall"; 6 | import { useMoralis } from "../useMoralis"; 7 | 8 | export interface UseMoralisWeb3ApiCallOptions extends UseResolveCallOptions {} 9 | 10 | export const useMoralisWeb3ApiCall = ( 11 | call: (params: Params) => Promise, 12 | params?: Params, 13 | options?: UseMoralisWeb3ApiCallOptions, 14 | ) => { 15 | const result = _useResolveCall( 16 | call, 17 | null, 18 | params, 19 | options, 20 | false, 21 | ); 22 | 23 | return result; 24 | }; 25 | 26 | export const useMoralisWeb3Api = () => { 27 | const { Moralis } = useMoralis(); 28 | 29 | return { Web3API: Moralis.Web3API, ...Moralis.Web3API }; 30 | }; 31 | -------------------------------------------------------------------------------- /src/hooks/core/useWeb3Contract/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useWeb3Contract"; 2 | -------------------------------------------------------------------------------- /src/hooks/core/useWeb3Contract/useWeb3Contract.ts: -------------------------------------------------------------------------------- 1 | import { 2 | useWeb3ExecuteFunction, 3 | Web3ExecuteFunctionParameters, 4 | } from "../useWeb3ExecuteFunction"; 5 | 6 | export const useWeb3Contract = (params: Web3ExecuteFunctionParameters) => { 7 | const { 8 | data, 9 | error, 10 | fetch: runContractFunction, 11 | isFetching, 12 | isLoading, 13 | } = useWeb3ExecuteFunction(params); 14 | 15 | return { runContractFunction, data, error, isFetching, isLoading }; 16 | }; 17 | -------------------------------------------------------------------------------- /src/hooks/core/useWeb3ExecuteFunction/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useWeb3ExecuteFunction"; 2 | -------------------------------------------------------------------------------- /src/hooks/core/useWeb3ExecuteFunction/useWeb3ExecuteFunction.ts: -------------------------------------------------------------------------------- 1 | import { useCallback } from "react"; 2 | import { useMoralis } from "../useMoralis"; 3 | import { 4 | UseResolveCallOptions, 5 | _useResolveCall, 6 | } from "../../internal/_useResolveAsyncCall"; 7 | 8 | export type Web3ExecuteFunctionResult = unknown; 9 | 10 | export interface UseWeb3ExecuteFunctionOptions extends UseResolveCallOptions {} 11 | 12 | export type Web3ExecuteFunctionParameters = { 13 | contractAddress?: string; 14 | abi?: object; 15 | functionName?: string; 16 | params?: Record; 17 | msgValue?: number | string; 18 | }; 19 | 20 | export interface Web3ExecuteFunctionFetchOptions { 21 | onError?: (error: Error) => void; 22 | onSuccess?: (results: Web3ExecuteFunctionResult) => void; 23 | onComplete?: () => void; 24 | throwOnError?: boolean; 25 | params?: Web3ExecuteFunctionParameters; 26 | } 27 | 28 | export const useWeb3ExecuteFunction = ( 29 | params?: Web3ExecuteFunctionParameters, 30 | options?: UseWeb3ExecuteFunctionOptions, 31 | ) => { 32 | const { Moralis } = useMoralis(); 33 | const call = useCallback( 34 | async (callParams: Web3ExecuteFunctionParameters) => { 35 | //@ts-ignore 36 | const allParams: Web3ExecuteFunctionParameters = { 37 | ...params, 38 | ...callParams, 39 | }; 40 | 41 | //@ts-ignore 42 | return await Moralis.executeFunction(allParams); 43 | }, 44 | [], 45 | ); 46 | 47 | return _useResolveCall< 48 | Web3ExecuteFunctionResult, 49 | Web3ExecuteFunctionParameters 50 | >(call, null, params, options, false); 51 | }; 52 | -------------------------------------------------------------------------------- /src/hooks/core/useWeb3Transfer/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useWeb3Transfer"; 2 | -------------------------------------------------------------------------------- /src/hooks/core/useWeb3Transfer/useWeb3Transfer.ts: -------------------------------------------------------------------------------- 1 | import { useCallback } from "react"; 2 | import { useMoralis } from "../useMoralis"; 3 | import { 4 | UseResolveCallOptions, 5 | _useResolveCall, 6 | } from "../../internal/_useResolveAsyncCall"; 7 | 8 | export type Web3TransferResult = unknown; 9 | 10 | export interface UseWeb3TransferOptions extends UseResolveCallOptions {} 11 | 12 | type TransferType = "native" | "erc20" | "erc721" | "erc1155"; 13 | type TransferSystem = "evm"; 14 | export type Web3TransferParameters = { 15 | type?: TransferType; 16 | receiver?: string; 17 | contractAddress?: string; 18 | /** @deprecated use contractAddress field instead */ 19 | contract_address?: string; 20 | amount?: string; 21 | tokenId?: string; 22 | /** @deprecated use tokenId field instead */ 23 | token_id?: string; 24 | system?: TransferSystem; 25 | }; 26 | 27 | export interface Web3TransferFetchOptions { 28 | onError?: (error: Error) => void; 29 | onSuccess?: (results: Web3TransferResult) => void; 30 | onComplete?: () => void; 31 | throwOnError?: boolean; 32 | params?: Web3TransferParameters; 33 | } 34 | 35 | export const useWeb3Transfer = ( 36 | params?: Web3TransferParameters, 37 | options?: UseWeb3TransferOptions, 38 | ) => { 39 | const { Moralis } = useMoralis(); 40 | const call = useCallback(async (callParams: Web3TransferParameters) => { 41 | //@ts-ignore 42 | const allParams: Web3TransferParameters = { 43 | ...params, 44 | ...callParams, 45 | }; 46 | 47 | //@ts-ignore 48 | return await Moralis.transfer(allParams); 49 | }, []); 50 | 51 | return _useResolveCall( 52 | call, 53 | null, 54 | params, 55 | options, 56 | false, 57 | ); 58 | }; 59 | -------------------------------------------------------------------------------- /src/hooks/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./core"; 2 | export * from "./plugins"; 3 | export * from "./web3ApiWrappers"; 4 | export * from "./utils"; 5 | -------------------------------------------------------------------------------- /src/hooks/internal/_useResolveAsyncCall/_useResolveAsyncCall.ts: -------------------------------------------------------------------------------- 1 | import isDeepEqual from "fast-deep-equal/react"; 2 | import { useCallback, useEffect, useMemo, useRef, useState } from "react"; 3 | import { useMoralis } from "../../../hooks/core/useMoralis"; 4 | import { useImmer } from "use-immer"; 5 | 6 | export interface UseResolveCallOptions { 7 | autoFetch?: boolean; 8 | } 9 | 10 | export type ResolveCallParams = object; 11 | 12 | export interface ResolveCallOptions { 13 | onError?: (error: Error) => void; 14 | onSuccess?: (results: Result) => void; 15 | onComplete?: () => void; 16 | throwOnError?: boolean; 17 | params?: Params; 18 | } 19 | 20 | export const _useResolveCall = ( 21 | call: (params: Params) => Promise, 22 | initialData: Result, 23 | params?: Params, 24 | options?: UseResolveCallOptions, 25 | defaultAutoFetch = true, 26 | validate?: (params: Params) => string | undefined | null, 27 | ) => { 28 | const { isInitialized } = useMoralis(); 29 | const { autoFetch } = { 30 | ...{ 31 | autoFetch: defaultAutoFetch, 32 | }, 33 | ...(options ?? {}), 34 | }; 35 | const [isFetching, setIsFetching] = useState(false); 36 | const [error, setError] = useState(null); 37 | const [data, setData] = useImmer(initialData); 38 | const paramsRef = useRef(params); 39 | 40 | if (!isDeepEqual(paramsRef.current, params)) { 41 | paramsRef.current = params; 42 | } 43 | 44 | /** 45 | * Run the function 46 | */ 47 | const fetch = useCallback( 48 | async ({ 49 | throwOnError, 50 | onComplete, 51 | onError, 52 | onSuccess, 53 | params: fetchParams, 54 | }: ResolveCallOptions = {}) => { 55 | // @ts-ignore 56 | const combinedParams: Params = { 57 | ...params, 58 | ...fetchParams, 59 | }; 60 | 61 | try { 62 | if (validate) { 63 | const error = validate(combinedParams); 64 | if (error) { 65 | throw new Error(error); 66 | } 67 | } 68 | 69 | setIsFetching(true); 70 | setError(null); 71 | 72 | const results = await call(combinedParams); 73 | 74 | setData(results); 75 | if (onSuccess) { 76 | onSuccess(results); 77 | } 78 | return results; 79 | } catch (error) { 80 | setData(initialData); 81 | setError(error); 82 | if (throwOnError) { 83 | throw error; 84 | } 85 | if (onError) { 86 | onError(error); 87 | } 88 | } finally { 89 | setIsFetching(false); 90 | if (onComplete) { 91 | onComplete(); 92 | } 93 | } 94 | }, 95 | [call, paramsRef.current, validate], 96 | ); 97 | const isEmpty = useMemo(() => { 98 | if (data == null) { 99 | return true; 100 | } 101 | if (Array.isArray(data) && data.length === 0) { 102 | return true; 103 | } 104 | return false; 105 | }, [data]); 106 | 107 | const isLoading = useMemo(() => { 108 | return isFetching && isEmpty; 109 | }, [isEmpty, isFetching]); 110 | 111 | /** 112 | * Automatically fetch the call function 113 | */ 114 | useEffect(() => { 115 | if (!isInitialized || !autoFetch) { 116 | return; 117 | } 118 | 119 | fetch(); 120 | }, [fetch, isInitialized]); 121 | 122 | return { 123 | fetch, 124 | isFetching, 125 | isLoading, 126 | error, 127 | data, 128 | setData, 129 | }; 130 | }; 131 | -------------------------------------------------------------------------------- /src/hooks/internal/_useResolveAsyncCall/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./_useResolveAsyncCall"; 2 | -------------------------------------------------------------------------------- /src/hooks/internal/_useResolvePluginCall/_useResolvePluginCall.ts: -------------------------------------------------------------------------------- 1 | import { useCallback } from "react"; 2 | import { useMoralis } from "../../core/useMoralis"; 3 | import { Plugin } from "../../../config/index"; 4 | import { 5 | ResolveCallParams, 6 | UseResolveCallOptions, 7 | _useResolveCall, 8 | } from "../_useResolveAsyncCall"; 9 | 10 | export const _useResolvePluginCall = ( 11 | plugin: Plugin, 12 | call: (params: Params) => Promise, 13 | initialData: Result, 14 | params?: Params, 15 | options?: UseResolveCallOptions, 16 | defaultAutoFetch = true, 17 | providedValidate?: (params: Params) => string | undefined | null, 18 | ) => { 19 | const { Moralis, isInitialized, isInitializing } = useMoralis(); 20 | 21 | const validate = useCallback( 22 | (params: Params) => { 23 | if (!isInitialized && isInitializing) { 24 | return "Plugins are not finished initializing"; 25 | } 26 | 27 | if (!isInitialized) { 28 | return "Moralis has not been initialized, run Moralis.start first"; 29 | } 30 | 31 | if (!Moralis?.Plugins || !Moralis?.Plugins[plugin]) { 32 | return `${plugin} plugin has not been installed or initialized`; 33 | } 34 | 35 | if (providedValidate) { 36 | return providedValidate(params); 37 | } 38 | }, 39 | [plugin, isInitialized, isInitializing, providedValidate], 40 | ); 41 | 42 | return _useResolveCall( 43 | call, 44 | initialData, 45 | params, 46 | options, 47 | defaultAutoFetch, 48 | validate, 49 | ); 50 | }; 51 | -------------------------------------------------------------------------------- /src/hooks/internal/_useResolvePluginCall/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./_useResolvePluginCall"; 2 | -------------------------------------------------------------------------------- /src/hooks/plugins/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useOneInch"; 2 | export * from "./useOpenSea"; 3 | export * from "./useFiat"; 4 | export * from "./useRarible"; 5 | -------------------------------------------------------------------------------- /src/hooks/plugins/useFiat/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useFiatBuy"; 2 | -------------------------------------------------------------------------------- /src/hooks/plugins/useFiat/useFiatBuy.ts: -------------------------------------------------------------------------------- 1 | import { useMoralis } from "../../core/useMoralis"; 2 | import { Plugin } from "../../../config"; 3 | import { UseResolveCallOptions } from "../../internal/_useResolveAsyncCall"; 4 | import { _useResolvePluginCall } from "../../internal/_useResolvePluginCall"; 5 | import { useCallback } from "react"; 6 | 7 | export interface UseFiatBuyParams { 8 | coin?: string; 9 | receiver?: string; 10 | } 11 | export interface UseFiatBuyOptions extends UseResolveCallOptions { 12 | disableTriggers?: boolean; 13 | } 14 | 15 | export const useFiatBuy = ( 16 | params: UseFiatBuyParams = {}, 17 | { disableTriggers, ...options }: UseFiatBuyOptions = {}, 18 | ) => { 19 | const { Moralis } = useMoralis(); 20 | 21 | const doBuyCall = useCallback( 22 | (params: { coin?: string; receiver?: string }) => { 23 | return Moralis.Plugins?.fiat?.buy(params, { disableTriggers }); 24 | }, 25 | [disableTriggers], 26 | ); 27 | 28 | const { fetch, data, isFetching, isLoading, error } = _useResolvePluginCall( 29 | Plugin.FIAT, 30 | doBuyCall, 31 | null, 32 | { 33 | coin: params.coin, 34 | receiver: params.receiver, 35 | }, 36 | options, 37 | false, 38 | ); 39 | 40 | return { buy: fetch, data, isFetching, isLoading, error }; 41 | }; 42 | -------------------------------------------------------------------------------- /src/hooks/plugins/useOneInch/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useOneInchTokens"; 2 | export * from "./useOneInchQuote"; 3 | export * from "./useOneInchSwap"; 4 | -------------------------------------------------------------------------------- /src/hooks/plugins/useOneInch/types.ts: -------------------------------------------------------------------------------- 1 | export interface OneInchToken { 2 | address: string; 3 | decimals: number; 4 | // symbol: string, 5 | // name: string, 6 | // logoURI: string 7 | } 8 | -------------------------------------------------------------------------------- /src/hooks/plugins/useOneInch/useOneInchQuote.ts: -------------------------------------------------------------------------------- 1 | import { useMoralis } from "../../core/useMoralis"; 2 | import { DEFAULT_API_CHAIN, Plugin } from "../../../config"; 3 | import { UseResolveCallOptions } from "../../internal/_useResolveAsyncCall"; 4 | import { _useResolvePluginCall } from "../../internal/_useResolvePluginCall"; 5 | import { OneInchToken } from "./types"; 6 | 7 | export interface UseOneInchQuoteParams { 8 | chain?: string; 9 | fromAmount: string | number; 10 | fromToken: OneInchToken; 11 | toToken: OneInchToken; 12 | } 13 | export interface UseOneInchQuoteOptions extends UseResolveCallOptions {} 14 | 15 | export const useOneInchQuote = ( 16 | params: UseOneInchQuoteParams, 17 | options: UseOneInchQuoteOptions = {}, 18 | ) => { 19 | const { Moralis } = useMoralis(); 20 | 21 | const { fetch, data, isFetching, isLoading, error } = _useResolvePluginCall( 22 | Plugin.ONE_INCH, 23 | Moralis.Plugins?.oneInch?.quote, 24 | null, 25 | Object.keys(params)?.length 26 | ? { 27 | chain: params.chain ?? DEFAULT_API_CHAIN, 28 | // The token you want to swap 29 | fromTokenAddress: params.fromToken.address, 30 | // The token you want to receive 31 | toTokenAddress: params.toToken.address, 32 | amount: Moralis.Units.Token( 33 | params.fromAmount, 34 | params.fromToken.decimals, 35 | ).toString(), 36 | } 37 | : undefined, 38 | options, 39 | false, 40 | ); 41 | 42 | return { getQuote: fetch, data, isFetching, isLoading, error }; 43 | }; 44 | -------------------------------------------------------------------------------- /src/hooks/plugins/useOneInch/useOneInchSwap.ts: -------------------------------------------------------------------------------- 1 | import { useMoralis } from "../../core/useMoralis"; 2 | import { DEFAULT_API_CHAIN, Plugin } from "../../../config"; 3 | import { UseResolveCallOptions } from "../..//internal/_useResolveAsyncCall"; 4 | import { _useResolvePluginCall } from "../../internal/_useResolvePluginCall"; 5 | import { OneInchToken } from "./types"; 6 | import { useCallback } from "react"; 7 | 8 | export interface UseOneInchSwapParams { 9 | chain?: string; 10 | fromAmount: string | number; 11 | fromToken: OneInchToken; 12 | toToken: OneInchToken; 13 | slippage?: number; 14 | } 15 | export interface UseOneInchSwapOptions extends UseResolveCallOptions {} 16 | 17 | export const useOneInchSwap = ( 18 | params: UseOneInchSwapParams, 19 | options: UseOneInchSwapOptions = {}, 20 | ) => { 21 | const { Moralis, account } = useMoralis(); 22 | 23 | const doApproveAndSwap = useCallback( 24 | async (params: { 25 | chain: string; 26 | fromTokenAddress: string; 27 | toTokenAddress: string; 28 | amount: number | string; 29 | fromAddress: string | null; 30 | slippage: number; 31 | }) => { 32 | const hasAllowance = await Moralis.Plugins.oneInch.hasAllowance({ 33 | chain: params.chain, 34 | fromTokenAddress: params.fromTokenAddress, 35 | fromAddress: params.fromAddress, 36 | amount: params.amount, 37 | }); 38 | 39 | if (!hasAllowance) { 40 | await Moralis.Plugins.oneInch.approve({ 41 | chain: params.chain, 42 | tokenAddress: params.fromTokenAddress, 43 | fromAddress: params.fromAddress, 44 | }); 45 | } 46 | 47 | return Moralis.Plugins.oneInch.swap(params); 48 | }, 49 | [], 50 | ); 51 | 52 | const { fetch, data, isFetching, isLoading, error } = _useResolvePluginCall( 53 | Plugin.ONE_INCH, 54 | doApproveAndSwap, 55 | null, 56 | { 57 | chain: params.chain ?? DEFAULT_API_CHAIN, 58 | fromTokenAddress: params.fromToken.address, 59 | toTokenAddress: params.toToken.address, 60 | amount: params.fromAmount, 61 | fromAddress: account, 62 | slippage: params.slippage ?? 1, 63 | }, 64 | options, 65 | false, 66 | () => { 67 | return !account ? "No web3 account found, run enableWeb3() first" : null; 68 | }, 69 | ); 70 | 71 | return { swap: fetch, data, isFetching, isLoading, error }; 72 | }; 73 | -------------------------------------------------------------------------------- /src/hooks/plugins/useOneInch/useOneInchTokens.ts: -------------------------------------------------------------------------------- 1 | import { useMoralis } from "../../core/useMoralis"; 2 | import { DEFAULT_API_CHAIN, Plugin } from "../../../config"; 3 | import { UseResolveCallOptions } from "../../internal/_useResolveAsyncCall"; 4 | import { _useResolvePluginCall } from "../../internal/_useResolvePluginCall"; 5 | 6 | interface UseOneInchTokensParams { 7 | chain?: string; 8 | } 9 | interface UseOneInchTokensOptions extends UseResolveCallOptions {} 10 | 11 | export const useOneInchTokens = ( 12 | { chain }: UseOneInchTokensParams = {}, 13 | options: UseOneInchTokensOptions = {}, 14 | ) => { 15 | const { Moralis, isInitialized } = useMoralis(); 16 | 17 | const { fetch, data, isFetching, isLoading, error } = _useResolvePluginCall( 18 | Plugin.ONE_INCH, 19 | Moralis.Plugins?.oneInch?.getSupportedTokens, 20 | [], 21 | { chain: chain ?? DEFAULT_API_CHAIN }, 22 | options, 23 | isInitialized, 24 | ); 25 | 26 | return { getSupportedTokens: fetch, data, isFetching, isLoading, error }; 27 | }; 28 | -------------------------------------------------------------------------------- /src/hooks/plugins/useOpenSea/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useOpenSeaAsset"; 2 | export * from "./useOpenSeaOrders"; 3 | export * from "./useOpenSeaSellOrder"; 4 | export * from "./useOpenSeaBuyOrder"; 5 | -------------------------------------------------------------------------------- /src/hooks/plugins/useOpenSea/types.ts: -------------------------------------------------------------------------------- 1 | export type OpenseaNetwork = "testnet" | "mainnet"; 2 | export type OpenseaTokenType = "ERC721" | "ERC1155"; 3 | export const DEFAULT_OPEN_SEA_NETWORK = "mainnet"; 4 | -------------------------------------------------------------------------------- /src/hooks/plugins/useOpenSea/useOpenSeaAsset.ts: -------------------------------------------------------------------------------- 1 | import { useMoralis } from "../../core/useMoralis"; 2 | import { Plugin } from "../../../config"; 3 | import { UseResolveCallOptions } from "../../internal/_useResolveAsyncCall"; 4 | import { _useResolvePluginCall } from "../../internal/_useResolvePluginCall"; 5 | import { DEFAULT_OPEN_SEA_NETWORK, OpenseaNetwork } from "./types"; 6 | 7 | export interface UseOpenSeaAssetParams { 8 | network?: OpenseaNetwork; 9 | tokenAddress: string; 10 | tokenId: string; 11 | } 12 | export interface UseOpenSeaAssetOptions extends UseResolveCallOptions {} 13 | 14 | export const useOpenSeaAsset = ( 15 | params: UseOpenSeaAssetParams, 16 | options: UseOpenSeaAssetOptions = {}, 17 | ) => { 18 | const { Moralis } = useMoralis(); 19 | 20 | const { fetch, data, isFetching, isLoading, error } = _useResolvePluginCall( 21 | Plugin.OPEN_SEA, 22 | Moralis.Plugins?.opensea?.getAsset, 23 | null, 24 | { 25 | network: params.network ?? DEFAULT_OPEN_SEA_NETWORK, 26 | tokenAddress: params.tokenAddress, 27 | tokenId: params.tokenId, 28 | }, 29 | options, 30 | false, 31 | ); 32 | 33 | return { getAsset: fetch, data, isFetching, isLoading, error }; 34 | }; 35 | -------------------------------------------------------------------------------- /src/hooks/plugins/useOpenSea/useOpenSeaBuyOrder.ts: -------------------------------------------------------------------------------- 1 | import { useMoralis } from "../../core/useMoralis"; 2 | import { Plugin } from "../../../config"; 3 | import { UseResolveCallOptions } from "../../internal/_useResolveAsyncCall"; 4 | import { _useResolvePluginCall } from "../../internal/_useResolvePluginCall"; 5 | import { 6 | DEFAULT_OPEN_SEA_NETWORK, 7 | OpenseaNetwork, 8 | OpenseaTokenType, 9 | } from "./types"; 10 | 11 | export interface UseOpenSeaBuyOrderParams { 12 | network?: OpenseaNetwork; 13 | tokenAddress: string; 14 | tokenId: string; 15 | tokenType: OpenseaTokenType; 16 | amount: number; 17 | userAddress: string; 18 | paymentTokenAddress: string; 19 | } 20 | export interface UseOpenSeaBuyOrderOptions extends UseResolveCallOptions {} 21 | 22 | export const useOpenSeaBuyOrder = ( 23 | params: UseOpenSeaBuyOrderParams, 24 | options: UseOpenSeaBuyOrderOptions = {}, 25 | ) => { 26 | const { Moralis } = useMoralis(); 27 | 28 | const { fetch, data, isFetching, isLoading, error } = _useResolvePluginCall( 29 | Plugin.OPEN_SEA, 30 | Moralis.Plugins?.opensea?.createBuyOrder, 31 | null, 32 | { 33 | network: params.network ?? DEFAULT_OPEN_SEA_NETWORK, 34 | tokenAddress: params.tokenAddress, 35 | tokenId: params.tokenId, 36 | tokenType: params.tokenType, 37 | amount: params.amount, 38 | userAddress: params.userAddress, 39 | paymentTokenAddress: params.paymentTokenAddress, 40 | }, 41 | options, 42 | false, 43 | ); 44 | 45 | return { createBuyOrder: fetch, data, isFetching, isLoading, error }; 46 | }; 47 | -------------------------------------------------------------------------------- /src/hooks/plugins/useOpenSea/useOpenSeaOrders.ts: -------------------------------------------------------------------------------- 1 | import { useMoralis } from "../../core/useMoralis"; 2 | import { Plugin } from "../../../config"; 3 | import { UseResolveCallOptions } from "../../internal/_useResolveAsyncCall"; 4 | import { _useResolvePluginCall } from "../../internal/_useResolvePluginCall"; 5 | import { DEFAULT_OPEN_SEA_NETWORK, OpenseaNetwork } from "./types"; 6 | 7 | export interface UseOpenSeaOrdersParams { 8 | network?: OpenseaNetwork; 9 | tokenAddress: string; 10 | tokenId: string; 11 | orderSide: 0 | 1; 12 | page?: number; 13 | } 14 | export interface UseOpenSeaOrdersOptions extends UseResolveCallOptions {} 15 | 16 | export const useOpenSeaOrders = ( 17 | params: UseOpenSeaOrdersParams, 18 | options: UseOpenSeaOrdersOptions = {}, 19 | ) => { 20 | const { Moralis } = useMoralis(); 21 | 22 | const { fetch, data, isFetching, isLoading, error } = _useResolvePluginCall( 23 | Plugin.OPEN_SEA, 24 | Moralis.Plugins?.opensea?.getOrders, 25 | null, 26 | { 27 | network: params.network ?? DEFAULT_OPEN_SEA_NETWORK, 28 | tokenAddress: params.tokenAddress, 29 | tokenId: params.tokenId, 30 | orderSide: params.orderSide, 31 | page: params.page ?? 1, 32 | }, 33 | options, 34 | false, 35 | ); 36 | 37 | return { getOrders: fetch, data, isFetching, isLoading, error }; 38 | }; 39 | -------------------------------------------------------------------------------- /src/hooks/plugins/useOpenSea/useOpenSeaSellOrder.ts: -------------------------------------------------------------------------------- 1 | import { useMoralis } from "../../core/useMoralis"; 2 | import { Plugin } from "../../../config"; 3 | import { UseResolveCallOptions } from "../../internal/_useResolveAsyncCall"; 4 | import { _useResolvePluginCall } from "../../internal/_useResolvePluginCall"; 5 | import { 6 | DEFAULT_OPEN_SEA_NETWORK, 7 | OpenseaNetwork, 8 | OpenseaTokenType, 9 | } from "./types"; 10 | 11 | export interface UseOpenSeaSellOrderParams { 12 | network?: OpenseaNetwork; 13 | tokenAddress: string; 14 | tokenId: string; 15 | tokenType: OpenseaTokenType; 16 | userAddress: string; 17 | startAmount: number; 18 | endAmount: number; 19 | expirationTime?: number; 20 | } 21 | export interface UseOpenSeaSellOrderOptions extends UseResolveCallOptions {} 22 | 23 | export const useOpenSeaSellOrder = ( 24 | params: UseOpenSeaSellOrderParams, 25 | options: UseOpenSeaSellOrderOptions = {}, 26 | ) => { 27 | const { Moralis } = useMoralis(); 28 | 29 | const { fetch, data, isFetching, isLoading, error } = _useResolvePluginCall( 30 | Plugin.OPEN_SEA, 31 | Moralis.Plugins?.opensea?.createSellOrder, 32 | null, 33 | { 34 | network: params.network ?? DEFAULT_OPEN_SEA_NETWORK, 35 | tokenAddress: params.tokenAddress, 36 | tokenId: params.tokenId, 37 | tokenType: params.tokenType, 38 | userAddress: params.userAddress, 39 | startAmount: params.startAmount, 40 | endAmount: params.endAmount, 41 | expirationTime: params.expirationTime, 42 | }, 43 | options, 44 | false, 45 | ); 46 | 47 | return { createSellOrder: fetch, data, isFetching, isLoading, error }; 48 | }; 49 | -------------------------------------------------------------------------------- /src/hooks/plugins/useRarible/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useRaribleLazyMint"; 2 | export * from "./useRaribleSellOrder"; 3 | -------------------------------------------------------------------------------- /src/hooks/plugins/useRarible/types.ts: -------------------------------------------------------------------------------- 1 | export type RaribleNetwork = "rinkeby" | "eth"; 2 | export type RaribleTokenType = "ERC721" | "ERC1155"; 3 | export type RaribleTokenTypeAssetClass = 4 | | "ETH" 5 | | "ERC20" 6 | | "ERC721" 7 | | "ERC1155" 8 | | "ERC721_LAZY" 9 | | "ERC1155_LAZY"; 10 | 11 | export const DEFAULT_RARIBLE_NETWORK = "eth"; 12 | -------------------------------------------------------------------------------- /src/hooks/plugins/useRarible/useRaribleLazyMint.ts: -------------------------------------------------------------------------------- 1 | import { useMoralis } from "../../core/useMoralis"; 2 | import { Plugin } from "../../../config"; 3 | import { UseResolveCallOptions } from "../../internal/_useResolveAsyncCall"; 4 | import { _useResolvePluginCall } from "../../internal/_useResolvePluginCall"; 5 | import { 6 | DEFAULT_RARIBLE_NETWORK, 7 | RaribleNetwork, 8 | RaribleTokenType, 9 | } from "./types"; 10 | 11 | export interface UseRaribleLazyMintParams { 12 | chain?: RaribleNetwork; 13 | userAddress: string; 14 | tokenType: RaribleTokenType; 15 | tokenUri: string; 16 | supply: number; 17 | royaltiesAmount?: number; 18 | } 19 | export interface UseRaribleLazyMintOptions extends UseResolveCallOptions {} 20 | 21 | export const useRaribleLazyMint = ( 22 | params: UseRaribleLazyMintParams, 23 | options: UseRaribleLazyMintOptions = {}, 24 | ) => { 25 | const { Moralis } = useMoralis(); 26 | 27 | const { fetch, data, isFetching, isLoading, error } = _useResolvePluginCall( 28 | Plugin.RARIBLE, 29 | Moralis.Plugins?.rarible?.lazyMint, 30 | null, 31 | { 32 | chain: params.chain ?? DEFAULT_RARIBLE_NETWORK, 33 | userAddress: params.userAddress, 34 | tokenType: params.tokenType, 35 | tokenUri: params.tokenUri, 36 | supply: params.supply, 37 | royaltiesAmount: params.royaltiesAmount, 38 | }, 39 | options, 40 | false, 41 | ); 42 | 43 | return { lazyMint: fetch, data, isFetching, isLoading, error }; 44 | }; 45 | -------------------------------------------------------------------------------- /src/hooks/plugins/useRarible/useRaribleSellOrder.ts: -------------------------------------------------------------------------------- 1 | import { useMoralis } from "../../core/useMoralis"; 2 | import { Plugin } from "../../../config"; 3 | import { UseResolveCallOptions } from "../../internal/_useResolveAsyncCall"; 4 | import { _useResolvePluginCall } from "../../internal/_useResolvePluginCall"; 5 | import { 6 | DEFAULT_RARIBLE_NETWORK, 7 | RaribleNetwork, 8 | RaribleTokenTypeAssetClass, 9 | } from "./types"; 10 | 11 | export interface UseRaribleSellOrderParams { 12 | chain?: RaribleNetwork; 13 | userAddress: string; 14 | makeTokenId: string; 15 | makeTokenAddress: string; 16 | makeAssetClass: RaribleTokenTypeAssetClass; 17 | makeValue: string; 18 | takeAssetClass: RaribleTokenTypeAssetClass; 19 | takeValue: string; 20 | } 21 | export interface UseRaribleSellOrderOptions extends UseResolveCallOptions {} 22 | 23 | export const useRaribleSellOrder = ( 24 | params: UseRaribleSellOrderParams, 25 | options: UseRaribleSellOrderOptions = {}, 26 | ) => { 27 | const { Moralis } = useMoralis(); 28 | 29 | const { fetch, data, isFetching, isLoading, error } = _useResolvePluginCall( 30 | Plugin.RARIBLE, 31 | Moralis.Plugins?.rarible?.createSellOrder, 32 | null, 33 | { 34 | chain: params.chain ?? DEFAULT_RARIBLE_NETWORK, 35 | userAddress: params.userAddress, 36 | makeTokenId: params.makeTokenId, 37 | makeTokenAddress: params.makeTokenAddress, 38 | makeAssetClass: params.makeAssetClass, 39 | makeValue: params.makeValue, 40 | takeAssetClass: params.takeAssetClass, 41 | takeValue: params.takeValue, 42 | }, 43 | options, 44 | false, 45 | ); 46 | 47 | return { createSellOrder: fetch, data, isFetching, isLoading, error }; 48 | }; 49 | -------------------------------------------------------------------------------- /src/hooks/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useEns"; 2 | -------------------------------------------------------------------------------- /src/hooks/utils/useEns/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useEnsAddress"; 2 | export * from "./useEnsName"; 3 | -------------------------------------------------------------------------------- /src/hooks/utils/useEns/useEnsAddress.ts: -------------------------------------------------------------------------------- 1 | import { useState, useEffect } from "react"; 2 | import { useMoralis } from "../../core/useMoralis"; 3 | 4 | export const useEnsAddress = (ensAddress: string) => { 5 | const { web3 } = useMoralis(); 6 | const [resolved, setResolved] = useState(null); 7 | const [isLoading, setIsLoading] = useState(false); 8 | const [error, setError] = useState(null); 9 | 10 | useEffect(() => { 11 | if (web3) { 12 | setIsLoading(true); 13 | setError(null); 14 | web3 15 | .lookupAddress(ensAddress) 16 | .then((result) => { 17 | setResolved(result); 18 | }) 19 | .catch(setError) 20 | .finally(() => { 21 | setIsLoading(false); 22 | }); 23 | } 24 | }, [ensAddress, web3]); 25 | 26 | return { name: resolved, isLoading, error }; 27 | }; 28 | -------------------------------------------------------------------------------- /src/hooks/utils/useEns/useEnsName.ts: -------------------------------------------------------------------------------- 1 | import { useState, useEffect } from "react"; 2 | import { useMoralis } from "../../core/useMoralis"; 3 | 4 | export const useEnsName = (ensName: string) => { 5 | const { web3 } = useMoralis(); 6 | const [address, setAddress] = useState(null); 7 | const [avatar, setAvatar] = useState(null); 8 | const [url, setUrl] = useState(null); 9 | const [email, setEmail] = useState(null); 10 | const [isLoading, setIsLoading] = useState(false); 11 | const [error, setError] = useState(null); 12 | 13 | useEffect(() => { 14 | if (web3) { 15 | setIsLoading(true); 16 | setError(null); 17 | web3 18 | .getResolver(ensName) 19 | .then((resolver) => { 20 | if (!resolver) { 21 | return; 22 | } 23 | Promise.all([ 24 | resolver.getAddress().catch(() => null), 25 | resolver.getAvatar().catch(() => null), 26 | resolver.getText("email").catch(() => null), 27 | resolver.getText("url").catch(() => null), 28 | ]).then( 29 | ([resolvedAddress, resolvedAvatar, resolvedEmail, resolvedUrl]) => { 30 | setAddress(resolvedAddress); 31 | setAvatar(resolvedAvatar?.url ?? null); 32 | setEmail(resolvedEmail); 33 | setUrl(resolvedUrl); 34 | }, 35 | ); 36 | }) 37 | .catch(setError) 38 | .finally(() => { 39 | setIsLoading(false); 40 | }); 41 | } 42 | }, [ensName, web3]); 43 | 44 | return { address, avatar, email, url, isLoading, error }; 45 | }; 46 | -------------------------------------------------------------------------------- /src/hooks/web3ApiWrappers/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useApiContract"; 2 | export * from "./useERC20Balances"; 3 | export * from "./useERC20Transfers"; 4 | export * from "./useNFTBalances"; 5 | export * from "./useNFTTransfers"; 6 | export * from "./useNativeBalance"; 7 | export * from "./useNativeTransactions"; 8 | export * from "./useTokenPrice"; 9 | -------------------------------------------------------------------------------- /src/hooks/web3ApiWrappers/useApiContract/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useApiContract"; 2 | -------------------------------------------------------------------------------- /src/hooks/web3ApiWrappers/useApiContract/useApiContract.ts: -------------------------------------------------------------------------------- 1 | import MoralisType from "moralis-v1/types"; 2 | import { 3 | useMoralisWeb3Api, 4 | useMoralisWeb3ApiCall, 5 | UseMoralisWeb3ApiCallOptions, 6 | } from "../../core/useMoralisWeb3Api"; 7 | 8 | export interface ApiContractParams 9 | extends Omit< 10 | Parameters[0], 11 | "address" | "function_name" | "params" | "abi" 12 | > { 13 | address?: string; 14 | // TODO: fix types 15 | functionName: string; 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | abi: any; 18 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 19 | params?: any; 20 | } 21 | 22 | export const useApiContract = ( 23 | // TODO: fix types 24 | { functionName, address, abi, chain, params }: ApiContractParams, 25 | options: UseMoralisWeb3ApiCallOptions = {}, 26 | ) => { 27 | const { native } = useMoralisWeb3Api(); 28 | 29 | const payload = { 30 | abi, 31 | chain, 32 | function_name: functionName, 33 | address, 34 | params, 35 | }; 36 | 37 | const { 38 | fetch: runContractFunction, 39 | data, 40 | error, 41 | isFetching, 42 | isLoading, 43 | // @ts-ignore 44 | // TODO: fix typings of payload and optional address 45 | } = useMoralisWeb3ApiCall(native.runContractFunction, payload, { 46 | autoFetch: options.autoFetch ?? false, 47 | ...options, 48 | }); 49 | 50 | return { runContractFunction, data, error, isLoading, isFetching }; 51 | }; 52 | -------------------------------------------------------------------------------- /src/hooks/web3ApiWrappers/useERC20Balances/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useERC20Balances"; 2 | -------------------------------------------------------------------------------- /src/hooks/web3ApiWrappers/useERC20Balances/useERC20Balances.ts: -------------------------------------------------------------------------------- 1 | import { useMoralis } from "../../core/useMoralis"; 2 | import { 3 | useMoralisWeb3Api, 4 | useMoralisWeb3ApiCall, 5 | UseMoralisWeb3ApiCallOptions, 6 | } from "../../core/useMoralisWeb3Api"; 7 | import { DEFAULT_API_CHAIN } from "../../../config"; 8 | import MoralisType from "moralis-v1"; 9 | import { isValidApiChain } from "../../../utils/isValidApiChain"; 10 | 11 | export interface UseERC20BalancesParams 12 | extends Omit< 13 | Parameters[0], 14 | "address" 15 | > { 16 | address?: string; 17 | } 18 | 19 | export const useERC20Balances = ( 20 | params?: UseERC20BalancesParams, 21 | options?: UseMoralisWeb3ApiCallOptions, 22 | ) => { 23 | const { 24 | account: { getTokenBalances }, 25 | } = useMoralisWeb3Api(); 26 | const { account, chainId } = useMoralis(); 27 | 28 | const { fetch, data, isLoading, isFetching, error } = useMoralisWeb3ApiCall( 29 | getTokenBalances, 30 | { 31 | chain: params?.chain ?? isValidApiChain(chainId) ?? DEFAULT_API_CHAIN, 32 | address: params?.address ?? account ?? "", 33 | ...params, 34 | }, 35 | { autoFetch: options?.autoFetch ?? !!account, ...options }, 36 | ); 37 | 38 | return { 39 | fetchERC20Balances: fetch, 40 | data, 41 | isLoading, 42 | isFetching, 43 | error, 44 | }; 45 | }; 46 | -------------------------------------------------------------------------------- /src/hooks/web3ApiWrappers/useERC20Transfers/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useERC20Transfers"; 2 | -------------------------------------------------------------------------------- /src/hooks/web3ApiWrappers/useERC20Transfers/useERC20Transfers.ts: -------------------------------------------------------------------------------- 1 | import { useMoralis } from "../../core/useMoralis"; 2 | 3 | import { 4 | useMoralisWeb3Api, 5 | useMoralisWeb3ApiCall, 6 | UseMoralisWeb3ApiCallOptions, 7 | } from "../../core/useMoralisWeb3Api"; 8 | import { DEFAULT_API_CHAIN } from "../../../config"; 9 | import MoralisType from "moralis-v1"; 10 | import { isValidApiChain } from "../../../utils/isValidApiChain"; 11 | 12 | export interface UseERC20TransfersParams 13 | extends Omit< 14 | Parameters[0], 15 | "address" 16 | > { 17 | address?: string; 18 | } 19 | 20 | export const useERC20Transfers = ( 21 | params?: UseERC20TransfersParams, 22 | options?: UseMoralisWeb3ApiCallOptions, 23 | ) => { 24 | const { 25 | account: { getTokenTransfers }, 26 | } = useMoralisWeb3Api(); 27 | const { account, chainId } = useMoralis(); 28 | 29 | const { fetch, data, isLoading, isFetching, error } = useMoralisWeb3ApiCall( 30 | getTokenTransfers, 31 | { 32 | chain: params?.chain ?? isValidApiChain(chainId) ?? DEFAULT_API_CHAIN, 33 | address: params?.address ?? account ?? "", 34 | ...params, 35 | }, 36 | { autoFetch: options?.autoFetch ?? !!account, ...options }, 37 | ); 38 | 39 | return { 40 | fetchERC20Transfers: fetch, 41 | data, 42 | error, 43 | isLoading, 44 | isFetching, 45 | }; 46 | }; 47 | -------------------------------------------------------------------------------- /src/hooks/web3ApiWrappers/useNFTBalances/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useNFTBalances"; 2 | -------------------------------------------------------------------------------- /src/hooks/web3ApiWrappers/useNFTBalances/useNFTBalances.ts: -------------------------------------------------------------------------------- 1 | import { useMemo } from "react"; 2 | import MoralisType from "moralis-v1"; 3 | import { useMoralis } from "../../core/useMoralis"; 4 | import { 5 | useMoralisWeb3Api, 6 | useMoralisWeb3ApiCall, 7 | UseMoralisWeb3ApiCallOptions, 8 | } from "../../core/useMoralisWeb3Api"; 9 | import { resolveIPFS } from "../../../functions/resolveIPFS"; 10 | import { DEFAULT_API_CHAIN } from "../../../config"; 11 | import { isValidApiChain } from "../../../utils/isValidApiChain"; 12 | 13 | export interface UseNFTBalancesParams 14 | extends Omit< 15 | Parameters[0], 16 | "address" 17 | > { 18 | address?: string; 19 | } 20 | 21 | export const useNFTBalances = ( 22 | params?: UseNFTBalancesParams, 23 | options?: UseMoralisWeb3ApiCallOptions, 24 | ) => { 25 | const { 26 | account: { getNFTs }, 27 | } = useMoralisWeb3Api(); 28 | const { chainId, account } = useMoralis(); 29 | 30 | const { 31 | fetch: getNFTBalances, 32 | data, 33 | error, 34 | isLoading, 35 | isFetching, 36 | } = useMoralisWeb3ApiCall( 37 | getNFTs, 38 | { 39 | chain: params?.chain ?? isValidApiChain(chainId) ?? DEFAULT_API_CHAIN, 40 | address: params?.address ?? account ?? "", 41 | ...params, 42 | }, 43 | { autoFetch: options?.autoFetch ?? !!account, ...options }, 44 | ); 45 | 46 | const balances = useMemo(() => { 47 | if (!data?.result || !data?.result.length) { 48 | return data; 49 | } 50 | 51 | const formattedResult = data.result.map((nft) => { 52 | try { 53 | if (nft.metadata) { 54 | const metadata = JSON.parse(nft.metadata); 55 | const image = resolveIPFS(metadata?.image); 56 | return { ...nft, image, metadata }; 57 | } 58 | } catch (error) { 59 | return nft; 60 | } 61 | return nft; 62 | }); 63 | 64 | return { ...data, result: formattedResult }; 65 | }, [data]); 66 | 67 | return { getNFTBalances, data: balances, error, isLoading, isFetching }; 68 | }; 69 | -------------------------------------------------------------------------------- /src/hooks/web3ApiWrappers/useNFTTransfers/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useNFTTransfers"; 2 | -------------------------------------------------------------------------------- /src/hooks/web3ApiWrappers/useNFTTransfers/useNFTTransfers.ts: -------------------------------------------------------------------------------- 1 | import MoralisType from "moralis-v1"; 2 | import { useMoralis } from "../../core/useMoralis"; 3 | import { 4 | useMoralisWeb3Api, 5 | useMoralisWeb3ApiCall, 6 | UseMoralisWeb3ApiCallOptions, 7 | } from "../../core/useMoralisWeb3Api"; 8 | import { DEFAULT_API_CHAIN } from "../../../config"; 9 | import { isValidApiChain } from "../../../utils/isValidApiChain"; 10 | 11 | export interface UseNFTTransfersParams 12 | extends Omit< 13 | Parameters[0], 14 | "address" 15 | > { 16 | address?: string; 17 | } 18 | 19 | export const useNFTTransfers = ( 20 | params?: UseNFTTransfersParams, 21 | options?: UseMoralisWeb3ApiCallOptions, 22 | ) => { 23 | const { 24 | account: { getNFTTransfers }, 25 | } = useMoralisWeb3Api(); 26 | const { chainId, account } = useMoralis(); 27 | 28 | const { fetch, data, error, isLoading, isFetching } = useMoralisWeb3ApiCall( 29 | getNFTTransfers, 30 | { 31 | chain: params?.chain ?? isValidApiChain(chainId) ?? DEFAULT_API_CHAIN, 32 | address: params?.address ?? account ?? "", 33 | ...params, 34 | }, 35 | { autoFetch: options?.autoFetch ?? !!account, ...options }, 36 | ); 37 | 38 | return { getNFTTransfers: fetch, data, error, isLoading, isFetching }; 39 | }; 40 | -------------------------------------------------------------------------------- /src/hooks/web3ApiWrappers/useNativeBalance/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useNativeBalance"; 2 | -------------------------------------------------------------------------------- /src/hooks/web3ApiWrappers/useNativeBalance/useNativeBalance.ts: -------------------------------------------------------------------------------- 1 | import MoralisType from "moralis-v1/types"; 2 | import { useMemo } from "react"; 3 | import { DEFAULT_API_CHAIN } from "../../../config"; 4 | import { isValidApiChain } from "../../../utils/isValidApiChain"; 5 | import { useMoralis } from "../../core/useMoralis"; 6 | import { 7 | useMoralisWeb3Api, 8 | useMoralisWeb3ApiCall, 9 | UseMoralisWeb3ApiCallOptions, 10 | } from "../../core/useMoralisWeb3Api"; 11 | import { tokenValueTxt } from "../../../utils/formatters"; 12 | import { getChain } from "../../../functions/chains"; 13 | 14 | export interface UseNativeBalancesParams 15 | extends Omit< 16 | Parameters[0], 17 | "address" 18 | > { 19 | address?: string; 20 | } 21 | 22 | export const useNativeBalance = ( 23 | params?: UseNativeBalancesParams, 24 | options?: UseMoralisWeb3ApiCallOptions, 25 | ) => { 26 | const { 27 | account: { getNativeBalance }, 28 | } = useMoralisWeb3Api(); 29 | const { chainId, account } = useMoralis(); 30 | 31 | const nativeToken = useMemo(() => { 32 | const chainData = getChain( 33 | params?.chain ?? isValidApiChain(chainId) ?? DEFAULT_API_CHAIN, 34 | ); 35 | 36 | if (!chainData) { 37 | return null; 38 | } 39 | 40 | return chainData.nativeCurrency; 41 | }, [params, chainId]); 42 | 43 | const { fetch, data, error, isLoading, isFetching } = useMoralisWeb3ApiCall( 44 | getNativeBalance, 45 | { 46 | chain: params?.chain ?? isValidApiChain(chainId) ?? DEFAULT_API_CHAIN, 47 | address: params?.address ?? account ?? "", 48 | ...params, 49 | }, 50 | { autoFetch: options?.autoFetch ?? !!account, ...options }, 51 | ); 52 | 53 | const formatted = useMemo(() => { 54 | if (!nativeToken || !data) { 55 | return null; 56 | } 57 | return tokenValueTxt( 58 | data.balance, 59 | nativeToken.decimals, 60 | nativeToken.symbol, 61 | ); 62 | }, [data, nativeToken]); 63 | 64 | return { 65 | getBalances: fetch, 66 | data: { 67 | balance: data?.balance, 68 | formatted, 69 | }, 70 | nativeToken, 71 | error, 72 | isLoading, 73 | isFetching, 74 | }; 75 | }; 76 | -------------------------------------------------------------------------------- /src/hooks/web3ApiWrappers/useNativeTransactions/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useNativeTransactions"; 2 | -------------------------------------------------------------------------------- /src/hooks/web3ApiWrappers/useNativeTransactions/useNativeTransactions.ts: -------------------------------------------------------------------------------- 1 | import MoralisType from "moralis-v1"; 2 | import { useMoralis } from "../../core/useMoralis"; 3 | import { 4 | useMoralisWeb3Api, 5 | useMoralisWeb3ApiCall, 6 | UseMoralisWeb3ApiCallOptions, 7 | } from "../../core/useMoralisWeb3Api"; 8 | import { DEFAULT_API_CHAIN } from "../../../config"; 9 | import { isValidApiChain } from "../../../utils/isValidApiChain"; 10 | 11 | export interface UseNativeTransactionsParams 12 | extends Omit< 13 | Parameters[0], 14 | "address" 15 | > { 16 | address?: string; 17 | } 18 | 19 | export const useNativeTransactions = ( 20 | params: UseNativeTransactionsParams, 21 | options?: UseMoralisWeb3ApiCallOptions, 22 | ) => { 23 | const { 24 | account: { getTransactions }, 25 | } = useMoralisWeb3Api(); 26 | const { chainId, account } = useMoralis(); 27 | 28 | const { 29 | fetch: getNativeTransations, 30 | data, 31 | error, 32 | isLoading, 33 | isFetching, 34 | } = useMoralisWeb3ApiCall( 35 | getTransactions, 36 | { 37 | chain: params?.chain ?? isValidApiChain(chainId) ?? DEFAULT_API_CHAIN, 38 | address: params?.address ?? account ?? "", 39 | ...params, 40 | }, 41 | { autoFetch: options?.autoFetch ?? !!account, ...options }, 42 | ); 43 | 44 | return { 45 | getNativeTransations, 46 | data, 47 | chainId, 48 | error, 49 | isLoading, 50 | isFetching, 51 | }; 52 | }; 53 | -------------------------------------------------------------------------------- /src/hooks/web3ApiWrappers/useTokenPrice/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./useTokenPrice"; 2 | -------------------------------------------------------------------------------- /src/hooks/web3ApiWrappers/useTokenPrice/useTokenPrice.ts: -------------------------------------------------------------------------------- 1 | import { useMemo } from "react"; 2 | import MoralisType from "moralis-v1"; 3 | import { tokenValueTxt, toUsd } from "../../../utils/formatters"; 4 | import { 5 | useMoralisWeb3Api, 6 | useMoralisWeb3ApiCall, 7 | UseMoralisWeb3ApiCallOptions, 8 | } from "../../core/useMoralisWeb3Api"; 9 | import { useMoralis } from "../../core/useMoralis"; 10 | import { DEFAULT_API_CHAIN } from "../../../config"; 11 | import { isValidApiChain } from "../../../utils/isValidApiChain"; 12 | 13 | export type UseTokenPriceParams = Parameters< 14 | typeof MoralisType.Web3API["token"]["getTokenPrice"] 15 | >[0]; 16 | 17 | export const useTokenPrice = ( 18 | params: UseTokenPriceParams, 19 | options?: UseMoralisWeb3ApiCallOptions, 20 | ) => { 21 | const { 22 | token: { getTokenPrice }, 23 | } = useMoralisWeb3Api(); 24 | const { chainId } = useMoralis(); 25 | 26 | const { fetch, data, error, isFetching, isLoading } = useMoralisWeb3ApiCall( 27 | getTokenPrice, 28 | { 29 | chain: params?.chain ?? isValidApiChain(chainId) ?? DEFAULT_API_CHAIN, 30 | ...params, 31 | }, 32 | { autoFetch: options?.autoFetch ?? true, ...options }, 33 | ); 34 | 35 | const formattedData = useMemo(() => { 36 | if (!data) { 37 | return null; 38 | } 39 | 40 | const { value, decimals, symbol } = data.nativePrice ?? {}; 41 | const formatted = { 42 | ...data, 43 | formattedUsd: toUsd(data.usdPrice), 44 | formattedNative: value 45 | ? tokenValueTxt(value, decimals ?? 0, symbol ?? "") 46 | : null, 47 | }; 48 | 49 | return formatted; 50 | }, [data]); 51 | 52 | return { 53 | fetchTokenPrice: fetch, 54 | data: formattedData, 55 | error, 56 | isLoading, 57 | isFetching, 58 | }; 59 | }; 60 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./hooks"; 2 | export * from "./components"; 3 | export * from "./context"; 4 | export * from "./functions"; 5 | 6 | export * from "./Errors"; 7 | -------------------------------------------------------------------------------- /src/utils/formatters.test.ts: -------------------------------------------------------------------------------- 1 | import { 2 | decimalToHexString, 3 | hexStringToDecimal, 4 | tokenValueTxt, 5 | toUsd, 6 | } from "./formatters"; 7 | 8 | describe("toUsd", () => { 9 | test.each` 10 | value | expected 11 | ${0} | ${"$0.00"} 12 | ${1} | ${"$1.00"} 13 | ${1.5} | ${"$1.50"} 14 | ${1.33333} | ${"$1.33"} 15 | ${1.666666} | ${"$1.67"} 16 | ${-1} | ${"-$1.00"} 17 | `("returns $expected for $value", ({ value, expected }) => { 18 | expect(toUsd(value)).toBe(expected); 19 | }); 20 | }); 21 | 22 | describe("tokenValueTxt", () => { 23 | test.each` 24 | value | decimals | symbol | expected 25 | ${0} | ${18} | ${"WETH"} | ${"0 WETH"} 26 | ${1000000000000000000} | ${18} | ${"WETH"} | ${"1 WETH"} 27 | ${50000000000000000} | ${18} | ${"WETH"} | ${"0.05 WETH"} 28 | ${500000000000000} | ${18} | ${"WETH"} | ${"0.0005 WETH"} 29 | ${543211111000000} | ${18} | ${"WETH"} | ${"0.0005432 WETH"} 30 | ${10000000} | ${6} | ${"USDC"} | ${"10 USDC"} 31 | ${-1000000000000000000} | ${18} | ${"WETH"} | ${"-1 WETH"} 32 | ${10} | ${0} | ${"TEST"} | ${"10 TEST"} 33 | ${10} | ${1} | ${"TEST"} | ${"1 TEST"} 34 | `( 35 | "returns $expected for $value, $decimals, $symbol", 36 | ({ value, decimals, symbol, expected }) => { 37 | expect(tokenValueTxt(value, decimals, symbol)).toBe(expected); 38 | }, 39 | ); 40 | }); 41 | 42 | describe("decimalToHexString", () => { 43 | test.each` 44 | value | expected 45 | ${0} | ${"0x0"} 46 | ${1} | ${"0x1"} 47 | ${2} | ${"0x2"} 48 | ${42} | ${"0x2a"} 49 | `("convert hex $value to decimal $expected", ({ value, expected }) => { 50 | expect(decimalToHexString(value)).toBe(expected); 51 | }); 52 | }); 53 | 54 | describe("hexStringToDecimal", () => { 55 | test.each` 56 | value | expected 57 | ${"0x0"} | ${0} 58 | ${"0x1"} | ${1} 59 | ${"0x2"} | ${2} 60 | ${"0x2a"} | ${42} 61 | `("convert decimal $value for hex $expected", ({ value, expected }) => { 62 | expect(hexStringToDecimal(value)).toBe(expected); 63 | }); 64 | }); 65 | -------------------------------------------------------------------------------- /src/utils/formatters.ts: -------------------------------------------------------------------------------- 1 | const currencyFormatter = new Intl.NumberFormat("en-us", { 2 | style: "currency", 3 | currency: "USD", 4 | minimumFractionDigits: 2, 5 | maximumFractionDigits: 2, 6 | }); 7 | 8 | export const decimalFormatter = new Intl.NumberFormat("en-us", { 9 | style: "decimal", 10 | minimumSignificantDigits: 1, 11 | maximumSignificantDigits: 4, 12 | }); 13 | 14 | export const toUsd = (value: number) => currencyFormatter.format(value); 15 | 16 | export const limitDecimals = (value: number) => decimalFormatter.format(value); 17 | 18 | export const tokenValue = (value: number, decimals: number) => 19 | value / Math.pow(10, decimals); 20 | 21 | export const tokenValueTxt = ( 22 | value: number | string, 23 | decimals: number, 24 | symbol: string, 25 | ) => { 26 | if (typeof value === "number") { 27 | return `${limitDecimals(tokenValue(value, decimals))} ${symbol}`; 28 | } 29 | // TODO: handle as BN 30 | return `${limitDecimals(tokenValue(Number(value), decimals))} ${symbol}`; 31 | }; 32 | 33 | export const decimalToHexString = (decimal: number) => 34 | "0x" + decimal.toString(16); 35 | 36 | export const hexStringToDecimal = (hexString: string) => 37 | parseInt(hexString, 16); 38 | -------------------------------------------------------------------------------- /src/utils/genericQuery.ts: -------------------------------------------------------------------------------- 1 | import MoralisType from "moralis-v1"; 2 | 3 | export type DefaultQueryAttribute = MoralisType.Attributes; 4 | 5 | export type Query< 6 | Entity extends DefaultQueryAttribute = DefaultQueryAttribute, 7 | > = MoralisType.Query>; 8 | -------------------------------------------------------------------------------- /src/utils/isValidApiChain.ts: -------------------------------------------------------------------------------- 1 | import { ApiChain } from "../config/"; 2 | 3 | export const isValidApiChain = (chain?: string | null) => { 4 | if (!chain) { 5 | return null; 6 | } 7 | // TODO: add check if chain is in provided list 8 | return chain as ApiChain; 9 | }; 10 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "skipLibCheck": true, 4 | "strict": true, 5 | "baseUrl": ".", 6 | "rootDir": "src", 7 | "declaration": true, 8 | "outDir": "lib", 9 | "declarationDir": "lib", 10 | "module": "esnext", 11 | "target": "es5", 12 | "lib": ["es6", "dom", "es2016", "es2017"], 13 | "sourceMap": true, 14 | "jsx": "react-jsx", 15 | "moduleResolution": "node", 16 | "resolveJsonModule": true, 17 | "isolatedModules": false, 18 | "allowSyntheticDefaultImports": true, 19 | "esModuleInterop": true, 20 | "forceConsistentCasingInFileNames": true, 21 | "noFallthroughCasesInSwitch": true, 22 | "composite": true, 23 | "useUnknownInCatchVariables": false 24 | }, 25 | "exclude": ["lib", "node_modules"], 26 | "include": ["src/**/*", "types/**/*"] 27 | } 28 | --------------------------------------------------------------------------------