@web3modal/wallet
Advanced tools
Comparing version 3.5.0 to 3.6.0-37fb52b0
@@ -65,3 +65,3 @@ import { W3mFrameConstants } from './W3mFrameConstants.js'; | ||
this.iframe.onerror = () => { | ||
this.frameLoadPromiseResolver?.reject(); | ||
this.frameLoadPromiseResolver?.reject('Unable to load email login dependency'); | ||
}; | ||
@@ -68,0 +68,0 @@ } |
@@ -8,2 +8,4 @@ export const W3mFrameConstants = { | ||
SESSION_TOKEN_KEY: 'SESSION_TOKEN_KEY', | ||
EMAIL_LOGIN_USED_KEY: 'EMAIL_LOGIN_USED_KEY', | ||
LAST_EMAIL_LOGIN_TIME: 'LAST_EMAIL_LOGIN_TIME', | ||
APP_SWITCH_NETWORK: '@w3m-app/SWITCH_NETWORK', | ||
@@ -10,0 +12,0 @@ APP_CONNECT_EMAIL: '@w3m-app/CONNECT_EMAIL', |
@@ -25,4 +25,7 @@ const RESTRICTED_TIMEZONES = [ | ||
} | ||
}, | ||
getTimeDifferenceMs(deadlineMs) { | ||
return Date.now() - deadlineMs; | ||
} | ||
}; | ||
//# sourceMappingURL=W3mFrameHelpers.js.map |
import { W3mFrame } from './W3mFrame.js'; | ||
import { W3mFrameConstants } from './W3mFrameConstants.js'; | ||
import { W3mFrameStorage } from './W3mFrameStorage.js'; | ||
import { W3mFrameHelpers } from './W3mFrameHelpers.js'; | ||
export class W3mFrameProvider { | ||
@@ -62,4 +63,15 @@ constructor(projectId) { | ||
} | ||
getLoginEmailUsed() { | ||
return Boolean(W3mFrameStorage.get(W3mFrameConstants.EMAIL_LOGIN_USED_KEY)); | ||
} | ||
async connectEmail(payload) { | ||
await this.w3mFrame.frameLoadPromise; | ||
const lastEmailLoginTime = W3mFrameStorage.get(W3mFrameConstants.LAST_EMAIL_LOGIN_TIME); | ||
if (lastEmailLoginTime) { | ||
const difference = W3mFrameHelpers.getTimeDifferenceMs(Number(lastEmailLoginTime)); | ||
if (difference < 30000) { | ||
const cooldownSec = Math.ceil((30000 - difference) / 1000); | ||
throw new Error(`Please try again after ${cooldownSec} seconds`); | ||
} | ||
} | ||
this.w3mFrame.events.postAppEvent({ type: W3mFrameConstants.APP_CONNECT_EMAIL, payload }); | ||
@@ -102,5 +114,5 @@ return new Promise((resolve, reject) => { | ||
} | ||
async connect() { | ||
async connect(payload) { | ||
await this.w3mFrame.frameLoadPromise; | ||
this.w3mFrame.events.postAppEvent({ type: W3mFrameConstants.APP_GET_USER }); | ||
this.w3mFrame.events.postAppEvent({ type: W3mFrameConstants.APP_GET_USER, payload }); | ||
return new Promise((resolve, reject) => { | ||
@@ -161,2 +173,3 @@ this.connectResolver = { resolve, reject }; | ||
this.connectEmailResolver?.resolve(event.payload); | ||
W3mFrameStorage.set(W3mFrameConstants.LAST_EMAIL_LOGIN_TIME, Date.now().toString()); | ||
} | ||
@@ -174,2 +187,4 @@ onConnectEmailError(event) { | ||
this.connectOtpResolver?.resolve(undefined); | ||
W3mFrameStorage.set(W3mFrameConstants.EMAIL_LOGIN_USED_KEY, 'true'); | ||
W3mFrameStorage.delete(W3mFrameConstants.LAST_EMAIL_LOGIN_TIME); | ||
} | ||
@@ -199,2 +214,3 @@ onConnectOtpError(event) { | ||
this.disconnectResolver?.resolve(undefined); | ||
W3mFrameStorage.delete(W3mFrameConstants.EMAIL_LOGIN_USED_KEY); | ||
} | ||
@@ -201,0 +217,0 @@ onSignOutError(event) { |
@@ -10,2 +10,3 @@ import { z } from 'zod'; | ||
export const AppConnectOtpRequest = z.object({ otp: z.string() }); | ||
export const AppGetUserRequest = z.object({ chainId: z.optional(z.number()) }); | ||
export const FrameConnectEmailResponse = z.object({ | ||
@@ -56,3 +57,3 @@ action: z.enum(['VERIFY_DEVICE', 'VERIFY_OTP']) | ||
.or(z.object({ type: zType('APP_CONNECT_OTP'), payload: AppConnectOtpRequest })) | ||
.or(z.object({ type: zType('APP_GET_USER') })) | ||
.or(z.object({ type: zType('APP_GET_USER'), payload: z.optional(AppGetUserRequest) })) | ||
.or(z.object({ type: zType('APP_SIGN_OUT') })) | ||
@@ -59,0 +60,0 @@ .or(z.object({ type: zType('APP_IS_CONNECTED'), payload: z.optional(FrameSession) })) |
import { z } from 'zod'; | ||
import { W3mFrameSchema, AppConnectEmailRequest, AppConnectOtpRequest, AppSwitchNetworkRequest, FrameConnectEmailResponse, FrameGetChainIdResponse, FrameGetUserResponse, FrameIsConnectedResponse, RpcPersonalSignRequest, RpcResponse, RpcEthSendTransactionRequest, RpcEthSignTypedDataV4, RpcEthAccountsRequest, RpcEthEstimateGas, RpcEthGasPrice, RpcGetBalance, FrameSession } from './W3mFrameSchema.js'; | ||
import { W3mFrameSchema, AppConnectEmailRequest, AppConnectOtpRequest, AppSwitchNetworkRequest, FrameConnectEmailResponse, FrameGetChainIdResponse, FrameGetUserResponse, FrameIsConnectedResponse, RpcPersonalSignRequest, RpcResponse, RpcEthSendTransactionRequest, RpcEthSignTypedDataV4, RpcEthAccountsRequest, RpcEthEstimateGas, RpcEthGasPrice, RpcGetBalance, FrameSession, AppGetUserRequest } from './W3mFrameSchema.js'; | ||
//# sourceMappingURL=W3mFrameTypes.js.map |
@@ -8,2 +8,4 @@ export declare const W3mFrameConstants: { | ||
readonly SESSION_TOKEN_KEY: "SESSION_TOKEN_KEY"; | ||
readonly EMAIL_LOGIN_USED_KEY: "EMAIL_LOGIN_USED_KEY"; | ||
readonly LAST_EMAIL_LOGIN_TIME: "LAST_EMAIL_LOGIN_TIME"; | ||
readonly APP_SWITCH_NETWORK: "@w3m-app/SWITCH_NETWORK"; | ||
@@ -10,0 +12,0 @@ readonly APP_CONNECT_EMAIL: "@w3m-app/CONNECT_EMAIL"; |
export declare const W3mFrameHelpers: { | ||
getBlockchainApiUrl(): false | "https://rpc.walletconnect.org" | "https://rpc.walletconnect.com"; | ||
getTimeDifferenceMs(deadlineMs: number): number; | ||
}; |
@@ -14,2 +14,3 @@ import type { W3mFrameTypes } from './W3mFrameTypes.js'; | ||
constructor(projectId: string); | ||
getLoginEmailUsed(): boolean; | ||
connectEmail(payload: W3mFrameTypes.Requests['AppConnectEmailRequest']): Promise<{ | ||
@@ -26,3 +27,3 @@ action: "VERIFY_DEVICE" | "VERIFY_OTP"; | ||
}>; | ||
connect(): Promise<{ | ||
connect(payload?: W3mFrameTypes.Requests['AppGetUserRequest']): Promise<{ | ||
chainId: number; | ||
@@ -29,0 +30,0 @@ address: string; |
@@ -23,2 +23,9 @@ import { z } from 'zod'; | ||
}>; | ||
export declare const AppGetUserRequest: z.ZodObject<{ | ||
chainId: z.ZodOptional<z.ZodNumber>; | ||
}, "strip", z.ZodTypeAny, { | ||
chainId?: number | undefined; | ||
}, { | ||
chainId?: number | undefined; | ||
}>; | ||
export declare const FrameConnectEmailResponse: z.ZodObject<{ | ||
@@ -193,6 +200,19 @@ action: z.ZodEnum<["VERIFY_DEVICE", "VERIFY_OTP"]>; | ||
type: z.ZodLiteral<"@w3m-app/GET_USER">; | ||
payload: z.ZodOptional<z.ZodObject<{ | ||
chainId: z.ZodOptional<z.ZodNumber>; | ||
}, "strip", z.ZodTypeAny, { | ||
chainId?: number | undefined; | ||
}, { | ||
chainId?: number | undefined; | ||
}>>; | ||
}, "strip", z.ZodTypeAny, { | ||
type: "@w3m-app/GET_USER"; | ||
payload?: { | ||
chainId?: number | undefined; | ||
} | undefined; | ||
}, { | ||
type: "@w3m-app/GET_USER"; | ||
payload?: { | ||
chainId?: number | undefined; | ||
} | undefined; | ||
}>]>, z.ZodObject<{ | ||
@@ -199,0 +219,0 @@ type: z.ZodLiteral<"@w3m-app/SIGN_OUT">; |
import { z } from 'zod'; | ||
import { W3mFrameSchema, AppConnectEmailRequest, AppConnectOtpRequest, AppSwitchNetworkRequest, FrameConnectEmailResponse, FrameGetChainIdResponse, FrameGetUserResponse, FrameIsConnectedResponse, RpcPersonalSignRequest, RpcResponse, RpcEthSendTransactionRequest, RpcEthSignTypedDataV4, RpcEthAccountsRequest, RpcEthEstimateGas, RpcEthGasPrice, RpcGetBalance, FrameSession } from './W3mFrameSchema.js'; | ||
import { W3mFrameSchema, AppConnectEmailRequest, AppConnectOtpRequest, AppSwitchNetworkRequest, FrameConnectEmailResponse, FrameGetChainIdResponse, FrameGetUserResponse, FrameIsConnectedResponse, RpcPersonalSignRequest, RpcResponse, RpcEthSendTransactionRequest, RpcEthSignTypedDataV4, RpcEthAccountsRequest, RpcEthEstimateGas, RpcEthGasPrice, RpcGetBalance, FrameSession, AppGetUserRequest } from './W3mFrameSchema.js'; | ||
export declare namespace W3mFrameTypes { | ||
@@ -10,2 +10,3 @@ type AppEvent = z.infer<typeof W3mFrameSchema.appEvent>; | ||
AppSwitchNetworkRequest: z.infer<typeof AppSwitchNetworkRequest>; | ||
AppGetUserRequest: z.infer<typeof AppGetUserRequest>; | ||
} | ||
@@ -12,0 +13,0 @@ interface Responses { |
{ | ||
"name": "@web3modal/wallet", | ||
"version": "3.5.0", | ||
"version": "3.6.0-37fb52b0", | ||
"type": "module", | ||
@@ -13,4 +13,4 @@ "main": "./dist/esm/index.js", | ||
"build:clean": "rm -rf dist", | ||
"build": "npm run build:clean; tsc --build", | ||
"watch": "npm run build:clean; tsc --watch", | ||
"build:wallet": "tsc --build", | ||
"watch": "tsc --watch", | ||
"typecheck": "tsc --noEmit", | ||
@@ -17,0 +17,0 @@ "lint": "eslint . --ext .js,.jsx,.ts,.tsx" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
71133
1315
0
1