Skip to content

Commit

Permalink
insert deployment json at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
zapaz committed Dec 26, 2024
1 parent 8f5fb36 commit 7bf2a0c
Show file tree
Hide file tree
Showing 29 changed files with 156 additions and 651 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests
File renamed without changes.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "wagmi-svelte5",
"version": "0.1.1",
"name": "@wagmi-svelte5",
"version": "0.1.2",
"license": "MIT",
"files": [
"dist"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"svelte": "./dist/index.js"
"types": "./dist/wagmi/index.d.ts",
"svelte": "./dist/wagmi/index.js"
}
},
"svelte": "./dist/index.js",
"svelte": "./dist/wagmi/index.js",
"sideEffects": [
"**/*.css"
],
Expand Down
397 changes: 11 additions & 386 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/lib/wagmi/classes/Account.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getAccount, watchAccount } from "@wagmi/core";
import { Address, wagmiConfig } from "@wagmi-svelte5";
import type { Nullable } from "@wagmi-svelte5";
import { Address, wagmiConfig } from "..";
import type { Nullable } from "..";

type AccountType = ReturnType<typeof getAccount>;

Expand Down
18 changes: 11 additions & 7 deletions src/lib/wagmi/classes/Address.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { untrack } from "svelte";
import { type Address as AddressType, checksumAddress } from "viem";
import { deepEqual, getBalance as getBalanceWagmi, type GetBalanceReturnType } from "@wagmi/core";

import { isAddress, isEns } from "@wagmi-svelte5";
import type { Nullable } from "@wagmi-svelte5";
import { wagmi, wagmiConfig, Watcher } from "@wagmi-svelte5";
import { getEnsAddress, getEnsAvatar, getEnsName } from "@wagmi/core";
import { mainnet } from "viem/chains";
import { untrack } from "svelte";

import {
deepEqual,
getBalance as getBalanceWagmi,
type GetBalanceReturnType,
getEnsAddress,
getEnsAvatar,
getEnsName
} from "@wagmi/core";
import { type Nullable, isAddress, isEns, wagmi, wagmiConfig, Watcher } from "..";

class Address {
watcher: Nullable<Watcher>;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wagmi/classes/Client.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getPublicClient, watchPublicClient } from "@wagmi/core";
import { wagmiConfig } from "@wagmi-svelte5";
import { wagmiConfig } from "..";

type PublicClientType = typeof Client.prototype.publicClient;

Expand Down
9 changes: 3 additions & 6 deletions src/lib/wagmi/classes/Events.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { type Address as AddressType, type ContractEventName, type Log } from "viem";

import { type DeploymentContractName } from "@wagmi-svelte5";

import { SmartContract, wagmi, wagmiConfig } from "@wagmi-svelte5";
import { getContractEvents, type LogWithArgs } from "@wagmi-svelte5";
import { watchContractEvent, getBlockNumber } from "@wagmi/core";

import { type LogWithArgs, SmartContract, wagmi, wagmiConfig, getContractEvents } from "..";

type EventsFilter = { eventName?: ContractEventName; args?: Record<string, unknown> };
type EventsSortOrder = "DESC" | "ASC" | undefined;

Expand Down Expand Up @@ -85,7 +82,7 @@ class Events extends SmartContract {
};

constructor(
nameOrAddress: DeploymentContractName | AddressType,
nameOrAddress: string | AddressType,
{
filter = {},
limit = 3,
Expand Down
9 changes: 5 additions & 4 deletions src/lib/wagmi/classes/Network.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { untrack } from "svelte";
import * as chains from "viem/chains";
import type { Chain } from "viem/chains";
import {
type WatchBlockNumberReturnType,
getBlockNumber as getBlockNumberWagmi,
switchChain,
watchBlockNumber as watchBlockNumberWagmi,
disconnect as disconnectWagmi
} from "@wagmi/core";
import { Account, wagmi, wagmiConfig } from "@wagmi-svelte5";
import * as chains from "viem/chains";
import type { Chain } from "viem/chains";
import { untrack } from "svelte";

import { Account, wagmi, wagmiConfig } from "..";

// Network Class, reactive on chainId
class Network {
Expand Down
24 changes: 11 additions & 13 deletions src/lib/wagmi/classes/SmartContract.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import { type Abi, type AbiFunction, type Address as AddressType } from "viem";
import { untrack } from "svelte";
import { SvelteMap } from "svelte/reactivity";
import type { Renderable } from "svelte-hot-french-toast";
import { type Abi, type AbiFunction, type Address as AddressType } from "viem";
import {
type ReadContractReturnType,
deepEqual,
readContract,
serialize,
waitForTransactionReceipt,
writeContract
} from "@wagmi/core";
import { wagmi, wagmiConfig } from "@wagmi-svelte5";
import { isAddress, shorten0xString, type DeploymentsChainId } from "@wagmi-svelte5";
import { readDeployment, type DeploymentContractName } from "@wagmi-svelte5";
import { untrack } from "svelte";
import { notification } from "@wagmi-svelte5";
import { LinkTx } from "@wagmi-svelte5";
import type { Renderable } from "svelte-hot-french-toast";

import { wagmi, wagmiConfig, isAddress, shorten0xString, readDeployment, notification, LinkTx } from "..";

let counter = 0;

class SmartContract {
id = 0;
chainId = $derived(wagmi.chainId as DeploymentsChainId);
chainId = $derived(wagmi.chainId);

name: string | undefined;
#nameOrAddress: DeploymentContractName | AddressType | undefined;
#nameOrAddress: string | AddressType | undefined;

get address(): AddressType | undefined {
const { address } = readDeployment(this.chainId, this.#nameOrAddress!) ?? {};
Expand All @@ -34,7 +32,7 @@ class SmartContract {
return abi;
}

#setNameOrAddress(nameOrAddress: DeploymentContractName | AddressType) {
#setNameOrAddress(nameOrAddress: string | AddressType) {
this.#nameOrAddress = nameOrAddress;
this.name = isAddress(nameOrAddress)
? "Contract @" + shorten0xString(this.#nameOrAddress as `0x$string`)
Expand All @@ -47,7 +45,7 @@ class SmartContract {
const { address, abi } = readDeployment(chainId, this.#nameOrAddress!) ?? {};
if (!(address && abi)) return;

const dataKey = JSON.stringify({ chainId, address, functionName, args });
const dataKey = serialize({ chainId, address, functionName, args });

return { chainId, address, abi, dataKey };
};
Expand Down Expand Up @@ -170,7 +168,7 @@ class SmartContract {
return hash;
};

constructor(nameOrAddress: DeploymentContractName | AddressType) {
constructor(nameOrAddress: string | AddressType) {
if (!nameOrAddress) throw new Error("SmartContract nameOrAddress required");

this.id = ++counter;
Expand Down
9 changes: 2 additions & 7 deletions src/lib/wagmi/classes/Wagmi.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ import {
type CreateConnectorFn
} from "@wagmi/core";
import { coinbaseWallet, injected, metaMask, walletConnect } from "@wagmi/connectors";
import { Network, createBurnerConnector, alchemyTransport } from "@wagmi-svelte5";
import {
ALCHEMY_API_KEY,
POLLING_INTERVAL,
CHAINS,
WALLET_CONNECT_PROJECT_ID
} from "@wagmi-svelte5";

import { Network, createBurnerConnector, alchemyTransport, ALCHEMY_API_KEY, POLLING_INTERVAL, CHAINS, WALLET_CONNECT_PROJECT_ID } from "..";

const getChains = () => {
const selectedChains: Chain[] = [];
Expand Down
92 changes: 0 additions & 92 deletions src/lib/wagmi/classes/Wagmi.svelte.ts.orig

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib/wagmi/classes/Watcher.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { POLLING_INTERVAL } from "@wagmi-svelte5";
import { POLLING_INTERVAL } from "..";

class Watcher {
id = $state(0);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/wagmi/components/BaseNotification.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
XMark
} from "svelte-hero-icons";
import toast_, { type Renderable, type Toast } from "svelte-hot-french-toast";
import { clickOutside } from "@wagmi-svelte5";
import { clickOutside } from "..";
const {
...allProps
Expand Down
10 changes: 7 additions & 3 deletions src/lib/wagmi/components/Connect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
type GetConnectorsReturnType
} from "@wagmi/core";
import { Network, wagmiConfig } from "@wagmi-svelte5";
import { BURNER_WALLET_ONLY_LOCAL } from "@wagmi-svelte5";
import { isDeploymentsChainId, type Nullable } from "@wagmi-svelte5";
import {
type Nullable,
Network,
wagmiConfig,
BURNER_WALLET_ONLY_LOCAL,
isDeploymentsChainId
} from "..";
type ConnectorType = GetConnectorsReturnType[number];
Expand Down
3 changes: 1 addition & 2 deletions src/lib/wagmi/components/LinkAddress.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
import { Link } from "@wagmi-svelte5";
import { Network, wagmi } from "@wagmi-svelte5";
import { Link , Network, wagmi } from "..";
const { address, description = "address" }: { address?: `0x${string}`; description?: string } =
$props();
Expand Down
4 changes: 1 addition & 3 deletions src/lib/wagmi/components/LinkTx.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<script lang="ts">
import { Link } from "@wagmi-svelte5";
import { shorten0xString } from "@wagmi-svelte5";
import { Network, wagmi } from "@wagmi-svelte5";
import { Link , Network,shorten0xString , wagmi } from "..";
const {
hash,
Expand Down
6 changes: 2 additions & 4 deletions src/lib/wagmi/components/Logs.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<script lang="ts">
import { replacer } from "@wagmi-svelte5";
import { Events } from "@wagmi-svelte5";
import type { DeploymentContractName } from "@wagmi-svelte5";
import { Events , replacer } from "..";
const { contractName }: { contractName: DeploymentContractName } = $props();
const { contractName }: { contractName: string } = $props();
const events = $derived(new Events(contractName));
</script>
Expand Down
18 changes: 4 additions & 14 deletions src/lib/wagmi/components/ViewEvents.svelte
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
<script lang="ts">
import { Logs } from "@wagmi-svelte5";
import {
readDeploymentContractsName,
type DeploymentContractName,
type DeploymentsChainId
} from "@wagmi-svelte5";
import { wagmi } from "@wagmi-svelte5";
import { Logs ,readDeploymentContractsName ,wagmi } from "..";
const localStorageContractKey = "wagmiSvelte5.contractSelected";
const contractsName: DeploymentContractName[] = $derived(
readDeploymentContractsName(wagmi.chainId as DeploymentsChainId)
);
const contractsName: string[] = $derived(readDeploymentContractsName(wagmi.chainId));
const getDefaultContractName = () => {
const localStorageContractName = localStorage.getItem(
localStorageContractKey
) as DeploymentContractName;
const localStorageContractName = localStorage.getItem(localStorageContractKey) as string;
if (localStorageContractName && contractsName.includes(localStorageContractName))
return localStorageContractName;
if (contractsName.length > 0) return contractsName[0];
};
let contractSelected = $state(getDefaultContractName());
const setDefaultContractName = (contractName: DeploymentContractName) => {
const setDefaultContractName = (contractName: string) => {
contractSelected = contractName;
localStorage.setItem(localStorageContractKey, String(contractName));
};
Expand Down
Loading

0 comments on commit 7bf2a0c

Please sign in to comment.