Skip to content

Commit

Permalink
various tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Oct 15, 2024
1 parent d07784f commit 37b7650
Show file tree
Hide file tree
Showing 13 changed files with 444 additions and 39 deletions.
5 changes: 3 additions & 2 deletions packages/entrykit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@latticexyz/world-modules": "workspace:*",
"@noble/curves": "^1.6.0",
"@radix-ui/react-dialog": "^1.0.5",
"@rainbow-me/rainbowkit": "^2.1.7",
"@rainbow-me/rainbowkit": "2.1.7",
"@tanstack/react-query": "^5.56.2",
"abitype": "catalog:",
"debug": "^4.3.4",
Expand All @@ -64,7 +64,6 @@
"zustand": "^4.5.2"
},
"devDependencies": {
"@ark/util": "catalog:",
"@latticexyz/explorer": "workspace:*",
"@types/debug": "^4.1.7",
"@types/react": "18.2.22",
Expand All @@ -79,6 +78,8 @@
"tailwindcss": "^3.4.13",
"tsup": "^6.7.0",
"vite": "^5.4.1",
"vite-plugin-dts": "^4.2.4",
"vite-plugin-externalize-deps": "^0.8.0",
"vitest": "0.34.6"
},
"publishConfig": {
Expand Down
3 changes: 2 additions & 1 deletion packages/entrykit/playground/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useEffect } from "react";
import { AccountButton, useAccountModal } from "../src/exports";
import { useLocalStorage } from "usehooks-ts";
import { UserWrite } from "./UserWrite";
import { ConnectButton } from "@rainbow-me/rainbowkit";
import { AppAccountWrite } from "./AppAccountWrite";
import { useAccountModal } from "../src/useAccountModal";
import { AccountButton } from "../src/AccountButton";

export function App() {
const { openAccountModal } = useAccountModal();
Expand Down
1 change: 1 addition & 0 deletions packages/entrykit/src/EntryKitConfigProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function EntryKitConfigProvider({ config, children }: Props) {
const currentConfig = useContext(Context);
if (currentConfig) throw new Error("`EntryKitProvider` can only be used once.");

// throw new Error("here");
return (
<RainbowKitProvider
initialChain={config.chainId}
Expand Down
2 changes: 2 additions & 0 deletions packages/entrykit/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export type EntryKitConfig = {
*/
readonly worldAddress: Address;

readonly walletConnectProjectId: string;

readonly bundlerTransport: Transport;
// currently assumes quarry paymaster
readonly paymasterAddress: Address;
Expand Down
7 changes: 0 additions & 7 deletions packages/entrykit/src/exports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,3 @@
*
* Be sure we're ready to commit to these being supported and changes made backward compatible!
*/

export type { EntryKitConfig } from "../config";
export { EntryKitProvider } from "../EntryKitProvider";
export { AccountButton } from "../AccountButton";
export { useAccountModal } from "../useAccountModal";
export { usePreparedAppAccountClient as useAppAccountClient } from "../usePreparedAppAccountClient";
export { createWagmiConfig, type CreateWagmiConfigOptions } from "../createWagmiConfig";
12 changes: 12 additions & 0 deletions packages/entrykit/src/exports/internal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// TODO: move to external exports once we're ready
export type { EntryKitConfig } from "../config";
export { EntryKitProvider } from "../EntryKitProvider";
export { useEntryKitConfig } from "../EntryKitConfigProvider";
export { AccountButton } from "../AccountButton";
export { useAccountModal } from "../useAccountModal";
export { usePreparedAppAccountClient as useAppAccountClient } from "../usePreparedAppAccountClient";
export { createWagmiConfig, type CreateWagmiConfigOptions } from "../createWagmiConfig";

// And some additional internal things
export * from "../passkey/passkeyWallet";
export * from "../passkey/passkeyConnector";
export * from "../smart-account/toCoinbaseSmartAccount";
export * from "../smart-account/isCoinbaseSmartAccount";
export * from "../wiresaw";
export * from "../getConnectors";
export * from "../getWallets";
14 changes: 14 additions & 0 deletions packages/entrykit/src/getConnectors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { EntryKitConfig } from "./config";
import { WalletList, connectorsForWallets } from "@rainbow-me/rainbowkit";
import { getWallets } from "./getWallets";
import { CreateConnectorFn } from "wagmi";

export function getConnectors({
wallets,
...config
}: EntryKitConfig & { readonly wallets?: WalletList }): CreateConnectorFn[] {
return connectorsForWallets(wallets ?? getWallets(config), {
appName: config.appInfo?.name ?? document.title,
projectId: config.walletConnectProjectId,
});
}
21 changes: 21 additions & 0 deletions packages/entrykit/src/getWallets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { EntryKitConfig } from "./config";
import { WalletList, getDefaultWallets } from "@rainbow-me/rainbowkit";
import { passkeyWallet } from "./passkey/passkeyWallet";

export function getWallets(config: EntryKitConfig): WalletList {
const { wallets: defaultWallets } = getDefaultWallets();
return [
{
groupName: "Recommended",
wallets: [
passkeyWallet({
// TODO: allow any chain ID
chainId: config.chainId,
bundlerTransport: config.bundlerTransport,
paymasterAddress: config.paymasterAddress,
}),
],
},
...defaultWallets,
];
}
6 changes: 3 additions & 3 deletions packages/entrykit/src/useRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export function useRecord<table extends Table>({
select: (data) => ({
...key,
...decodeValueArgs(getSchemaTypes(getValueSchema(table)), {
staticData: data[0],
encodedLengths: data[1],
dynamicData: data[2],
staticData: (data as [Hex, Hex, Hex])[0],
encodedLengths: (data as [Hex, Hex, Hex])[1],
dynamicData: (data as [Hex, Hex, Hex])[2],
}),
}),
},
Expand Down
10 changes: 5 additions & 5 deletions packages/entrykit/src/utils/callWithSignature.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Address } from "abitype";
import { Hex, WalletClient, Transport, Chain, Account, PublicClient } from "viem";
import { Hex, Client } from "viem";
import { writeContract as viem_writeContract } from "viem/actions";
import { getAction } from "viem/utils";
import { AppAccountClient } from "../common";
import { signCall } from "./signCall";
import CallWithSignatureAbi from "@latticexyz/world-modules/out/IUnstable_CallWithSignatureSystem.sol/IUnstable_CallWithSignatureSystem.abi.json";
import { ConnectedClient } from "../common";

// TODO: move this to world package or similar
// TODO: nonce _or_ publicClient?
Expand All @@ -17,9 +17,9 @@ export type CallWithSignatureOptions = {
/**
* This should be bound to the same chain as `chainId` option.
*/
publicClient: PublicClient<Transport, Chain>;
userAccountClient: WalletClient<Transport, Chain, Account>;
appAccountClient: AppAccountClient;
publicClient: Client;
userAccountClient: ConnectedClient;
appAccountClient: ConnectedClient;
nonce?: bigint | null;
};

Expand Down
16 changes: 11 additions & 5 deletions packages/entrykit/src/utils/signCall.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { Account, Address, Chain, Client, Hex, PublicClient, Transport, toHex } from "viem";
import { Address, Client, Hex, toHex } from "viem";
import { signTypedData } from "viem/actions";
import { callWithSignatureTypes } from "@latticexyz/world/internal";
import { getRecord } from "./getRecord";
import modulesConfig from "@latticexyz/world-modules/internal/mud.config";
import { hexToResource } from "@latticexyz/common";
import { getAction } from "viem/utils";
import { ConnectedClient } from "../common";

// TODO: move this to world package or similar
// TODO: nonce _or_ publicClient?

export type SignCallOptions = {
userAccountClient: Client<Transport, Chain, Account>;
userAccountClient: ConnectedClient;
chainId: number;
worldAddress: Address;
systemId: Hex;
Expand All @@ -18,7 +20,7 @@ export type SignCallOptions = {
/**
* This should be bound to the same chain as `chainId` option.
*/
publicClient?: PublicClient<Transport, Chain>;
publicClient?: Client;
};

export async function signCall({
Expand All @@ -35,7 +37,7 @@ export async function signCall({
(publicClient
? (
await getRecord(publicClient, {
storeAddress: worldAddress,
address: worldAddress,
table: modulesConfig.tables.CallWithSignatureNonces,
key: { signer: userAccountClient.account.address },
blockTag: "pending",
Expand All @@ -45,7 +47,11 @@ export async function signCall({

const { namespace: systemNamespace, name: systemName } = hexToResource(systemId);

return await signTypedData(userAccountClient, {
return await getAction(
userAccountClient,
signTypedData,
"signTypedData",
)({
account: userAccountClient.account,
domain: {
verifyingContract: worldAddress,
Expand Down
7 changes: 3 additions & 4 deletions packages/entrykit/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineConfig } from "tsup";
// import packageJson from "./package.json";

export default defineConfig({
outDir: "dist/tsup",
Expand All @@ -15,8 +16,6 @@ export default defineConfig({
// Because we're injecting CSS via shadow DOM, we'll disable style injection and load CSS as a base64 string.
// TODO: figure out how to do this conditionally for only specific imports?
injectStyle: false,
loader: {
".css": "text",
},
external: ["react", "react-dom", "wagmi", "viem"],
loader: { ".css": "text" },
// external: Object.keys(packageJson.dependencies),
});
Loading

0 comments on commit 37b7650

Please sign in to comment.