Skip to content

Commit

Permalink
Merge pull request #30 from upbond/fast-login
Browse files Browse the repository at this point in the history
  • Loading branch information
ardiyu07 authored Jan 22, 2024
2 parents 181885a + d5fe26c commit 7604a52
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/consent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export default class Consent {
enabled: boolean;
};

flowConfig: string;

publicKey: string;

isLoggedIn: boolean;
Expand Down Expand Up @@ -56,6 +58,7 @@ export default class Consent {
enabled: false,
scopes: scope,
};
this.flowConfig = "normal";
this.publicKey = publicKey;
this.communicationMux = consentStream;
this.provider = provider;
Expand Down
46 changes: 46 additions & 0 deletions src/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ class Upbond {
};
};

flowConfig: string;

private loginHint = "";

private useWalletConnect: boolean;
Expand Down Expand Up @@ -226,6 +228,7 @@ class Upbond {
origin: "",
},
},
flowConfig = "normal",
}: IUpbondEmbedParams = {}): Promise<void> {
// Send WARNING for deprecated buildEnvs
// Give message to use others instead
Expand Down Expand Up @@ -305,6 +308,7 @@ class Upbond {
log.setDefaultLevel(logLevel);

this.consentConfiguration = consentConfiguration;
this.flowConfig = flowConfig;

const upbondIframeUrl = new URL(torusUrl);
if (upbondIframeUrl.pathname.endsWith("/")) upbondIframeUrl.pathname += "popup";
Expand Down Expand Up @@ -373,6 +377,7 @@ class Upbond {
redirectUrl: dappRedirectUri,
},
consentConfiguration: this.consentConfiguration,
flowConfig,
},
});
};
Expand Down Expand Up @@ -642,6 +647,47 @@ class Upbond {
});
}

getTkey(message?: string) {
return new Promise((resolve, reject) => {
if (this.isLoggedIn) {
const tkeyAccessStream = this.communicationMux.getStream("tkey_access") as Substream;
tkeyAccessStream.write({ name: "tkey_access_request" });
const tkeyAccessHandler = (chunk) => {
const {
name,
data: { approved, payload, rejected, newRequest },
} = chunk;
if (name === "tkey_access_response") {
if (approved) {
resolve(payload);
} else if (rejected) {
reject(new Error("User rejected the request"));
} else if (newRequest) {
const tkeyInfoStream = this.communicationMux.getStream("tkey") as Substream;
const tkeyInfoHandler = (handlerChunk) => {
if (handlerChunk.name === "tkey_response") {
if (handlerChunk.data.approved) {
resolve(handlerChunk.data.payload);
} else {
reject(new Error("User rejected the request"));
}
}
};
handleStream(tkeyInfoStream, "data", tkeyInfoHandler);
const preopenInstanceId = getPreopenInstanceId();
this._handleWindow(preopenInstanceId, {
target: "_blank",
features: FEATURES_PROVIDER_CHANGE_WINDOW,
});
tkeyInfoStream.write({ name: "tkey_request", data: { message, preopenInstanceId } });
}
}
};
handleStream(tkeyAccessStream, "data", tkeyAccessHandler);
} else reject(new Error("User has not logged in yet"));
});
}

initiateTopup(provider: PAYMENT_PROVIDER_TYPE, params: PaymentParams): Promise<boolean> {
return new Promise((resolve, reject) => {
if (this.isInitialized) {
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,8 @@ export interface IUpbondEmbedParams {
origin: string;
};
};

flowConfig?: "normal" | "fastlogin";
}

export interface UnvalidatedJsonRpcRequest {
Expand Down

0 comments on commit 7604a52

Please sign in to comment.