Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: include all supported connectors in the create fuels template #2691

Merged
merged 35 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6085010
chore: include all supported connectors in the create fuels template
Dhaiwat10 Jul 3, 2024
94e3e2b
add changeset
Dhaiwat10 Jul 3, 2024
78470c9
Merge branch 'master' into dp/bump-fuel-connectors
maschad Jul 4, 2024
723979c
Merge branch 'master' into dp/bump-fuel-connectors
Dhaiwat10 Jul 4, 2024
23ffcaa
initialise connectors properly
Dhaiwat10 Jul 8, 2024
1643ac6
reset dummy contract id
Dhaiwat10 Jul 8, 2024
36ffef8
Merge branch 'master' into dp/bump-fuel-connectors
Dhaiwat10 Jul 8, 2024
9e189fa
Update pnpm-lock.yaml
Dhaiwat10 Jul 8, 2024
4e17a6c
enable pr release
Dhaiwat10 Jul 8, 2024
28e438a
update docs
Dhaiwat10 Jul 8, 2024
734f89b
Update Forc.toml
Dhaiwat10 Jul 8, 2024
518c54e
fix formatting
Dhaiwat10 Jul 8, 2024
9e13861
Update .knip.json
Dhaiwat10 Jul 8, 2024
6df5cb2
disable pr release
Dhaiwat10 Jul 8, 2024
5c0aeb9
Update .knip.json
Dhaiwat10 Jul 8, 2024
78aa2af
Merge branch 'master' into dp/bump-fuel-connectors
Dhaiwat10 Jul 8, 2024
5027d91
revert unrelated changes
Dhaiwat10 Jul 8, 2024
ba09ad9
add msg in changeset
Dhaiwat10 Jul 8, 2024
6bcc5a6
Merge branch 'master' into dp/bump-fuel-connectors
Dhaiwat10 Jul 8, 2024
081658a
refactor gitignores
Dhaiwat10 Jul 8, 2024
a4923e8
Merge branch 'dp/bump-fuel-connectors' of https://github.com/FuelLabs…
Dhaiwat10 Jul 8, 2024
fcc1568
Merge branch 'master' into dp/bump-fuel-connectors
Dhaiwat10 Jul 8, 2024
737c27e
Merge branch 'master' into dp/bump-fuel-connectors
Torres-ssf Jul 8, 2024
2362ffa
Merge branch 'master' into dp/bump-fuel-connectors
Dhaiwat10 Jul 8, 2024
a9f8df5
Merge branch 'master' into dp/bump-fuel-connectors
Dhaiwat10 Jul 9, 2024
1dda013
modify changeset
Dhaiwat10 Jul 9, 2024
0349b77
Merge branch 'master' into dp/bump-fuel-connectors
Dhaiwat10 Jul 9, 2024
06b54e9
Merge branch 'master' into dp/bump-fuel-connectors
Torres-ssf Jul 10, 2024
4221348
update fuel-core version
Dhaiwat10 Jul 10, 2024
d6ef1bc
Merge branch 'master' into dp/bump-fuel-connectors
Dhaiwat10 Jul 10, 2024
231148c
Update pnpm-lock.yaml
Dhaiwat10 Jul 10, 2024
ad5b75a
Merge branch 'dp/bump-fuel-connectors' of https://github.com/FuelLabs…
Dhaiwat10 Jul 10, 2024
a4d97a4
update lockfile
Dhaiwat10 Jul 10, 2024
8c986a0
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into dp…
petertonysmith94 Jul 10, 2024
457da59
Merge branch 'master' into dp/bump-fuel-connectors
petertonysmith94 Jul 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changeset/tall-rockets-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---
Dhaiwat10 marked this conversation as resolved.
Show resolved Hide resolved

chore: include all supported connectors in the create fuels template
3 changes: 2 additions & 1 deletion .knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"**/*/.vitepress/*",
"/apps/docs/*",
"/packages/abi-typegen/test/**",
"templates/**"
"templates/**",
"apps/create-fuels-counter-guide/**"
],
"ignoreDependencies": [
"bun",
Expand Down
6 changes: 1 addition & 5 deletions apps/create-fuels-counter-guide/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
NEXT_PUBLIC_HAS_CONTRACT=true
NEXT_PUBLIC_HAS_PREDICATE=false
NEXT_PUBLIC_HAS_SCRIPT=false
NEXT_PUBLIC_FUEL_NODE_PORT=4000
NEXT_PUBLIC_DAPP_ENVIRONMENT=local
NEXT_PUBLIC_TESTNET_CONTRACT_ID=0x9310ab0b757826b745d601cb682c1b4f35abde02cddd67f8535c0b5bfb296d25
NEXT_PUBLIC_DAPP_ENVIRONMENT=local
4 changes: 2 additions & 2 deletions apps/create-fuels-counter-guide/fuels.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// #region fuels-config-file-env
import { createConfig } from 'fuels';
import dotenv from 'dotenv';
import { NODE_URL } from '@/lib'
import { NODE_URL } from '@/lib';

dotenv.config({
path: ['.env.local', '.env'],
Expand All @@ -15,4 +15,4 @@ export default createConfig({
fuelCorePort,
providerUrl: NODE_URL,
});
// #endregion fuels-config-file-env
// #endregion fuels-config-file-env
2 changes: 1 addition & 1 deletion apps/create-fuels-counter-guide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"postbuild": "run-s fuels:build original:build"
},
"dependencies": {
"@fuels/connectors": "^0.2.2",
"@fuels/connectors": "^0.8.1",
"@fuels/react": "^0.20.0",
"fuels": "workspace:*",
"@tanstack/react-query": "^5.29.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
"use client";

import { Button } from "@/components/Button";
import { Input } from "@/components/Input";
import { useActiveWallet } from "@/hooks/useActiveWallet";
import { useFaucet } from "@/hooks/useFaucet";
import { BN, bn } from "fuels";
import { useState } from "react";
import { bn } from "fuels";
import { useEffect, useState } from "react";
import toast from "react-hot-toast";

export default function Faucet() {
const { faucetWallet } = useFaucet();
const { wallet, refreshWalletBalance } = useActiveWallet();

const { refreshWalletBalance } = useActiveWallet();
const [receiverAddress, setReceiverAddress] = useState<string>("");
const [amountToSend, setAmountToSend] = useState<string>("5");

const [receiverAddress, setReceiverAddress] = useState<string>();
const [amountToSend, setAmountToSend] = useState<BN>();
useEffect(() => {
if (wallet) {
setReceiverAddress(wallet.address.toB256());
}
}, [wallet]);

const sendFunds = async () => {
if (!faucetWallet) {
Expand All @@ -27,7 +34,10 @@ export default function Faucet() {
return toast.error("Amount cannot be empty");
}

const tx = await faucetWallet.transfer(receiverAddress, amountToSend);
const tx = await faucetWallet.transfer(
receiverAddress,
bn.parseUnits(amountToSend.toString()),
);
await tx.waitForResult();

toast.success("Funds sent!");
Expand All @@ -40,25 +50,29 @@ export default function Faucet() {
<h3 className="text-2xl font-semibold">Local Faucet</h3>

<div className="flex gap-4 items-center">
<span className="text-gray-400">Receiving address:</span>
<label htmlFor="receiver-address-input" className="text-gray-400">
Receiving address:
</label>
<Input
className="w-full"
value={receiverAddress}
onChange={(e) => setReceiverAddress(e.target.value)}
placeholder="0x..."
id="receiver-address-input"
/>
</div>

<div className="flex gap-4 items-center">
<span className="text-gray-400">Amount:</span>
<label htmlFor="amount-input" className="text-gray-400">
Amount (ETH):
</label>
<Input
className="w-full"
value={amountToSend?.toString()}
onChange={(e) =>
setAmountToSend(e.target.value ? bn(e.target.value) : undefined)
}
placeholder="100"
value={amountToSend}
onChange={(e) => setAmountToSend(e.target.value)}
placeholder="5"
type="number"
id="amount-input"
/>
</div>

Expand Down
66 changes: 66 additions & 0 deletions apps/create-fuels-counter-guide/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"use client";

import { Layout } from "@/components/Layout";
import "@/styles/globals.css";
import { FuelProvider } from "@fuels/react";
import React, { ReactNode, useEffect, useMemo, useState } from "react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { Provider } from "fuels";
import {
BakoSafeConnector,
BurnerWalletConnector,
FuelWalletConnector,
FuelWalletDevelopmentConnector,
FueletWalletConnector,
WalletConnectConnector,
} from "@fuels/connectors";
import { NODE_URL } from "@/lib";
import { ActiveWalletProvider } from "@/hooks/useActiveWallet";

const queryClient = new QueryClient();

interface RootLayoutProps {
children: ReactNode;
}

export default function RootLayout({ children }: RootLayoutProps) {
const [isMounted, setIsMounted] = useState(false);
const providerToUse = useMemo(() => Provider.create(NODE_URL), [NODE_URL]);

useEffect(() => {
setIsMounted(true);
}, []);

if (!isMounted) return null;

return (
<html lang="en" className="bg-black text-white">
<body>
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<FuelProvider
fuelConfig={{
connectors: [
new FuelWalletConnector(),
new BurnerWalletConnector({
fuelProvider: providerToUse,
}),
new WalletConnectConnector({
fuelProvider: providerToUse,
}),
new BakoSafeConnector(),
new FueletWalletConnector(),
new FuelWalletDevelopmentConnector(),
danielbate marked this conversation as resolved.
Show resolved Hide resolved
],
}}
>
<ActiveWalletProvider>
<Layout>{children}</Layout>
</ActiveWalletProvider>
</FuelProvider>
</QueryClientProvider>
</React.StrictMode>
</body>
</html>
);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/** @knipignore */
"use client";

import type { TestContractAbi } from "@/sway-api";
/** @knipignore */
import { TestContractAbi__factory } from "@/sway-api";
import contractIds from "@/sway-api/contract-ids.json";

import { FuelLogo } from "@/components/FuelLogo";
import { bn } from "fuels";
import { useState } from "react";
Expand All @@ -12,7 +11,7 @@ import { Button } from "@/components/Button";
import toast from "react-hot-toast";
import { useActiveWallet } from "@/hooks/useActiveWallet";
import useAsync from "react-use/lib/useAsync";
import { CURRENT_ENVIRONMENT } from '@/lib'
import { CURRENT_ENVIRONMENT } from "@/lib";

// #region deploying-dapp-to-testnet-frontend-contract-id
const contractId =
Expand All @@ -21,11 +20,6 @@ const contractId =
: (process.env.NEXT_PUBLIC_TESTNET_CONTRACT_ID as string); // Testnet Contract ID
// #endregion deploying-dapp-to-testnet-frontend-contract-id


const hasContract = process.env.NEXT_PUBLIC_HAS_CONTRACT === "true";
const hasPredicate = process.env.NEXT_PUBLIC_HAS_PREDICATE === "true";
const hasScript = process.env.NEXT_PUBLIC_HAS_SCRIPT === "true";

export default function Home() {
const { wallet, walletBalance, refreshWalletBalance } = useActiveWallet();
const [contract, setContract] = useState<TestContractAbi>();
Expand All @@ -36,7 +30,7 @@ export default function Home() {
* See: https://github.com/streamich/react-use/blob/master/docs/useAsync.md
*/
useAsync(async () => {
if (hasContract && wallet) {
if (wallet) {
const testContract = TestContractAbi__factory.connect(contractId, wallet);
setContract(testContract);
const { value } = await testContract.functions.get_count().get();
Expand Down Expand Up @@ -88,12 +82,10 @@ export default function Home() {
<h1 className="text-2xl font-semibold ali">Welcome to Fuel</h1>
</div>

{hasContract && (
<span className="text-gray-400">
Get started by editing <i>sway-programs/contract/main.sw</i> or{" "}
<i>src/pages/index.tsx</i>.
</span>
)}
<span className="text-gray-400">
Get started by editing <i>sway-programs/contract/main.sw</i> or{" "}
<i>src/pages/index.tsx</i>.
</span>

<span className="text-gray-400">
This template uses the new{" "}
Expand All @@ -103,36 +95,31 @@ export default function Home() {
to enable type-safe hot-reloading for your Sway programs.
</span>

{hasContract && (
<>
<h3 className="text-xl font-semibold">Counter</h3>

<span className="text-gray-400 text-6xl">{counter}</span>
<>
<h3 className="text-xl font-semibold">Counter</h3>

<Button onClick={onIncrementPressed} className="mt-6">
Increment Counter
</Button>
<span data-testid="counter" className="text-gray-400 text-6xl">
{counter}
</span>

{/* #region create-fuels-counter-guide-on-decrement-ui */}
<Button onClick={onDecrementPressed} className="mt-6">
Decrement Counter
</Button>
{/* #endregion create-fuels-counter-guide-on-decrement-ui */}
</>
)}
<Button onClick={onIncrementPressed} className="mt-6">
Increment Counter
</Button>

{hasPredicate && (
<Link href="/predicate" className="mt-4">
Predicate Example
</Link>
)}
{/* #region create-fuels-counter-guide-on-decrement-ui */}
<Button onClick={onDecrementPressed} className="mt-6">
Decrement Counter
</Button>
{/* #endregion create-fuels-counter-guide-on-decrement-ui */}
</>

{hasScript && (
<Link href="/script" className="mt-4">
Script Example
</Link>
)}
<Link href="/predicate" className="mt-4">
Predicate Example
</Link>

<Link href="/script" className="mt-4">
Script Example
</Link>
<Link href="https://docs.fuel.network" target="_blank" className="mt-12">
Fuel Docs
</Link>
Expand Down
Loading
Loading