adrianhajdin / project_crowdfunding

With a stunning design, connected to the blockchain, metamask pairing, interaction with smart contracts, sending Ethereum through the blockchain network, and writing solidity code.
https://jsmastery.pro
693 stars 375 forks source link

StateContextProvider #19

Open Davison82 opened 1 year ago

Davison82 commented 1 year ago

Hi All

I'm having trouble with the StateContext.Provider return function. The "Create a campaign" button which appears in the tutorial isn't there.

return (
    <StateContext.Provider
        value={{ 
            address,
            contract,
            connect,
            createCampaign: publishCampaign,
         }}
    >
        {children}
    </StateContext.Provider>
)

}

export const useStateContext = () => useContext (StateContext);

Davison82 commented 1 year ago

image

A-Pradeep commented 1 year ago

@Davison82 Hi, the CreateCampaign button is written at Navbar

<div className="flex mx-4">
            <CustomButton
              btnType="button"
              title={address ? "Create a Campaign" : "Connect"}
              styles={address ? "bg-[#1dc071]" : "bg-[#8c6dfd]"}
              handleClick={() => {
                if (address) {
                  navigate("create_campaign");
                  setToggleDrawer((prev) => !prev);
                } else {
                  connect();
                }
              }}
            />
          </div>

StateContext.Provider is passing connect function. You can refer this : https://github.com/adrianhajdin/project_crowdfunding/blob/a554d7eaeefe1f6f2b73c8ecd837b6805aaed4b7/client/src/components/Navbar.jsx#L81

Davison82 commented 1 year ago

Hi Pradeep Thank you for replying to my question. I have checked the code in the Navbar as you suggested and it's good but after importing { UseStateContext } and const { connect, address } = useStateContext(); nothing happnes the button is dead. Is there a package that I need to download?

Best RegardsJohn On Wednesday, 1 March 2023 at 13:35:26 GMT, Pradeep A @.***> wrote:

@Davison82 Hi, the CreateCampaign button is written at Navbar

{ if (address) { navigate("create_campaign"); setToggleDrawer((prev) => !prev); } else { connect(); } }} />

StateContext.Provider is passing connect function. You can refer this : https://github.com/adrianhajdin/project_crowdfunding/blob/a554d7eaeefe1f6f2b73c8ecd837b6805aaed4b7/client/src/components/Navbar.jsx#L81

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

A-Pradeep commented 1 year ago

@Davison82 No additional package was installed. Can you try this code snipped inside handleClick trigger

handleClick={() => { if (address) navigate("create_campaign"); else connect(); }}

Davison82 commented 1 year ago

Thank you this is now functioning.

Now, I'm having issues with the Campaign Details page.

<CountBox title={Raised of ${state.target}} value={state.amountCollected} />

It won't display the amount donated?