From 78656e4fa893e7515eb3a7631c7edfff93ba9141 Mon Sep 17 00:00:00 2001 From: Erno Date: Fri, 21 Jan 2022 22:52:57 +0000 Subject: [PATCH 1/3] chore: bump moralis version --- package.json | 4 ++-- yarn.lock | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 42fad6a..cc6fb84 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "husky": "^7.0.4", "jest": "^27.4.5", "lint-staged": "^12.1.2", - "moralis": "^1.0.7", + "moralis": "1.1.0", "prettier": "^2.5.1", "rollup": "^2.61.1", "rollup-plugin-cleaner": "^1.0.0", @@ -77,7 +77,7 @@ "typescript": "^4.5.4" }, "peerDependencies": { - "moralis": ">=1.0.7", + "moralis": ">=1.1.0", "react": ">=17.0.0", "react-dom": ">=17.0.0" }, diff --git a/yarn.lock b/yarn.lock index 480dd8e..50c78d0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7011,10 +7011,10 @@ modify-values@^1.0.0: resolved "https://registry.yarnpkg.com/modify-values/-/modify-values-1.0.1.tgz#b3939fa605546474e3e3e3c63d64bd43b4ee6022" integrity sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw== -moralis@^1.0.7: - version "1.0.7" - resolved "https://registry.yarnpkg.com/moralis/-/moralis-1.0.7.tgz#20c5f1acde236d71009c817af4cd793ec82032b0" - integrity sha512-23RwCJayAQHUSPtrVFiAmy4LaSjFLiy2z0Z7AvvCZ7CfbsUY8U+fuJRX0Yh8YcR5W3HzDQfxR7C6xSoRjMiMCQ== +moralis@1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/moralis/-/moralis-1.1.0.tgz#aed5c01b00ac1860236c5237d0a6a54986708eec" + integrity sha512-NJSJ/gCgY4AI3BZ7YHvKC/xe8BcKpevwgHgux9UWMv7tZNhTPju+7vIdTIoPJQgcWUlmHFPZ1v70a0dGttF8pA== dependencies: "@babel/runtime" "7.16.7" "@babel/runtime-corejs3" "7.16.8" From efd9d1218460ff81b67a661706c78bd234763a20 Mon Sep 17 00:00:00 2001 From: Erno Wever Date: Fri, 21 Jan 2022 22:56:27 +0000 Subject: [PATCH 2/3] feat: support for Moralis.SolanaAPI --- README.md | 40 +++++++++++++++++++ src/hooks/core/index.ts | 1 + src/hooks/core/useMoralisSolanaApi/index.ts | 1 + .../useMoralisSolanaApi.ts | 30 ++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 src/hooks/core/useMoralisSolanaApi/index.ts create mode 100644 src/hooks/core/useMoralisSolanaApi/useMoralisSolanaApi.ts diff --git a/README.md b/README.md index 1882e55..f5f7e25 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,8 @@ function App() { - [Trigger manually](#trigger-manually) - [`useMoralisWeb3Api()`](#usemoralisweb3api) - [Resolve data with `useMoralisWeb3ApiCall()`](#resolve-data-with-usemoralisweb3apicall) + - [`useMoralisSolanaApi()`](#usemoralissolanaapi) + - [Resolve data with `useMoralisSolanaApiCall()`](#resolve-data-with-usemoralissolanaapicall) - [`useNewMoralisObject()`](#usenewmoralisobject) - [`useWeb3ExecuteFunction()`](#useweb3executefunction) - [`useChain()`](#usechain) @@ -750,6 +752,44 @@ For this you can use `useMoralisWeb3ApiCall()`: ``` +## `useMoralisSolanaApi()` +This hook will expose all the convenience functions of the `Moralis.SolanaAPI` in the sdk (ex. `SolanaApi.account.balance`). You can use this function in any way you want, for example: + +```jsx +const SolanaApi = useMoralisSolanaApi() + +const fetchBalance = async() => { + const result = await SolanaApi.account.balance({ + network: "mainnet", + address: "3yFwqXBfZY4jBVUafQ1YEXw189y2dN3V5KQq9uzBDy1E", + }) + console.log(result) +} +``` + +### Resolve data with `useMoralisSolanaApiCall()` + +You can also use a resolver, to resolve the asynchronous function. This works similar to useMoralisQuery or useMoralisCloudFunction. It will resolve the data/error for you and will re-trigger if dependencies change. + +For this you can use `useMoralisSolanaApiCall()`: + +```jsx + const SolanaApi = useMoralisSolanaApi() + + const { fetch, data, error, isLoading } = useMoralisSolanaApiCall(SolanaApi.account.balance, { + network: "mainnet", + address: "3yFwqXBfZY4jBVUafQ1YEXw189y2dN3V5KQq9uzBDy1E", + }); + + return ( +
+ +
{JSON.stringify(data, null, 2)}
+
+ ) + +``` + ## `useNewMoralisObject()` This is a wrapper around the save method for a `Moralis.Object`. It creates a new object, and resolves the data, error and loading state, similar to the other hooks. diff --git a/src/hooks/core/index.ts b/src/hooks/core/index.ts index 4105bab..5d7f4c3 100644 --- a/src/hooks/core/index.ts +++ b/src/hooks/core/index.ts @@ -6,6 +6,7 @@ export * from "./useMoralisObject"; export * from "./useMoralisQuery"; export * from "./useMoralisSubscription"; export * from "./useMoralisWeb3Api"; +export * from "./useMoralisSolanaApi"; export * from "./useWeb3Contract"; export * from "./useWeb3ExecuteFunction"; export * from "./useWeb3Transfer"; diff --git a/src/hooks/core/useMoralisSolanaApi/index.ts b/src/hooks/core/useMoralisSolanaApi/index.ts new file mode 100644 index 0000000..fdf6722 --- /dev/null +++ b/src/hooks/core/useMoralisSolanaApi/index.ts @@ -0,0 +1 @@ +export * from "./useMoralisSolanaApi"; diff --git a/src/hooks/core/useMoralisSolanaApi/useMoralisSolanaApi.ts b/src/hooks/core/useMoralisSolanaApi/useMoralisSolanaApi.ts new file mode 100644 index 0000000..8146d3b --- /dev/null +++ b/src/hooks/core/useMoralisSolanaApi/useMoralisSolanaApi.ts @@ -0,0 +1,30 @@ +import { + ResolveCallParams, + UseResolveCallOptions, + _useResolveCall, +} from "../../internal/_useResolveAsyncCall"; +import { useMoralis } from "../useMoralis"; + +export interface UseMoralisSolanaApiCallOptions extends UseResolveCallOptions {} + +export const useMoralisSolanaCall = ( + call: (params: Params) => Promise, + params?: Params, + options?: UseMoralisSolanaApiCallOptions, +) => { + const result = _useResolveCall( + call, + null, + params, + options, + false, + ); + + return result; +}; + +export const useMoralisSolanaApi = () => { + const { Moralis } = useMoralis(); + + return { SolanaAPI: Moralis.SolanaAPI, ...Moralis.SolanaAPI }; +}; From eaa4c3b1758bcf183c590ad8f53e67d9fbec2db9 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 21 Jan 2022 22:57:41 +0000 Subject: [PATCH 3/3] chore(release): set `package.json` to 1.1.0 [skip ci] # [1.1.0](https://github.com/MoralisWeb3/react-moralis/compare/v1.0.4...v1.1.0) (2022-01-21) ### Features * support for Moralis.SolanaAPI ([efd9d12](https://github.com/MoralisWeb3/react-moralis/commit/efd9d1218460ff81b67a661706c78bd234763a20)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e738fc..fb92ca6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [1.1.0](https://github.com/MoralisWeb3/react-moralis/compare/v1.0.4...v1.1.0) (2022-01-21) + + +### Features + +* support for Moralis.SolanaAPI ([efd9d12](https://github.com/MoralisWeb3/react-moralis/commit/efd9d1218460ff81b67a661706c78bd234763a20)) + ## [1.0.4](https://github.com/MoralisWeb3/react-moralis/compare/v1.0.3...v1.0.4) (2022-01-20) diff --git a/package.json b/package.json index cc6fb84..8cf0241 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-moralis", - "version": "1.0.4", + "version": "1.1.0", "description": "Hooks and components to use Moralis in a React app", "keywords": [ "moralis",