Skip to content

Commit

Permalink
Make backwards compat with 0.3.40
Browse files Browse the repository at this point in the history
  • Loading branch information
broody committed Aug 20, 2024
1 parent 9e69d51 commit f1abf2a
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ const cartridge = new CartridgeConnector({
],
url:
!process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL ||
process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL.split(".")[0] ===
process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL.split(".")[0] ===
"cartridge-starknet-react-next"
? process.env.XFRAME_URL
: "https://" +
(process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL ?? "").replace(
"cartridge-starknet-react-next",
"keychain",
),
(process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL ?? "").replace(
"cartridge-starknet-react-next",
"keychain",
),
rpc: process.env.NEXT_PUBLIC_RPC_SEPOLIA,
paymaster: {
caller: shortString.encodeShortString("ANY_CALLER"),
Expand Down
18 changes: 8 additions & 10 deletions packages/controller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { KEYCHAIN_URL, RPC_SEPOLIA } from "./constants";

class Controller {
private url: URL;
private policies?: Policy[];
private policies: Policy[];
private paymaster?: PaymasterOptions;
private connection?: Connection<Keychain>;
private modal?: Modal;
Expand All @@ -51,13 +51,11 @@ class Controller {
this.url = new URL(url || KEYCHAIN_URL);
this.rpc = new URL(rpc || RPC_SEPOLIA);
this.paymaster = paymaster;

if (policies?.length) {
this.policies = policies.map((policy) => ({
this.policies =
policies?.map((policy) => ({
...policy,
target: addAddressPadding(policy.target),
}));
}
})) || [];

this.setTheme(theme, config?.presets);
if (colorMode) {
Expand Down Expand Up @@ -189,10 +187,10 @@ class Controller {
this.modal.open();

try {
let response = await this.keychain.connect({
rpcUrl: this.rpc.toString(),
policies: this.policies,
});
let response = await this.keychain.connect(
this.policies,
this.rpc.toString(),
);
if (response.code !== ResponseCodes.SUCCESS) {
throw new Error(response.message);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ export type ProbeReply = {

export interface Keychain {
probe(rpcUrl?: string): Promise<ProbeReply | ConnectError>;
connect(args: {
rpcUrl: string;
policies?: Policy[];
}): Promise<ConnectReply | ConnectError>;
connect(
policies: Policy[],
rpcUrl: string,
): Promise<ConnectReply | ConnectError>;
disconnect(): void;

reset(): void;
Expand Down
2 changes: 1 addition & 1 deletion packages/keychain/src/components/connect/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function Form({
credentialId,
});

if (mode === LoginMode.Controller && policies.length > 0) {
if (mode === LoginMode.Controller && policies?.length > 0) {
await controller.approve(origin, expiresAt, policies);
} else {
await doLogin(usernameField.value, credentialId);
Expand Down
4 changes: 2 additions & 2 deletions packages/keychain/src/components/layout/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function Footer({
const isExpandable = useMemo(
() =>
!!origin &&
!!policies?.length &&
!!policies.length &&
variant === "connect" &&
!isSignup &&
!hideTxSummary,
Expand Down Expand Up @@ -100,7 +100,7 @@ export function Footer({
onClick={footer.onToggle}
_hover={{ cursor: "pointer" }}
>
{!hideTxSummary && !!policies?.length && (
{!hideTxSummary && !!policies.length && (
<TransactionSummary
isSlot={isSlot}
createSession={createSession}
Expand Down
2 changes: 1 addition & 1 deletion packages/keychain/src/hooks/connection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type ConnectionContextValue = {
rpcUrl: string;
chainId: string;
chainName: string;
policies?: Policy[];
policies: Policy[];
prefunds: Prefund[];
hasPrefundRequest: boolean;
error: Error;
Expand Down
13 changes: 2 additions & 11 deletions packages/keychain/src/utils/connection/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,10 @@ export function connectFactory({
setContext: (context: ConnectionCtx) => void;
}) {
return (origin: string) =>
({
rpcUrl,
policies,
}: {
rpcUrl: string;
policies?: Policy[];
}): Promise<ConnectReply> => {
(policies: Policy[], rpcUrl: string): Promise<ConnectReply> => {
setOrigin(origin);
setRpcUrl(rpcUrl);

if (policies?.length) {
setPolicies(policies);
}
setPolicies(policies);

return new Promise((resolve, reject) => {
setContext({
Expand Down
2 changes: 1 addition & 1 deletion packages/keychain/src/utils/connection/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type ConnectionCtx =
export type ConnectCtx = {
origin: string;
type: "connect";
policies?: Policy[];
policies: Policy[];
resolve: (res: ConnectReply | ConnectError) => void;
reject: (reason?: unknown) => void;
};
Expand Down

0 comments on commit f1abf2a

Please sign in to comment.