Skip to content

Commit

Permalink
feat: Add AddressType to AbiType Register
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsdls committed Jan 18, 2024
1 parent 400ba8a commit a847edf
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 9 deletions.
6 changes: 6 additions & 0 deletions packages/thirdweb/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { transaction, type TransactionOptions } from "./transaction/index.js";
import { memoizePromise } from "./utils/promise.js";
import type { AbiFunction } from "abitype";

declare module "abitype" {
export interface Register {
AddressType: string;
}
}

export type CreateClientOptions =
| {
clientId: string;
Expand Down
8 changes: 5 additions & 3 deletions packages/thirdweb/src/react/wallet-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "react";
import type { IWallet } from "../wallets/interfaces/wallet.js";

export type WalletWithId = IWallet & { _id: string };
export type WalletWithId = IWallet<any> & { _id: string };

type WalletContext = {
activeWallet: WalletWithId | null;
Expand Down Expand Up @@ -115,14 +115,14 @@ export function useConnect() {
const [error, setError] = useState<Error | null>(null);

const connect = useCallback(
async (options: IWallet | (() => Promise<IWallet>)) => {
async function <T>(options: IWallet<T> | (() => Promise<IWallet<T>>)) {
// reset error state
setError(null);
if (typeof options !== "function") {
const walletWithId = options as WalletWithId;
walletWithId._id = fakeUuid();
connectWallet(walletWithId);
return;
return walletWithId as IWallet<T>;
}

setIsConnecting(true);
Expand All @@ -132,11 +132,13 @@ export function useConnect() {
const walletWithId = wallet as WalletWithId;
walletWithId._id = fakeUuid();
connectWallet(walletWithId);
return walletWithId as IWallet<T>;
} catch (e) {
setError(e as Error);
} finally {
setIsConnecting(false);
}
return null;
},
[connectWallet],
);
Expand Down
2 changes: 1 addition & 1 deletion packages/thirdweb/src/rpc/methods.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Address } from "abitype";
import type { RPCClient } from "./index.js";
import {
type Address,
type BlockNumber,
type BlockTag,
type RpcBlock,
Expand Down
5 changes: 3 additions & 2 deletions packages/thirdweb/src/transaction/actions/estimate-gas.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { AbiFunction, Address } from "abitype";
import type { AbiFunction } from "abitype";
import type { Transaction } from "../index.js";
import { getDefaultGasOverrides } from "../../gas/fee-data.js";
import { encode } from "./encode.js";
import { formatTransactionRequest, hexToBigInt } from "viem/utils";
import type { IWallet } from "../../wallets/interfaces/wallet.js";
import type { Address } from "viem";

export async function estimateGas<
const abiFn extends AbiFunction,
const wallet extends IWallet,
const wallet extends IWallet<any>,
>(tx: Transaction<abiFn>, wallet?: wallet) {
const rpcRequest = tx.client.rpc({ chainId: tx.inputs.chainId });

Expand Down
2 changes: 1 addition & 1 deletion packages/thirdweb/src/transaction/actions/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { IWallet } from "../../wallets/interfaces/wallet.js";

export async function execute<
const abiFn extends AbiFunction,
const wallet extends IWallet,
const wallet extends IWallet<any>,
>(tx: Transaction<abiFn>, wallet: wallet) {
if (!wallet || !wallet.address) {
throw new Error("no wallet to sign with");
Expand Down
2 changes: 1 addition & 1 deletion packages/thirdweb/src/wallets/interfaces/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Address } from "abitype";
import type { Transaction } from "../../transaction/index.js";
import type {
AbiFunction,
Address,
Hex,
SignableMessage,
TransactionReceipt,
Expand Down
3 changes: 2 additions & 1 deletion packages/thirdweb/src/wallets/private-key.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
Address,
Hash,
Hex,
PrivateKeyAccount,
Expand All @@ -7,7 +8,7 @@ import type {
TypedDataDefinition,
} from "viem";
import type { ThirdwebClient } from "../client/client.js";
import type { AbiFunction, Address, TypedData } from "abitype";
import type { AbiFunction, TypedData } from "abitype";
import type { Transaction } from "../transaction/index.js";
import type { IWallet } from "./interfaces/wallet.js";

Expand Down

0 comments on commit a847edf

Please sign in to comment.