Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backwards compat #604

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading