From 46f734ce6d6915d713e8c69ffb77fb9dc13506dc Mon Sep 17 00:00:00 2001 From: RedBeardEth <90423049+RedBeardEth@users.noreply.github.com> Date: Thu, 5 Dec 2024 22:41:11 +1100 Subject: [PATCH] update cartridge controller connector --- apps/nextjs/package.json | 3 +- .../wallet/StarknetLoginButton.tsx | 86 ++++++++++++------- apps/nextjs/src/providers/Web3Providers.tsx | 15 ++-- pnpm-lock.yaml | 64 +++++++------- 4 files changed, 95 insertions(+), 73 deletions(-) diff --git a/apps/nextjs/package.json b/apps/nextjs/package.json index 3bd1785d..c966a0c3 100644 --- a/apps/nextjs/package.json +++ b/apps/nextjs/package.json @@ -16,7 +16,8 @@ "dependencies": { "@ark-project/react": "1.1.2", "@avnu/avnu-sdk": "^2.1.1", - "@cartridge/connector": "^0.4.0", + "@cartridge/connector": "^0.5.1", + "@cartridge/controller": "^0.5.1", "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", "@keystatic/core": "^0.5.36", diff --git a/apps/nextjs/src/app/_components/wallet/StarknetLoginButton.tsx b/apps/nextjs/src/app/_components/wallet/StarknetLoginButton.tsx index c0c5a35b..8c7e02f2 100644 --- a/apps/nextjs/src/app/_components/wallet/StarknetLoginButton.tsx +++ b/apps/nextjs/src/app/_components/wallet/StarknetLoginButton.tsx @@ -1,15 +1,15 @@ "use client"; +import type ControllerConnector from "@cartridge/connector/controller"; +import type { buttonVariants } from "@realms-world/ui/components/ui/button"; import type { VariantProps } from "class-variance-authority"; import React from "react"; import StarknetLogo from "@/icons/starknet.svg"; import { useUIStore } from "@/providers/UIStoreProvider"; import { shortenHex } from "@/utils/utils"; -import { useAccount } from "@starknet-react/core"; - -import type { buttonVariants } from "@realms-world/ui/components/ui/button"; import { Button } from "@realms-world/ui/components/ui/button"; -import { Loader } from "lucide-react"; +import { useAccount } from "@starknet-react/core"; +import { Loader, User } from "lucide-react"; export const StarknetLoginButton = ({ openAccount = false, @@ -17,46 +17,68 @@ export const StarknetLoginButton = ({ textClass, buttonClass, children, - newTransactionCount + newTransactionCount, }: { openAccount?: boolean; variant?: VariantProps["variant"]; textClass?: string; buttonClass?: string; - children?: React.ReactNode, - newTransactionCount?: number + children?: React.ReactNode; + newTransactionCount?: number; }) => { - const { address, isConnected, isConnecting } = useAccount(); + const { address, isConnected, isConnecting, connector } = useAccount(); const { toggleAccount, toggleStarknetLogin } = useUIStore((state) => state); const onConnectClick = () => { - return !isConnected - ? toggleStarknetLogin() - : openAccount && toggleAccount(); + if (!isConnected) { + return toggleStarknetLogin(); + } + + if (connector?.id === "controller") { + // eslint-disable-next-line @typescript-eslint/no-floating-promises + (connector as unknown as ControllerConnector).controller.openProfile( + "inventory", + ); + } else if (openAccount) { + toggleAccount(); + } }; return ( - + {isConnected && newTransactionCount && newTransactionCount > 0 ? ( + + {newTransactionCount} + + ) : null} + + {connector?.id === "controller" ? ( + + ) : null} + ); }; diff --git a/apps/nextjs/src/providers/Web3Providers.tsx b/apps/nextjs/src/providers/Web3Providers.tsx index a30d9900..391ebdc4 100644 --- a/apps/nextjs/src/providers/Web3Providers.tsx +++ b/apps/nextjs/src/providers/Web3Providers.tsx @@ -1,7 +1,7 @@ "use client"; import type { ReactElement } from "react"; -import { env } from "env"; +import ControllerConnector from "@cartridge/connector/controller"; import { getDefaultConfig, RainbowKitProvider } from "@rainbow-me/rainbowkit"; import { darkTheme, ReservoirKitProvider } from "@reservoir0x/reservoir-kit-ui"; import { @@ -16,17 +16,18 @@ import { publicProvider as starkPublicProvider, //useInjectedConnectors, } from "@starknet-react/core"; +import { env } from "env"; +import { constants } from "starknet"; import { ArgentMobileConnector, isInArgentMobileAppBrowser, } from "starknetkit/argentMobile"; -import CartridgeConnector from "@cartridge/connector"; import { InjectedConnector } from "starknetkit/injected"; import { WebWalletConnector } from "starknetkit/webwallet"; import { http, WagmiProvider } from "wagmi"; import { mainnet, sepolia } from "wagmi/chains"; + import { TransferLogProvider } from "./TransferLogProvider"; -import { constants } from "starknet"; const starkProvider = env.NEXT_PUBLIC_BLAST_API ? blastProvider({ @@ -49,9 +50,11 @@ const starkConnectors = isInArgentMobileAppBrowser() }), ] : [ - /*new CartridgeConnector({ - rpc: "https://api.cartridge.gg/x/starknet/mainnet", - }),*/ + new ControllerConnector({ + rpc: + "https://api.cartridge.gg/x/starknet/" + + (isTestnet ? "sepolia" : "mainnet"), + }), new InjectedConnector({ options: { id: "braavos", name: "Braavos" } }), new InjectedConnector({ options: { id: "argentX", name: "Argent X" } }), ArgentMobileConnector.init({ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 47d6aec7..5769ca58 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -299,8 +299,11 @@ importers: specifier: ^2.1.1 version: 2.1.1(ethers@6.13.4(bufferutil@4.0.8)(utf-8-validate@5.0.10))(qs@6.13.0)(starknet@6.11.0(encoding@0.1.13)) '@cartridge/connector': - specifier: ^0.4.0 - version: 0.4.0(encoding@0.1.13)(get-starknet-core@3.3.4(starknet@6.11.0(encoding@0.1.13)))(react@19.0.0-rc-bf7e210c-20241017) + specifier: ^0.5.1 + version: 0.5.1(bufferutil@4.0.8)(encoding@0.1.13)(get-starknet-core@3.3.4(starknet@6.11.0(encoding@0.1.13)))(react@19.0.0-rc-bf7e210c-20241017)(typescript@5.6.3)(utf-8-validate@5.0.10) + '@cartridge/controller': + specifier: ^0.5.1 + version: 0.5.1(encoding@0.1.13) '@emotion/react': specifier: ^11.11.4 version: 11.13.3(@types/react@18.3.11)(react@19.0.0-rc-bf7e210c-20241017) @@ -2159,14 +2162,14 @@ packages: '@braintree/sanitize-url@6.0.4': resolution: {integrity: sha512-s3jaWicZd0pkP0jf5ysyHUI/RE7MHos6qlToFcGWXVp+ykHOy77OUMrfbgJ9it2C5bow7OIQwYYaHjk9XlBQ2A==} - '@cartridge/account-wasm@0.4.0': - resolution: {integrity: sha512-slkZhkgAPMhh2sXa2GNeidighPjjjiTA4hpi5yqEJIbMV7SnoHZGBqBZC9oDiDWGnCGVeClwF5+YPdkxZMGhYA==} + '@cartridge/account-wasm@0.5.1': + resolution: {integrity: sha512-m7XGkiZvh49s7SIvWHpgu7xNcgzTTn3XPewd2V+AWXTZzkj/JtRDSsUK0Rywg0qLTh3SEimviSiSpX6qm0XCgA==} - '@cartridge/connector@0.4.0': - resolution: {integrity: sha512-Yv4phu5LODD2RP/1BiVKmBvCvfCiZDYAqw80CEyYKfduR0oh3qsv8BCTypQULeuDP+Ufm6mVihw5X+/ATT2LoQ==} + '@cartridge/connector@0.5.1': + resolution: {integrity: sha512-50wVk+EkbSIArGEzb+cylCE68vU5lx7IdFoWDPqMueZ9AWxODuVEo4TubqbUAt2vqGO+L2fhEnknlmOFGdZE9A==} - '@cartridge/controller@0.4.0': - resolution: {integrity: sha512-2ZhKE9FBO8lN4QeS0bfVURc8XmJ7DVnpae7WZHnkc9DVCjAPZdliFp/Zgzdq7OsCu64zIAgwe7EPPdBHAmvI4w==} + '@cartridge/controller@0.5.1': + resolution: {integrity: sha512-9yK+TOu5cYVyM3jEiqtDWVqf/TsBPzIJl104lJRNRMsVxfVBunpI+FPSsXB1X25wxqR68zefwfL2VEe2xYdErw==} '@cartridge/penpal@6.2.3': resolution: {integrity: sha512-K8h9VqBfFPXcAFQNnvgBnejF/dp7249pS4jXu3NhNYR6JqMQxtcrDqfnPmJvbF4ECEBs+8Z2UiwlRQiKt5nNsg==} @@ -19173,23 +19176,27 @@ snapshots: '@braintree/sanitize-url@6.0.4': {} - '@cartridge/account-wasm@0.4.0': {} + '@cartridge/account-wasm@0.5.1': {} - '@cartridge/connector@0.4.0(encoding@0.1.13)(get-starknet-core@3.3.4(starknet@6.11.0(encoding@0.1.13)))(react@19.0.0-rc-bf7e210c-20241017)': + '@cartridge/connector@0.5.1(bufferutil@4.0.8)(encoding@0.1.13)(get-starknet-core@3.3.4(starknet@6.11.0(encoding@0.1.13)))(react@19.0.0-rc-bf7e210c-20241017)(typescript@5.6.3)(utf-8-validate@5.0.10)': dependencies: - '@cartridge/controller': 0.4.0(encoding@0.1.13) - '@starknet-react/core': 2.9.0(get-starknet-core@3.3.4(starknet@6.11.0(encoding@0.1.13)))(react@19.0.0-rc-bf7e210c-20241017)(starknet@6.11.0(encoding@0.1.13)) - '@telegram-apps/sdk': 2.5.0 + '@cartridge/controller': 0.5.1(encoding@0.1.13) + '@starknet-react/core': 3.0.3(bufferutil@4.0.8)(get-starknet-core@3.3.4(starknet@6.11.0(encoding@0.1.13)))(react@19.0.0-rc-bf7e210c-20241017)(starknet@6.11.0(encoding@0.1.13))(typescript@5.6.3)(utf-8-validate@5.0.10) starknet: 6.11.0(encoding@0.1.13) transitivePeerDependencies: + - bufferutil - encoding - get-starknet-core - react + - typescript + - utf-8-validate - '@cartridge/controller@0.4.0(encoding@0.1.13)': + '@cartridge/controller@0.5.1(encoding@0.1.13)': dependencies: - '@cartridge/account-wasm': 0.4.0 + '@cartridge/account-wasm': 0.5.1 '@cartridge/penpal': 6.2.3 + '@starknet-io/types-js': 0.7.7 + '@telegram-apps/sdk': 2.5.0 base64url: 3.0.1 cbor-x: 1.6.0 fast-deep-equal: 3.1.3 @@ -25106,17 +25113,6 @@ snapshots: starknet: 6.11.0(encoding@0.1.13) zod: 3.23.8 - '@starknet-react/core@2.9.0(get-starknet-core@3.3.4(starknet@6.11.0(encoding@0.1.13)))(react@19.0.0-rc-bf7e210c-20241017)(starknet@6.11.0(encoding@0.1.13))': - dependencies: - '@starknet-react/chains': 0.1.7 - '@tanstack/react-query': 5.59.15(react@19.0.0-rc-bf7e210c-20241017) - eventemitter3: 5.0.1 - get-starknet-core: 3.3.4(starknet@6.11.0(encoding@0.1.13)) - immutable: 4.3.7 - react: 19.0.0-rc-bf7e210c-20241017 - starknet: 6.11.0(encoding@0.1.13) - zod: 3.23.8 - '@starknet-react/core@3.0.3(bufferutil@4.0.8)(get-starknet-core@3.3.4(starknet@6.11.0(encoding@0.1.13)))(react@18.3.1)(starknet@6.11.0(encoding@0.1.13))(typescript@5.6.3)(utf-8-validate@5.0.10)': dependencies: '@starknet-io/types-js': 0.7.7 @@ -30423,7 +30419,7 @@ snapshots: eslint: 6.8.0 get-stdin: 6.0.0 - eslint-config-react-app@5.2.1(@typescript-eslint/eslint-plugin@2.34.0(@typescript-eslint/parser@2.34.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(@typescript-eslint/parser@2.34.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(babel-eslint@10.1.0(eslint@9.12.0(jiti@2.3.3)))(eslint-plugin-flowtype@3.13.0(eslint@9.12.0(jiti@2.3.3)))(eslint-plugin-import@2.31.0(@typescript-eslint/parser@2.34.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint@9.12.0(jiti@2.3.3)))(eslint-plugin-jsx-a11y@6.10.0(eslint@9.12.0(jiti@2.3.3)))(eslint-plugin-react-hooks@2.5.1(eslint@6.8.0))(eslint-plugin-react@7.37.1(eslint@9.12.0(jiti@2.3.3)))(eslint@6.8.0)(typescript@3.9.10): + eslint-config-react-app@5.2.1(@typescript-eslint/eslint-plugin@2.34.0(@typescript-eslint/parser@2.34.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(@typescript-eslint/parser@2.34.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(babel-eslint@10.1.0(eslint@9.12.0(jiti@2.3.3)))(eslint-plugin-flowtype@3.13.0(eslint@9.12.0(jiti@2.3.3)))(eslint-plugin-import@2.31.0(@typescript-eslint/parser@2.34.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint@9.12.0(jiti@2.3.3)))(eslint-plugin-jsx-a11y@6.10.0(eslint@6.8.0))(eslint-plugin-react-hooks@2.5.1(eslint@9.12.0(jiti@2.3.3)))(eslint-plugin-react@7.37.1(eslint@9.12.0(jiti@2.3.3)))(eslint@6.8.0)(typescript@3.9.10): dependencies: '@typescript-eslint/eslint-plugin': 2.34.0(@typescript-eslint/parser@2.34.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint@6.8.0)(typescript@3.9.10) '@typescript-eslint/parser': 2.34.0(eslint@6.8.0)(typescript@3.9.10) @@ -30457,7 +30453,7 @@ snapshots: debug: 4.3.7 enhanced-resolve: 5.17.1 eslint: 9.12.0(jiti@2.3.3) - eslint-module-utils: 2.12.0(@typescript-eslint/parser@7.18.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@7.18.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0(@typescript-eslint/parser@7.18.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint@9.12.0(jiti@2.3.3)))(eslint@9.12.0(jiti@2.3.3)))(eslint@9.12.0(jiti@2.3.3)) + eslint-module-utils: 2.12.0(@typescript-eslint/parser@7.18.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@9.12.0(jiti@2.3.3)) fast-glob: 3.3.2 get-tsconfig: 4.8.1 is-bun-module: 1.2.1 @@ -30480,7 +30476,7 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-module-utils@2.12.0(@typescript-eslint/parser@7.18.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@7.18.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0(@typescript-eslint/parser@7.18.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint@9.12.0(jiti@2.3.3)))(eslint@9.12.0(jiti@2.3.3)))(eslint@9.12.0(jiti@2.3.3)): + eslint-module-utils@2.12.0(@typescript-eslint/parser@7.18.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@9.12.0(jiti@2.3.3)): dependencies: debug: 3.2.7 optionalDependencies: @@ -30546,7 +30542,7 @@ snapshots: doctrine: 2.1.0 eslint: 9.12.0(jiti@2.3.3) eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.12.0(@typescript-eslint/parser@7.18.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@7.18.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.31.0(@typescript-eslint/parser@7.18.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint@9.12.0(jiti@2.3.3)))(eslint@9.12.0(jiti@2.3.3)))(eslint@9.12.0(jiti@2.3.3)) + eslint-module-utils: 2.12.0(@typescript-eslint/parser@7.18.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@9.12.0(jiti@2.3.3)) hasown: 2.0.2 is-core-module: 2.15.1 is-glob: 4.0.3 @@ -34599,7 +34595,7 @@ snapshots: metro-source-map@0.80.12: dependencies: '@babel/traverse': 7.25.7 - '@babel/types': 7.25.8 + '@babel/types': 7.26.0 flow-enums-runtime: 0.0.6 invariant: 2.2.4 metro-symbolicate: 0.80.12 @@ -34638,7 +34634,7 @@ snapshots: '@babel/core': 7.25.8 '@babel/generator': 7.25.7 '@babel/parser': 7.25.8 - '@babel/types': 7.25.8 + '@babel/types': 7.26.0 flow-enums-runtime: 0.0.6 metro: 0.80.12(bufferutil@4.0.8)(utf-8-validate@5.0.10) metro-babel-transformer: 0.80.12 @@ -34661,7 +34657,7 @@ snapshots: '@babel/parser': 7.25.8 '@babel/template': 7.25.7 '@babel/traverse': 7.25.7 - '@babel/types': 7.25.8 + '@babel/types': 7.26.0 accepts: 1.3.8 chalk: 4.1.2 ci-info: 2.0.0 @@ -38735,7 +38731,7 @@ snapshots: enquirer: 2.4.1 eslint: 6.8.0 eslint-config-prettier: 6.15.0(eslint@6.8.0) - eslint-config-react-app: 5.2.1(@typescript-eslint/eslint-plugin@2.34.0(@typescript-eslint/parser@2.34.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(@typescript-eslint/parser@2.34.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(babel-eslint@10.1.0(eslint@9.12.0(jiti@2.3.3)))(eslint-plugin-flowtype@3.13.0(eslint@9.12.0(jiti@2.3.3)))(eslint-plugin-import@2.31.0(@typescript-eslint/parser@2.34.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint@9.12.0(jiti@2.3.3)))(eslint-plugin-jsx-a11y@6.10.0(eslint@9.12.0(jiti@2.3.3)))(eslint-plugin-react-hooks@2.5.1(eslint@6.8.0))(eslint-plugin-react@7.37.1(eslint@9.12.0(jiti@2.3.3)))(eslint@6.8.0)(typescript@3.9.10) + eslint-config-react-app: 5.2.1(@typescript-eslint/eslint-plugin@2.34.0(@typescript-eslint/parser@2.34.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(@typescript-eslint/parser@2.34.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(babel-eslint@10.1.0(eslint@9.12.0(jiti@2.3.3)))(eslint-plugin-flowtype@3.13.0(eslint@9.12.0(jiti@2.3.3)))(eslint-plugin-import@2.31.0(@typescript-eslint/parser@2.34.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint@9.12.0(jiti@2.3.3)))(eslint-plugin-jsx-a11y@6.10.0(eslint@6.8.0))(eslint-plugin-react-hooks@2.5.1(eslint@9.12.0(jiti@2.3.3)))(eslint-plugin-react@7.37.1(eslint@9.12.0(jiti@2.3.3)))(eslint@6.8.0)(typescript@3.9.10) eslint-plugin-flowtype: 3.13.0(eslint@6.8.0) eslint-plugin-import: 2.31.0(@typescript-eslint/parser@2.34.0(eslint@9.12.0(jiti@2.3.3))(typescript@5.6.3))(eslint@6.8.0) eslint-plugin-jsx-a11y: 6.10.0(eslint@6.8.0)