diff --git a/packages/keychain/src/hooks/connection.ts b/packages/keychain/src/hooks/connection.ts index 7b521508d..12514384c 100644 --- a/packages/keychain/src/hooks/connection.ts +++ b/packages/keychain/src/hooks/connection.ts @@ -84,10 +84,10 @@ export function useConnectionValue() { }, [context, parent]); const setController = useCallback((controller?: Controller) => { - if (controller && controller.cartridge && origin) { - posthog.identify(controller.cartridge.username(), { + if (controller && origin) { + posthog.identify(controller.username(), { address: controller.address, - class: controller.cartridge.classHash, + class: controller.classHash(), chainId: controller.chainId, appId: origin, }); diff --git a/packages/keychain/src/hooks/deploy.ts b/packages/keychain/src/hooks/deploy.ts index 28e666204..d05a55d2f 100644 --- a/packages/keychain/src/hooks/deploy.ts +++ b/packages/keychain/src/hooks/deploy.ts @@ -1,11 +1,10 @@ import { useCallback, useState } from "react"; -import { num } from "starknet"; import { useConnection } from "./connection"; type TransactionHash = string; interface DeployInterface { - deploySelf: (maxFee: string) => Promise; + deploySelf: (maxFee: string) => Promise; isDeploying: boolean; } @@ -18,9 +17,7 @@ export const useDeploy = (): DeployInterface => { if (!controller) return; try { setIsDeploying(true); - const { transaction_hash } = await controller.cartridge.deploySelf( - num.toHex(maxFee), - ); + const { transaction_hash } = await controller.selfDeploy(maxFee); return transaction_hash; } catch (e) { diff --git a/packages/keychain/src/hooks/upgrade.ts b/packages/keychain/src/hooks/upgrade.ts index aeb91ad55..0ad094071 100644 --- a/packages/keychain/src/hooks/upgrade.ts +++ b/packages/keychain/src/hooks/upgrade.ts @@ -93,7 +93,7 @@ export const useUpgrade = (controller?: Controller): UpgradeInterface => { const current = CONTROLLER_VERSIONS.find( (v) => addAddressPadding(v.hash) === - addAddressPadding(controller.cartridge.classHash()), + addAddressPadding(controller.classHash()), ); setCurrent(current); setAvailable(current?.version !== LATEST_CONTROLLER.version); @@ -110,7 +110,7 @@ export const useUpgrade = (controller?: Controller): UpgradeInterface => { return []; } - return [controller.cartridge.upgrade(LATEST_CONTROLLER.hash)]; + return [controller.upgrade(LATEST_CONTROLLER.hash)]; }, [controller]); const onUpgrade = useCallback(async () => { diff --git a/packages/keychain/src/pages/session.tsx b/packages/keychain/src/pages/session.tsx index 23e37e158..630a6e194 100644 --- a/packages/keychain/src/pages/session.tsx +++ b/packages/keychain/src/pages/session.tsx @@ -107,7 +107,7 @@ export default function Session() { onCallback({ username: controller.username(), address: controller.address, - ownerGuid: controller.cartridge.ownerGuid(), + ownerGuid: controller.ownerGuid(), transactionHash: transaction_hash, expiresAt: String(SESSION_EXPIRATION), }); @@ -129,7 +129,7 @@ export default function Session() { onCallback({ username: controller.username(), address: controller.address, - ownerGuid: controller.cartridge.ownerGuid(), + ownerGuid: controller.ownerGuid(), alreadyRegistered: true, expiresAt: String(SESSION_EXPIRATION), }); diff --git a/packages/keychain/src/utils/connection/execute.ts b/packages/keychain/src/utils/connection/execute.ts index f524d7700..fd34ec065 100644 --- a/packages/keychain/src/utils/connection/execute.ts +++ b/packages/keychain/src/utils/connection/execute.ts @@ -124,7 +124,7 @@ export function execute({ } try { - let estimate = await account.cartridge.estimateInvokeFee(calls); + let estimate = await account.estimateInvokeFee(calls); const maxFee = num.toHex( num.addPercent(estimate.overall_fee, ESTIMATE_FEE_PERCENTAGE), ); diff --git a/packages/keychain/src/utils/controller.ts b/packages/keychain/src/utils/controller.ts index 77b5cf747..56e9f609e 100644 --- a/packages/keychain/src/utils/controller.ts +++ b/packages/keychain/src/utils/controller.ts @@ -26,9 +26,10 @@ import { SessionMetadata, } from "@cartridge/account-wasm/controller"; import { SessionPolicies } from "@cartridge/presets"; +import { DeployedAccountTransaction } from "@starknet-io/types-js"; export default class Controller extends Account { - cartridge: CartridgeAccount; + private cartridge: CartridgeAccount; constructor({ appId, @@ -72,6 +73,14 @@ export default class Controller extends Account { return this.cartridge.username(); } + classHash() { + return this.cartridge.classHash(); + } + + ownerGuid() { + return this.cartridge.ownerGuid(); + } + rpcUrl() { return this.cartridge.rpcUrl(); } @@ -260,6 +269,15 @@ export default class Controller extends Account { } } + async selfDeploy(maxFee: BigNumberish): Promise { + const release = await mutex.obtain(); + try { + return await this.cartridge.deploySelf(num.toHex(maxFee)); + } finally { + release(); + } + } + async delegateAccount(): Promise { const release = await mutex.obtain(); try {