From a6a826e25e2d9a59df62bd88950ee439a660e644 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Mon, 3 Jun 2024 12:06:36 -0300 Subject: [PATCH 01/11] feat: add docs for useContractRead --- packages/docs/docs/dev/hooks-reference.mdx | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/packages/docs/docs/dev/hooks-reference.mdx b/packages/docs/docs/dev/hooks-reference.mdx index 8299d426d..91d738d36 100644 --- a/packages/docs/docs/dev/hooks-reference.mdx +++ b/packages/docs/docs/dev/hooks-reference.mdx @@ -5,6 +5,46 @@ category: For Developers # React Hooks Reference +## `useContractRead` + +Reads and calls a method from a Fuel contract, returns ``. + + +### Reading with a Contract instance +```tsx +const { contract } = useContractRead({ + contract: _contract, + functionName: 'get_count', + args: undefined, +}); +``` + +### Reading with ABI + ContractId + Provider +```tsx +const { contract } = useContractRead({ + address, + abi: counterAbi, + provider: fuelProvider, + functionName: 'get_count', + args: undefined, +}); +``` +> See [here](/fuels-ts/cookbook/wallet-sdk-and-react-hooks/#the-provider) for more information on our Provider +> Cick [here](https://github.com/FuelLabs/fuels-wallet/blob/b5766321dbc2a5e5f17f05e0cb9a9f697f137a23/packages/e2e-contract-tests/src/contracts/contracts/factories/CustomAssetAbi__factory.ts#L16) to see an example of an ABI for a Fuel contract + +[See the source file](https://github.com/FuelLabs/fuels-npm-packs/tree/main/packages/react/src/hooks/useAccount.ts) + +## `useAccounts` + +Retrieves the fuel accounts and returns the addresses of the accounts `` + +```tsx +const { accounts } = useAccounts(); +console.log(accounts); +// [fuel1r20zhd..., fuel1qqluc9..., ...] +``` + +[See the source file](https://github.com/FuelLabs/fuels-npm-packs/tree/main/packages/react/src/hooks/useContractRead.ts) ## `useAccount` Retrieves the current fuel account and returns the account address ``. From 65dbc76f704a5e3e07cda7cfacfc2f24c13ecc28 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Mon, 3 Jun 2024 12:20:20 -0300 Subject: [PATCH 02/11] chore: decrease size of headings --- packages/docs/docs/dev/hooks-reference.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/docs/docs/dev/hooks-reference.mdx b/packages/docs/docs/dev/hooks-reference.mdx index 91d738d36..ac16c541f 100644 --- a/packages/docs/docs/dev/hooks-reference.mdx +++ b/packages/docs/docs/dev/hooks-reference.mdx @@ -10,7 +10,7 @@ category: For Developers Reads and calls a method from a Fuel contract, returns ``. -### Reading with a Contract instance +#### Reading with a Contract instance ```tsx const { contract } = useContractRead({ contract: _contract, @@ -19,7 +19,7 @@ const { contract } = useContractRead({ }); ``` -### Reading with ABI + ContractId + Provider +#### Reading with ABI + ContractId + Provider ```tsx const { contract } = useContractRead({ address, From 5b04adcf5cf82b99a0734845e59b317e98004a04 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Mon, 3 Jun 2024 12:20:31 -0300 Subject: [PATCH 03/11] chore: add line break --- packages/docs/docs/dev/hooks-reference.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/docs/docs/dev/hooks-reference.mdx b/packages/docs/docs/dev/hooks-reference.mdx index ac16c541f..cd4b4d943 100644 --- a/packages/docs/docs/dev/hooks-reference.mdx +++ b/packages/docs/docs/dev/hooks-reference.mdx @@ -29,7 +29,8 @@ const { contract } = useContractRead({ args: undefined, }); ``` -> See [here](/fuels-ts/cookbook/wallet-sdk-and-react-hooks/#the-provider) for more information on our Provider +> See [here](/fuels-ts/cookbook/wallet-sdk-and-react-hooks/#the-provider) for more information on our Provider + > Cick [here](https://github.com/FuelLabs/fuels-wallet/blob/b5766321dbc2a5e5f17f05e0cb9a9f697f137a23/packages/e2e-contract-tests/src/contracts/contracts/factories/CustomAssetAbi__factory.ts#L16) to see an example of an ABI for a Fuel contract [See the source file](https://github.com/FuelLabs/fuels-npm-packs/tree/main/packages/react/src/hooks/useAccount.ts) From 3f7f4b21cf3538d817aa66acf7648f89fe6f0eed Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Mon, 3 Jun 2024 13:34:58 -0300 Subject: [PATCH 04/11] feat: add reference to ts sdk docs --- packages/docs/docs/dev/hooks-reference.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docs/docs/dev/hooks-reference.mdx b/packages/docs/docs/dev/hooks-reference.mdx index cd4b4d943..c291b71a2 100644 --- a/packages/docs/docs/dev/hooks-reference.mdx +++ b/packages/docs/docs/dev/hooks-reference.mdx @@ -29,7 +29,7 @@ const { contract } = useContractRead({ args: undefined, }); ``` -> See [here](/fuels-ts/cookbook/wallet-sdk-and-react-hooks/#the-provider) for more information on our Provider +> See [here](/fuels-ts/cookbook/wallet-sdk-and-react-hooks/#the-provider) for more information on our Provider in our TS SDK [docs](https://docs.fuel.network/docs/fuels-ts/) > Cick [here](https://github.com/FuelLabs/fuels-wallet/blob/b5766321dbc2a5e5f17f05e0cb9a9f697f137a23/packages/e2e-contract-tests/src/contracts/contracts/factories/CustomAssetAbi__factory.ts#L16) to see an example of an ABI for a Fuel contract From 97204208c41eac3079f8732ce5c77a3446eebe98 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Mon, 3 Jun 2024 13:37:54 -0300 Subject: [PATCH 05/11] fix: remove duplicate doc --- packages/docs/docs/dev/hooks-reference.mdx | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/packages/docs/docs/dev/hooks-reference.mdx b/packages/docs/docs/dev/hooks-reference.mdx index c291b71a2..c52bb6b89 100644 --- a/packages/docs/docs/dev/hooks-reference.mdx +++ b/packages/docs/docs/dev/hooks-reference.mdx @@ -35,17 +35,6 @@ const { contract } = useContractRead({ [See the source file](https://github.com/FuelLabs/fuels-npm-packs/tree/main/packages/react/src/hooks/useAccount.ts) -## `useAccounts` - -Retrieves the fuel accounts and returns the addresses of the accounts `` - -```tsx -const { accounts } = useAccounts(); -console.log(accounts); -// [fuel1r20zhd..., fuel1qqluc9..., ...] -``` - -[See the source file](https://github.com/FuelLabs/fuels-npm-packs/tree/main/packages/react/src/hooks/useContractRead.ts) ## `useAccount` Retrieves the current fuel account and returns the account address ``. From 6bf008d9c45241d2c3d1dbbe6d11c29d793246eb Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Mon, 3 Jun 2024 17:30:01 -0300 Subject: [PATCH 06/11] chore: change heading size --- packages/docs/docs/dev/hooks-reference.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/docs/docs/dev/hooks-reference.mdx b/packages/docs/docs/dev/hooks-reference.mdx index c52bb6b89..2ecf96013 100644 --- a/packages/docs/docs/dev/hooks-reference.mdx +++ b/packages/docs/docs/dev/hooks-reference.mdx @@ -10,7 +10,7 @@ category: For Developers Reads and calls a method from a Fuel contract, returns ``. -#### Reading with a Contract instance +### Reading with a Contract instance ```tsx const { contract } = useContractRead({ contract: _contract, @@ -19,7 +19,7 @@ const { contract } = useContractRead({ }); ``` -#### Reading with ABI + ContractId + Provider +### Reading with ABI + ContractId + Provider ```tsx const { contract } = useContractRead({ address, From 800b96ff48388b8777b4c63d5df04dd940d2b323 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Mon, 3 Jun 2024 17:31:35 -0300 Subject: [PATCH 07/11] feat: update docs with changes --- packages/docs/docs/dev/hooks-reference.mdx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/docs/docs/dev/hooks-reference.mdx b/packages/docs/docs/dev/hooks-reference.mdx index 2ecf96013..291a9c556 100644 --- a/packages/docs/docs/dev/hooks-reference.mdx +++ b/packages/docs/docs/dev/hooks-reference.mdx @@ -12,7 +12,7 @@ Reads and calls a method from a Fuel contract, returns ``. ### Reading with a Contract instance ```tsx -const { contract } = useContractRead({ +const { contractRead } = useContractRead({ contract: _contract, functionName: 'get_count', args: undefined, @@ -21,10 +21,8 @@ const { contract } = useContractRead({ ### Reading with ABI + ContractId + Provider ```tsx -const { contract } = useContractRead({ - address, - abi: counterAbi, - provider: fuelProvider, +const { contractRead } = useContractRead({ + contract: { address, abi: countAbi, provider }, functionName: 'get_count', args: undefined, }); From 8465f577944b2440dc2a5d6605420e555701c6ae Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Mon, 3 Jun 2024 18:22:22 -0300 Subject: [PATCH 08/11] fix: put doc in alphabetical order --- packages/docs/docs/dev/hooks-reference.mdx | 56 +++++++++++----------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/packages/docs/docs/dev/hooks-reference.mdx b/packages/docs/docs/dev/hooks-reference.mdx index 291a9c556..27e059c82 100644 --- a/packages/docs/docs/dev/hooks-reference.mdx +++ b/packages/docs/docs/dev/hooks-reference.mdx @@ -5,34 +5,6 @@ category: For Developers # React Hooks Reference -## `useContractRead` - -Reads and calls a method from a Fuel contract, returns ``. - - -### Reading with a Contract instance -```tsx -const { contractRead } = useContractRead({ - contract: _contract, - functionName: 'get_count', - args: undefined, -}); -``` - -### Reading with ABI + ContractId + Provider -```tsx -const { contractRead } = useContractRead({ - contract: { address, abi: countAbi, provider }, - functionName: 'get_count', - args: undefined, -}); -``` -> See [here](/fuels-ts/cookbook/wallet-sdk-and-react-hooks/#the-provider) for more information on our Provider in our TS SDK [docs](https://docs.fuel.network/docs/fuels-ts/) - -> Cick [here](https://github.com/FuelLabs/fuels-wallet/blob/b5766321dbc2a5e5f17f05e0cb9a9f697f137a23/packages/e2e-contract-tests/src/contracts/contracts/factories/CustomAssetAbi__factory.ts#L16) to see an example of an ABI for a Fuel contract - -[See the source file](https://github.com/FuelLabs/fuels-npm-packs/tree/main/packages/react/src/hooks/useAccount.ts) - ## `useAccount` Retrieves the current fuel account and returns the account address ``. @@ -115,6 +87,34 @@ console.log(connectors); [See the source file](https://github.com/FuelLabs/fuels-npm-packs/tree/main/packages/react/src/hooks/useConnectors.ts) +## `useContractRead` + +Reads and calls a method from a Fuel contract, returns ``. + + +### Reading with a Contract instance +```tsx +const { contractRead } = useContractRead({ + contract: _contract, + functionName: 'get_count', + args: undefined, +}); +``` + +### Reading with ABI + ContractId + Provider +```tsx +const { contractRead } = useContractRead({ + contract: { address, abi: countAbi, provider }, + functionName: 'get_count', + args: undefined, +}); +``` +> See [here](/fuels-ts/cookbook/wallet-sdk-and-react-hooks/#the-provider) for more information on our Provider in our TS SDK [docs](https://docs.fuel.network/docs/fuels-ts/) + +> Cick [here](https://github.com/FuelLabs/fuels-wallet/blob/b5766321dbc2a5e5f17f05e0cb9a9f697f137a23/packages/e2e-contract-tests/src/contracts/contracts/factories/CustomAssetAbi__factory.ts#L16) to see an example of an ABI for a Fuel contract + +[See the source file](https://github.com/FuelLabs/fuels-npm-packs/tree/main/packages/react/src/hooks/useAccount.ts) + ## `useDisconnect` Facilitates disconnection from the Fuel Wallet. It provides a function `>` to initiate disconnection. From af2de955d0dad884c7afcb2b030af52c49c783e9 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Mon, 3 Jun 2024 18:27:30 -0300 Subject: [PATCH 09/11] fix: typo --- packages/docs/docs/dev/hooks-reference.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docs/docs/dev/hooks-reference.mdx b/packages/docs/docs/dev/hooks-reference.mdx index 27e059c82..19b98c7dd 100644 --- a/packages/docs/docs/dev/hooks-reference.mdx +++ b/packages/docs/docs/dev/hooks-reference.mdx @@ -111,7 +111,7 @@ const { contractRead } = useContractRead({ ``` > See [here](/fuels-ts/cookbook/wallet-sdk-and-react-hooks/#the-provider) for more information on our Provider in our TS SDK [docs](https://docs.fuel.network/docs/fuels-ts/) -> Cick [here](https://github.com/FuelLabs/fuels-wallet/blob/b5766321dbc2a5e5f17f05e0cb9a9f697f137a23/packages/e2e-contract-tests/src/contracts/contracts/factories/CustomAssetAbi__factory.ts#L16) to see an example of an ABI for a Fuel contract +> Click [here](https://github.com/FuelLabs/fuels-wallet/blob/b5766321dbc2a5e5f17f05e0cb9a9f697f137a23/packages/e2e-contract-tests/src/contracts/contracts/factories/CustomAssetAbi__factory.ts#L16) to see an example of an ABI for a Fuel contract [See the source file](https://github.com/FuelLabs/fuels-npm-packs/tree/main/packages/react/src/hooks/useAccount.ts) From 3f6884e8a1bfbfac5121cbf8368b245f74707b93 Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Mon, 3 Jun 2024 20:23:46 -0300 Subject: [PATCH 10/11] fix: doc link --- packages/docs/docs/dev/hooks-reference.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docs/docs/dev/hooks-reference.mdx b/packages/docs/docs/dev/hooks-reference.mdx index 19b98c7dd..cbebdde42 100644 --- a/packages/docs/docs/dev/hooks-reference.mdx +++ b/packages/docs/docs/dev/hooks-reference.mdx @@ -109,7 +109,7 @@ const { contractRead } = useContractRead({ args: undefined, }); ``` -> See [here](/fuels-ts/cookbook/wallet-sdk-and-react-hooks/#the-provider) for more information on our Provider in our TS SDK [docs](https://docs.fuel.network/docs/fuels-ts/) +> For more information on our Provider, refer to our TS SDK [docs](https://docs.fuel.network/docs/fuels-ts/) > Click [here](https://github.com/FuelLabs/fuels-wallet/blob/b5766321dbc2a5e5f17f05e0cb9a9f697f137a23/packages/e2e-contract-tests/src/contracts/contracts/factories/CustomAssetAbi__factory.ts#L16) to see an example of an ABI for a Fuel contract From 8b070568eb2ab58c41a010913eba173fd84e655a Mon Sep 17 00:00:00 2001 From: Arthur Geron <3487334+arthurgeron@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:18:54 -0300 Subject: [PATCH 11/11] chore: change heading siz --- packages/docs/docs/dev/hooks-reference.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/docs/docs/dev/hooks-reference.mdx b/packages/docs/docs/dev/hooks-reference.mdx index cbebdde42..3f301d017 100644 --- a/packages/docs/docs/dev/hooks-reference.mdx +++ b/packages/docs/docs/dev/hooks-reference.mdx @@ -92,7 +92,7 @@ console.log(connectors); Reads and calls a method from a Fuel contract, returns ``. -### Reading with a Contract instance +##### Reading with a Contract instance ```tsx const { contractRead } = useContractRead({ contract: _contract, @@ -101,7 +101,7 @@ const { contractRead } = useContractRead({ }); ``` -### Reading with ABI + ContractId + Provider +##### Reading with ABI + ContractId + Provider ```tsx const { contractRead } = useContractRead({ contract: { address, abi: countAbi, provider },