Skip to content

Commit

Permalink
Add back deployment required ui on execute (#281)
Browse files Browse the repository at this point in the history
* Add back deployment required ui on execute

* hardcode url
  • Loading branch information
broody authored May 15, 2024
1 parent 964df54 commit b912a0f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const url =
"keychain",
)
: process.env.XFRAME_URL;

const connectors = [
new CartridgeConnector(
[
Expand Down
7 changes: 1 addition & 6 deletions packages/keychain/src/components/DeploymentRequired.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,18 @@ export function DeploymentRequired({
const id = setInterval(async () => {
if (account.status !== Status.DEPLOYING) clearInterval(id);
setStatus(account.status);
console.log("deployment/registration required");
await account.sync();
}, 2000);

return () => clearInterval(id);
}, [account, setStatus]);

if (status === Status.DEPLOYING) {
const title =
status === Status.DEPLOYING
? "Deploying your account"
: "Creating a session";
return (
<Container chainId={chainId} onLogout={onLogout}>
<PortalBanner
Icon={Loading}
title={title}
title={"Deploying your account"}
description="This may take a second"
/>

Expand Down
34 changes: 27 additions & 7 deletions packages/keychain/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ import { revoke, session, sessions } from "../methods/sessions";
import { normalize, validate } from "../methods";
import {
Connect,
DeploymentRequired,
Execute,
Login,
Logout,
SignMessage,
Signup,
} from "components";
import { useController } from "hooks/controller";
import { Status } from "utils/account";

type Context = Connect | Logout | Execute | SignMessage;

Expand Down Expand Up @@ -148,8 +150,14 @@ const Index: NextPage = () => {
} as Execute);
});
}

const account = controller.account(cId);
if (account.status === Status.DEPLOYING) {
return Promise.resolve({
code: ResponseCodes.NOT_ALLOWED,
message: "Account is deploying.",
});
}

const calls = Array.isArray(transactions)
? transactions
: [transactions];
Expand Down Expand Up @@ -384,19 +392,31 @@ const Index: NextPage = () => {
const ctx = context as Execute;

return (
<Execute
{...ctx}
chainId={ctx.transactionsDetail?.chainId ?? chainId}
<DeploymentRequired
chainId={chainId}
controller={controller}
onExecute={(res: ExecuteReply) => ctx.resolve(res)}
onCancel={() =>
onClose={() =>
ctx.resolve({
code: ResponseCodes.CANCELED,
message: "Canceled",
})
}
onLogout={() => onLogout(ctx)}
/>
>
<Execute
{...ctx}
chainId={chainId}
controller={controller}
onExecute={(res: ExecuteReply) => ctx.resolve(res)}
onCancel={() =>
ctx.resolve({
code: ResponseCodes.CANCELED,
message: "Canceled",
})
}
onLogout={() => onLogout(ctx)}
/>
</DeploymentRequired>
);
}

Expand Down
9 changes: 5 additions & 4 deletions packages/keychain/src/utils/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@ class Account extends BaseAccount {
//transactionsDetail.maxFee = num.toHex(transactionsDetail.maxFee);
transactionsDetail.maxFee = "0x38D7EA4C68000"; // 0.001 eth

const res = await this.cartridge.execute(
calls as Array<Call>,
transactionsDetail,
);
const res = await this.cartridge
.execute(calls as Array<Call>, transactionsDetail)
.catch((e) => {
throw new Error("Execute error: " + e.message);
});

Storage.update(this.selector, {
nonce: (BigInt(transactionsDetail.nonce) + 1n).toString(),
Expand Down

0 comments on commit b912a0f

Please sign in to comment.