Skip to content

Commit

Permalink
Merge branch 'master' into ps/chore/refactor-get-transaction-cost
Browse files Browse the repository at this point in the history
  • Loading branch information
petertonysmith94 authored Jul 12, 2024
2 parents b9058e0 + b7a3e5b commit f06fdff
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-forks-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-fuels": patch
---

chore: replace `create-fuels` hardcoded values with constants
5 changes: 5 additions & 0 deletions .changeset/soft-cycles-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/contract": patch
---

fix: `launchTestNode` multiple contracts type inference
8 changes: 4 additions & 4 deletions apps/create-fuels-counter-guide/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ 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, DOCS_URL, Environments } from "@/lib";

// #region deploying-dapp-to-testnet-frontend-contract-id
const contractId =
CURRENT_ENVIRONMENT === "local"
CURRENT_ENVIRONMENT === Environments.LOCAL
? contractIds.testContract
: (process.env.NEXT_PUBLIC_TESTNET_CONTRACT_ID as string); // Testnet Contract ID
// #endregion deploying-dapp-to-testnet-frontend-contract-id
Expand Down Expand Up @@ -92,7 +92,7 @@ export default function Home() {

<span className="text-gray-400">
This template uses the new{" "}
<Link href="https://docs.fuel.network/docs/fuels-ts/fuels/#fuels-cli">
<Link href={`${DOCS_URL}/docs/fuels-ts/fuels/#fuels-cli`}>
Fuels CLI
</Link>{" "}
to enable type-safe hot-reloading for your Sway programs.
Expand Down Expand Up @@ -123,7 +123,7 @@ export default function Home() {
<Link href="/script" className="mt-4">
Script Example
</Link>
<Link href="https://docs.fuel.network" target="_blank" className="mt-12">
<Link href={DOCS_URL} target="_blank" className="mt-12">
Fuel Docs
</Link>
</>
Expand Down
4 changes: 2 additions & 2 deletions apps/create-fuels-counter-guide/src/hooks/useFaucet.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NODE_URL } from "@/lib";
import { FAUCET_PRIVATE_KEY, NODE_URL } from "@/lib";
import { Provider, Wallet, WalletUnlocked } from "fuels";
import { useState } from "react";
import useAsync from "react-use/lib/useAsync";
Expand All @@ -9,7 +9,7 @@ export const useFaucet = () => {
useAsync(async () => {
if (!faucetWallet) {
const provider = await Provider.create(NODE_URL);
const wallet = Wallet.fromPrivateKey("0x01", provider);
const wallet = Wallet.fromPrivateKey(FAUCET_PRIVATE_KEY, provider);
setFaucetWallet(wallet);
}
}, [faucetWallet]);
Expand Down
20 changes: 14 additions & 6 deletions apps/create-fuels-counter-guide/src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { Account, BN } from 'fuels';
import { Account, BN, TESTNET_NETWORK_URL } from 'fuels';

// #region deploying-dapp-to-testnet-lib-current-environment
type DappEnvironment = 'local' | 'testnet';
export const Environments = {
LOCAL: 'local',
TESTNET: 'testnet',
} as const;
type Environment = (typeof Environments)[keyof typeof Environments];

export const CURRENT_ENVIRONMENT: DappEnvironment =
(process.env.NEXT_PUBLIC_DAPP_ENVIRONMENT as DappEnvironment) || 'local';
export const CURRENT_ENVIRONMENT: Environment =
(process.env.NEXT_PUBLIC_DAPP_ENVIRONMENT as Environment) || Environments.LOCAL;
// #endregion deploying-dapp-to-testnet-lib-current-environment

export const NODE_URL =
CURRENT_ENVIRONMENT === 'local'
CURRENT_ENVIRONMENT === Environments.LOCAL
? `http://127.0.0.1:${process.env.NEXT_PUBLIC_FUEL_NODE_PORT || 4000}/v1/graphql`
: 'https://testnet.fuel.network/v1/graphql';
: TESTNET_NETWORK_URL;

export interface AppWallet {
wallet?: Account;
Expand All @@ -19,3 +23,7 @@ export interface AppWallet {
}

export const TESTNET_FAUCET_LINK = 'https://faucet-testnet.fuel.network/';

export const FAUCET_PRIVATE_KEY = '0x01';

export const DOCS_URL = 'https://docs.fuel.network';
4 changes: 2 additions & 2 deletions apps/docs/src/guide/wallets/connectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ By using these connectors, developers can simplify wallet integration and enable

## Learning Resources

For a deeper understanding of `Fuel Wallet Connectors` and how to start using them in your projects, consider the following resources:
For a deeper understanding of `Fuel Connectors` and how to start using them in your projects, consider the following resources:

- [**Fuel Wallet Connectors Wiki**](https://github.com/FuelLabs/fuels-wallet/wiki/Fuel-Wallet-Connectors) - read about what is `Fuel Wallet Connector` and how it works.
- [**Fuel Connectors Wiki**](https://github.com/FuelLabs/fuel-connectors/wiki) - read about what a `Fuel Connector` is and how it works.
- [**Fuel Connectors Guide**](https://docs.fuel.network/docs/wallet/dev/connectors/) - find out how to set up and use connectors.
- [**GitHub Repository**](https://github.com/FuelLabs/fuel-connectors) - explore different connector implementations.
2 changes: 1 addition & 1 deletion packages/contract/src/test-utils/launch-test-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function getWalletForDeployment(config: DeployContractConfig, wallets: WalletUnl
return wallets[config.walletIndex];
}

export async function launchTestNode<TFactories extends DeployContractConfig[]>({
export async function launchTestNode<const TFactories extends DeployContractConfig[]>({
providerOptions = {},
walletsConfig = {},
nodeOptions = {},
Expand Down
29 changes: 29 additions & 0 deletions packages/fuel-gauge/src/launch-test-node-types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { launchTestNode } from 'fuels/test-utils';

import type { AdvancedLoggingAbi, CallTestContractAbi } from '../test/typegen';
import { AdvancedLoggingAbi__factory, CallTestContractAbi__factory } from '../test/typegen';
import AdvancedLoggingBytecode from '../test/typegen/contracts/AdvancedLoggingAbi.hex';
import CallTestContractBytecode from '../test/typegen/contracts/CallTestContractAbi.hex';

/**
* @group node
* @group browser
*/
describe('type level tests for launchTestNode', () => {
test('infers types correctly', async () => {
using launched = await launchTestNode({
contractsConfigs: [
{ deployer: AdvancedLoggingAbi__factory, bytecode: AdvancedLoggingBytecode },
{ deployer: CallTestContractAbi__factory, bytecode: CallTestContractBytecode },
{ deployer: AdvancedLoggingAbi__factory, bytecode: AdvancedLoggingBytecode },
],
});
const {
contracts: [c1, c2, c3],
} = launched;

expectTypeOf(c1).toMatchTypeOf<AdvancedLoggingAbi>();
expectTypeOf(c2).toMatchTypeOf<CallTestContractAbi>();
expectTypeOf(c3).toMatchTypeOf<AdvancedLoggingAbi>();
});
});
8 changes: 4 additions & 4 deletions templates/nextjs/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ 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, DOCS_URL, Environments } from "@/lib";

const contractId =
CURRENT_ENVIRONMENT === "local"
CURRENT_ENVIRONMENT === Environments.LOCAL
? contractIds.testContract
: (process.env.NEXT_PUBLIC_TESTNET_CONTRACT_ID as string); // Testnet Contract ID

Expand Down Expand Up @@ -73,7 +73,7 @@ export default function Home() {

<span className="text-gray-400">
This template uses the new{" "}
<Link href="https://docs.fuel.network/docs/fuels-ts/fuels/#fuels-cli">
<Link href={`${DOCS_URL}/docs/fuels-ts/fuels/#fuels-cli`}>
Fuels CLI
</Link>{" "}
to enable type-safe hot-reloading for your Sway programs.
Expand All @@ -98,7 +98,7 @@ export default function Home() {
<Link href="/script" className="mt-4">
Script Example
</Link>
<Link href="https://docs.fuel.network" target="_blank" className="mt-12">
<Link href={DOCS_URL} target="_blank" className="mt-12">
Fuel Docs
</Link>
</>
Expand Down
4 changes: 2 additions & 2 deletions templates/nextjs/src/hooks/useFaucet.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NODE_URL } from "@/lib";
import { FAUCET_PRIVATE_KEY, NODE_URL } from "@/lib";
import { Provider, Wallet, WalletUnlocked } from "fuels";
import { useState } from "react";
import useAsync from "react-use/lib/useAsync";
Expand All @@ -9,7 +9,7 @@ export const useFaucet = () => {
useAsync(async () => {
if (!faucetWallet) {
const provider = await Provider.create(NODE_URL);
const wallet = Wallet.fromPrivateKey("0x01", provider);
const wallet = Wallet.fromPrivateKey(FAUCET_PRIVATE_KEY, provider);
setFaucetWallet(wallet);
}
}, [faucetWallet]);
Expand Down
20 changes: 14 additions & 6 deletions templates/nextjs/src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Account, BN } from 'fuels';
import { Account, BN, TESTNET_NETWORK_URL } from 'fuels';

type DappEnvironment = 'local' | 'testnet';
export const Environments = {
LOCAL: 'local',
TESTNET: 'testnet',
} as const;
type Environment = (typeof Environments)[keyof typeof Environments];

export const CURRENT_ENVIRONMENT: DappEnvironment =
(process.env.NEXT_PUBLIC_DAPP_ENVIRONMENT as DappEnvironment) || 'local';
export const CURRENT_ENVIRONMENT: Environment =
(process.env.NEXT_PUBLIC_DAPP_ENVIRONMENT as Environment) || Environments.LOCAL;

export const NODE_URL =
CURRENT_ENVIRONMENT === 'local'
CURRENT_ENVIRONMENT === Environments.LOCAL
? `http://127.0.0.1:${process.env.NEXT_PUBLIC_FUEL_NODE_PORT || 4000}/v1/graphql`
: 'https://testnet.fuel.network/v1/graphql';
: TESTNET_NETWORK_URL;

export interface AppWallet {
wallet?: Account;
Expand All @@ -17,3 +21,7 @@ export interface AppWallet {
}

export const TESTNET_FAUCET_LINK = 'https://faucet-testnet.fuel.network/';

export const FAUCET_PRIVATE_KEY = '0x01';

export const DOCS_URL = 'https://docs.fuel.network';

0 comments on commit f06fdff

Please sign in to comment.