From 1a1ca431e329c2deb7283d01e05115308b7268c5 Mon Sep 17 00:00:00 2001 From: zhl Date: Thu, 23 Mar 2023 15:41:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B4=A6=E5=8F=B7email?= =?UTF-8?q?=E8=AE=A4=E8=AF=81=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=80=E5=A7=8B=E8=B4=AD=E4=B9=B0=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 6 ++++++ src/services/EmailVerifySvr.ts | 30 ++++++++++++++++++++++++++++++ src/services/PaySvr.ts | 15 +++++++++++++++ src/types/data.types.ts | 6 ++++++ 4 files changed, 57 insertions(+) create mode 100644 src/services/EmailVerifySvr.ts create mode 100644 src/services/PaySvr.ts diff --git a/src/index.ts b/src/index.ts index 908df40..d8b1967 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,7 +28,9 @@ import { loadInternalWallet, restoreWalletByMnemonic, } from "./manage/WalletManage"; +import { EmailVerifySvr } from "./services/EmailVerifySvr"; import { NativeSvr } from "./services/NativeSvr"; +import { PaySvr } from "./services/PaySvr"; import { TranHistorySvr } from "./services/TranHistorySvr"; import { ChainCommon } from "./standards/ChainCommon"; import { ERC1155Standard } from "./standards/ERC1155Standard"; @@ -70,6 +72,8 @@ export default class JCWallet { public jcStandard: JCStandard; public nativeSvr: NativeSvr; public historySvr: TranHistorySvr; + public emailVerifySvr: EmailVerifySvr; + public paySvr: PaySvr; public wConnect: ZWalletConnect; public mainHandlers = createWalletEvents(); public data: IAccount[] = []; @@ -84,6 +88,8 @@ export default class JCWallet { constructor({ type, chain }: { type: number; chain: number }) { this.nativeSvr = new NativeSvr(); this.historySvr = new TranHistorySvr(); + this.emailVerifySvr = new EmailVerifySvr(); + this.paySvr = new PaySvr(); this.walletType = type; chain = chain || 80001; let data = AllChains.find((o) => o.id === chain); diff --git a/src/services/EmailVerifySvr.ts b/src/services/EmailVerifySvr.ts new file mode 100644 index 0000000..e6c28d9 --- /dev/null +++ b/src/services/EmailVerifySvr.ts @@ -0,0 +1,30 @@ +import { updateEmailVerify } from "../api/PayApi"; +import { isEmailVerified } from "../api/WalletApi"; +import { singleton } from "../decorator/singleton.decorator"; + +@singleton +export class EmailVerifySvr { + /** + * Checks if the user's email is verified + * @returns an object containing the verification status and the user's email + */ + public async checkEmailVerified() { + let res = await isEmailVerified(); + let verified = 0; + let email = ""; + if (!res.errcode) { + verified = res.data.verified; + email = res.data?.email; + } + return { verified, email }; + } + /** + * Begins the process of verifying the user's email + * @param email - the email to be verified + * @returns a Promise that resolves to the result of the updateEmailVerify API call + */ + + public async beginVerifyEmail(email: string) { + return updateEmailVerify({ email }); + } +} diff --git a/src/services/PaySvr.ts b/src/services/PaySvr.ts new file mode 100644 index 0000000..9ccb2ca --- /dev/null +++ b/src/services/PaySvr.ts @@ -0,0 +1,15 @@ +import { alchemyPrePay } from "../api/PayApi"; +import { singleton } from "../decorator/singleton.decorator"; +import { IPayData } from "../types/data.types"; + +@singleton +export class PaySvr { + /** + * Calls the alchemyPrePay function with the given data. + * @param data - The data to be passed to the alchemyPrePay function. + * @returns The result of the alchemyPrePay function. + */ + public async alchemyPrePay(data: IPayData) { + return alchemyPrePay(data); + } +} diff --git a/src/types/data.types.ts b/src/types/data.types.ts index b142a84..cbec1f8 100644 --- a/src/types/data.types.ts +++ b/src/types/data.types.ts @@ -7,3 +7,9 @@ export interface IChainData { explorerurl: string; decimals?: number; } + +export interface IPayData { + address: string; + chain: string; + currency: string; +}