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 c942610
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 19 deletions.
12 changes: 5 additions & 7 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 @@ -190,8 +188,8 @@ class Controller {

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

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

Expand Down
3 changes: 2 additions & 1 deletion packages/keychain/src/components/connect/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function Form({
const [isValidating, setIsValidating] = useState(false);

const onSubmit = useCallback(async () => {
console.log(policies);
setIsValidating(true);
const error = await validateUsernameFor("login")(usernameField.value);
if (error) {
Expand Down Expand Up @@ -81,7 +82,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
7 changes: 2 additions & 5 deletions packages/keychain/src/utils/connection/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ export function connectFactory({
policies,
}: {
rpcUrl: string;
policies?: Policy[];
policies: Policy[];
}): 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 c942610

Please sign in to comment.