@web3modal/wallet
Advanced tools
Comparing version 3.6.0-3e71d4e4 to 3.6.0-48f50850
export const W3mFrameConstants = { | ||
SECURE_SITE_SDK: 'http://localhost:3010/sdk', | ||
SECURE_SITE_SDK: 'https://secure.web3modal.com/sdk', | ||
APP_EVENT_KEY: '@w3m-app/', | ||
@@ -20,3 +20,4 @@ FRAME_EVENT_KEY: '@w3m-frame/', | ||
APP_RPC_REQUEST: '@w3m-app/RPC_REQUEST', | ||
APP_UPDATE_EMAIL: '@w3m=app/UPDATE_EMAIL', | ||
APP_UPDATE_EMAIL: '@w3m-app/UPDATE_EMAIL', | ||
APP_AWAIT_UPDATE_EMAIL: '@w3m-app/AWAIT_UPDATE_EMAIL', | ||
FRAME_SWITCH_NETWORK_ERROR: '@w3m-frame/SWITCH_NETWORK_ERROR', | ||
@@ -42,4 +43,6 @@ FRAME_SWITCH_NETWORK_SUCCESS: '@w3m-frame/SWITCH_NETWORK_SUCCESS', | ||
FRAME_UPDATE_EMAIL_SUCCESS: '@w3m-frame/UPDATE_EMAIL_SUCCESS', | ||
FRAME_UPDATE_EMAIL_ERROR: '@w3m-frame/UPDATE_EMAIL_ERROR' | ||
FRAME_UPDATE_EMAIL_ERROR: '@w3m-frame/UPDATE_EMAIL_ERROR', | ||
FRAME_AWAIT_UPDATE_EMAIL_SUCCESS: '@w3m-frame/AWAIT_UPDATE_EMAIL_SUCCESS', | ||
FRAME_AWAIT_UPDATE_EMAIL_ERROR: '@w3m-frame/AWAIT_UPDATE_EMAIL_ERROR' | ||
}; | ||
//# sourceMappingURL=W3mFrameConstants.js.map |
@@ -0,1 +1,3 @@ | ||
import { W3mFrameStorage } from './W3mFrameStorage.js'; | ||
import { W3mFrameConstants } from './W3mFrameConstants.js'; | ||
const RESTRICTED_TIMEZONES = [ | ||
@@ -26,6 +28,13 @@ 'ASIA/SHANGHAI', | ||
}, | ||
getTimeDifferenceMs(deadlineMs) { | ||
return Date.now() - deadlineMs; | ||
checkIfAllowedToTriggerEmail() { | ||
const lastEmailLoginTime = W3mFrameStorage.get(W3mFrameConstants.LAST_EMAIL_LOGIN_TIME); | ||
if (lastEmailLoginTime) { | ||
const difference = Date.now() - Number(lastEmailLoginTime); | ||
if (difference < 30000) { | ||
const cooldownSec = Math.ceil((30000 - difference) / 1000); | ||
throw new Error(`Please try again after ${cooldownSec} seconds`); | ||
} | ||
} | ||
} | ||
}; | ||
//# sourceMappingURL=W3mFrameHelpers.js.map |
@@ -17,2 +17,3 @@ import { W3mFrame } from './W3mFrame.js'; | ||
this.updateEmailResolver = undefined; | ||
this.awaitUpdateEmailResolver = undefined; | ||
this.w3mFrame = new W3mFrame(projectId, true); | ||
@@ -64,2 +65,6 @@ this.w3mFrame.events.onFrameEvent(event => { | ||
return this.onUpdateEmailError(event); | ||
case W3mFrameConstants.FRAME_AWAIT_UPDATE_EMAIL_SUCCESS: | ||
return this.onAwaitUpdateEmailSuccess(event); | ||
case W3mFrameConstants.FRAME_AWAIT_UPDATE_EMAIL_ERROR: | ||
return this.onAwaitUpdateEmailError(event); | ||
default: | ||
@@ -78,10 +83,3 @@ return null; | ||
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`); | ||
} | ||
} | ||
W3mFrameHelpers.checkIfAllowedToTriggerEmail(); | ||
this.w3mFrame.events.postAppEvent({ type: W3mFrameConstants.APP_CONNECT_EMAIL, payload }); | ||
@@ -125,2 +123,3 @@ return new Promise((resolve, reject) => { | ||
await this.w3mFrame.frameLoadPromise; | ||
W3mFrameHelpers.checkIfAllowedToTriggerEmail(); | ||
this.w3mFrame.events.postAppEvent({ type: W3mFrameConstants.APP_UPDATE_EMAIL, payload }); | ||
@@ -131,2 +130,9 @@ return new Promise((resolve, reject) => { | ||
} | ||
async awaitUpdateEmail() { | ||
await this.w3mFrame.frameLoadPromise; | ||
this.w3mFrame.events.postAppEvent({ type: W3mFrameConstants.APP_AWAIT_UPDATE_EMAIL }); | ||
return new Promise((resolve, reject) => { | ||
this.awaitUpdateEmailResolver = { resolve, reject }; | ||
}); | ||
} | ||
async connect(payload) { | ||
@@ -189,3 +195,3 @@ await this.w3mFrame.frameLoadPromise; | ||
this.connectEmailResolver?.resolve(event.payload); | ||
W3mFrameStorage.set(W3mFrameConstants.LAST_EMAIL_LOGIN_TIME, Date.now().toString()); | ||
this.setNewLastEmailLoginTime(); | ||
} | ||
@@ -208,5 +214,3 @@ onConnectEmailError(event) { | ||
onConnectSuccess(event) { | ||
W3mFrameStorage.set(W3mFrameConstants.EMAIL, event.payload.email); | ||
W3mFrameStorage.set(W3mFrameConstants.EMAIL_LOGIN_USED_KEY, 'true'); | ||
W3mFrameStorage.delete(W3mFrameConstants.LAST_EMAIL_LOGIN_TIME); | ||
this.setEmailLoginSuccess(event.payload.email); | ||
this.connectResolver?.resolve(event.payload); | ||
@@ -256,2 +260,3 @@ } | ||
this.updateEmailResolver?.resolve(undefined); | ||
this.setNewLastEmailLoginTime(); | ||
} | ||
@@ -261,3 +266,18 @@ onUpdateEmailError(event) { | ||
} | ||
onAwaitUpdateEmailSuccess(event) { | ||
this.setEmailLoginSuccess(event.payload.email); | ||
this.awaitUpdateEmailResolver?.resolve(event.payload); | ||
} | ||
onAwaitUpdateEmailError(event) { | ||
this.awaitUpdateEmailResolver?.reject(event.payload.message); | ||
} | ||
setNewLastEmailLoginTime() { | ||
W3mFrameStorage.set(W3mFrameConstants.LAST_EMAIL_LOGIN_TIME, Date.now().toString()); | ||
} | ||
setEmailLoginSuccess(email) { | ||
W3mFrameStorage.set(W3mFrameConstants.EMAIL, email); | ||
W3mFrameStorage.set(W3mFrameConstants.EMAIL_LOGIN_USED_KEY, 'true'); | ||
W3mFrameStorage.delete(W3mFrameConstants.LAST_EMAIL_LOGIN_TIME); | ||
} | ||
} | ||
//# sourceMappingURL=W3mFrameProvider.js.map |
@@ -11,3 +11,3 @@ import { z } from 'zod'; | ||
export const AppGetUserRequest = z.object({ chainId: z.optional(z.number()) }); | ||
export const AppUpdateEmail = z.object({ email: z.string().email() }); | ||
export const AppUpdateEmailRequest = z.object({ email: z.string().email() }); | ||
export const FrameConnectEmailResponse = z.object({ | ||
@@ -23,2 +23,3 @@ action: z.enum(['VERIFY_DEVICE', 'VERIFY_OTP']) | ||
export const FrameGetChainIdResponse = z.object({ chainId: z.number() }); | ||
export const FrameAwaitUpdateEmailResponse = z.object({ email: z.string().email() }); | ||
export const RpcResponse = z.string(); | ||
@@ -73,3 +74,4 @@ export const RpcPersonalSignRequest = z.object({ | ||
})) | ||
.or(z.object({ type: zType('APP_UPDATE_EMAIL'), payload: AppUpdateEmail })), | ||
.or(z.object({ type: zType('APP_UPDATE_EMAIL'), payload: AppUpdateEmailRequest })) | ||
.or(z.object({ type: zType('APP_AWAIT_UPDATE_EMAIL') })), | ||
frameEvent: z | ||
@@ -97,3 +99,8 @@ .object({ type: zType('FRAME_SWITCH_NETWORK_ERROR'), payload: zError }) | ||
.or(z.object({ type: zType('FRAME_UPDATE_EMAIL_SUCCESS') })) | ||
.or(z.object({ type: zType('FRAME_AWAIT_UPDATE_EMAIL_ERROR'), payload: zError })) | ||
.or(z.object({ | ||
type: zType('FRAME_AWAIT_UPDATE_EMAIL_SUCCESS'), | ||
payload: FrameAwaitUpdateEmailResponse | ||
})) | ||
}; | ||
//# sourceMappingURL=W3mFrameSchema.js.map |
import { z } from 'zod'; | ||
import { W3mFrameSchema, AppConnectEmailRequest, AppConnectOtpRequest, AppSwitchNetworkRequest, FrameConnectEmailResponse, FrameGetChainIdResponse, FrameGetUserResponse, FrameIsConnectedResponse, RpcPersonalSignRequest, RpcResponse, RpcEthSendTransactionRequest, RpcEthSignTypedDataV4, RpcEthAccountsRequest, RpcEthEstimateGas, RpcEthGasPrice, RpcGetBalance, FrameSession, AppGetUserRequest, AppUpdateEmail } from './W3mFrameSchema.js'; | ||
import { W3mFrameSchema, AppConnectEmailRequest, AppConnectOtpRequest, AppSwitchNetworkRequest, FrameConnectEmailResponse, FrameGetChainIdResponse, FrameGetUserResponse, FrameIsConnectedResponse, RpcPersonalSignRequest, RpcResponse, RpcEthSendTransactionRequest, RpcEthSignTypedDataV4, RpcEthAccountsRequest, RpcEthEstimateGas, RpcEthGasPrice, RpcGetBalance, FrameSession, AppGetUserRequest, AppUpdateEmailRequest, FrameAwaitUpdateEmailResponse } from './W3mFrameSchema.js'; | ||
//# sourceMappingURL=W3mFrameTypes.js.map |
export declare const W3mFrameConstants: { | ||
readonly SECURE_SITE_SDK: "http://localhost:3010/sdk"; | ||
readonly SECURE_SITE_SDK: "https://secure.web3modal.com/sdk"; | ||
readonly APP_EVENT_KEY: "@w3m-app/"; | ||
@@ -20,3 +20,4 @@ readonly FRAME_EVENT_KEY: "@w3m-frame/"; | ||
readonly APP_RPC_REQUEST: "@w3m-app/RPC_REQUEST"; | ||
readonly APP_UPDATE_EMAIL: "@w3m=app/UPDATE_EMAIL"; | ||
readonly APP_UPDATE_EMAIL: "@w3m-app/UPDATE_EMAIL"; | ||
readonly APP_AWAIT_UPDATE_EMAIL: "@w3m-app/AWAIT_UPDATE_EMAIL"; | ||
readonly FRAME_SWITCH_NETWORK_ERROR: "@w3m-frame/SWITCH_NETWORK_ERROR"; | ||
@@ -43,2 +44,4 @@ readonly FRAME_SWITCH_NETWORK_SUCCESS: "@w3m-frame/SWITCH_NETWORK_SUCCESS"; | ||
readonly FRAME_UPDATE_EMAIL_ERROR: "@w3m-frame/UPDATE_EMAIL_ERROR"; | ||
readonly FRAME_AWAIT_UPDATE_EMAIL_SUCCESS: "@w3m-frame/AWAIT_UPDATE_EMAIL_SUCCESS"; | ||
readonly FRAME_AWAIT_UPDATE_EMAIL_ERROR: "@w3m-frame/AWAIT_UPDATE_EMAIL_ERROR"; | ||
}; |
export declare const W3mFrameHelpers: { | ||
getBlockchainApiUrl(): false | "https://rpc.walletconnect.org" | "https://rpc.walletconnect.com"; | ||
getTimeDifferenceMs(deadlineMs: number): number; | ||
checkIfAllowedToTriggerEmail(): void; | ||
}; |
@@ -14,2 +14,3 @@ import type { W3mFrameTypes } from './W3mFrameTypes.js'; | ||
private updateEmailResolver; | ||
private awaitUpdateEmailResolver; | ||
constructor(projectId: string); | ||
@@ -29,3 +30,6 @@ getLoginEmailUsed(): boolean; | ||
}>; | ||
updateEmail(payload: W3mFrameTypes.Requests['AppUpdateEmail']): Promise<unknown>; | ||
updateEmail(payload: W3mFrameTypes.Requests['AppUpdateEmailRequest']): Promise<unknown>; | ||
awaitUpdateEmail(): Promise<{ | ||
email: string; | ||
}>; | ||
connect(payload?: W3mFrameTypes.Requests['AppGetUserRequest']): Promise<{ | ||
@@ -63,2 +67,6 @@ chainId: number; | ||
private onUpdateEmailError; | ||
private onAwaitUpdateEmailSuccess; | ||
private onAwaitUpdateEmailError; | ||
private setNewLastEmailLoginTime; | ||
private setEmailLoginSuccess; | ||
} |
@@ -30,3 +30,3 @@ import { z } from 'zod'; | ||
}>; | ||
export declare const AppUpdateEmail: z.ZodObject<{ | ||
export declare const AppUpdateEmailRequest: z.ZodObject<{ | ||
email: z.ZodString; | ||
@@ -72,2 +72,9 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
export declare const FrameAwaitUpdateEmailResponse: z.ZodObject<{ | ||
email: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
email: string; | ||
}, { | ||
email: string; | ||
}>; | ||
export declare const RpcResponse: z.ZodString; | ||
@@ -146,3 +153,3 @@ export declare const RpcPersonalSignRequest: z.ZodObject<{ | ||
export declare const W3mFrameSchema: { | ||
appEvent: z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodObject<{ | ||
appEvent: z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodObject<{ | ||
type: z.ZodLiteral<"@w3m-app/SWITCH_NETWORK">; | ||
@@ -365,3 +372,3 @@ payload: z.ZodObject<{ | ||
}>]>, z.ZodObject<{ | ||
type: z.ZodLiteral<"@w3m=app/UPDATE_EMAIL">; | ||
type: z.ZodLiteral<"@w3m-app/UPDATE_EMAIL">; | ||
payload: z.ZodObject<{ | ||
@@ -375,3 +382,3 @@ email: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
type: "@w3m=app/UPDATE_EMAIL"; | ||
type: "@w3m-app/UPDATE_EMAIL"; | ||
payload: { | ||
@@ -381,8 +388,14 @@ email: string; | ||
}, { | ||
type: "@w3m=app/UPDATE_EMAIL"; | ||
type: "@w3m-app/UPDATE_EMAIL"; | ||
payload: { | ||
email: string; | ||
}; | ||
}>]>, z.ZodObject<{ | ||
type: z.ZodLiteral<"@w3m-app/AWAIT_UPDATE_EMAIL">; | ||
}, "strip", z.ZodTypeAny, { | ||
type: "@w3m-app/AWAIT_UPDATE_EMAIL"; | ||
}, { | ||
type: "@w3m-app/AWAIT_UPDATE_EMAIL"; | ||
}>]>; | ||
frameEvent: z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodObject<{ | ||
frameEvent: z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodObject<{ | ||
type: z.ZodLiteral<"@w3m-frame/SWITCH_NETWORK_ERROR">; | ||
@@ -721,3 +734,41 @@ payload: z.ZodObject<{ | ||
type: "@w3m-frame/UPDATE_EMAIL_SUCCESS"; | ||
}>]>, z.ZodObject<{ | ||
type: z.ZodLiteral<"@w3m-frame/AWAIT_UPDATE_EMAIL_ERROR">; | ||
payload: z.ZodObject<{ | ||
message: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
message: string; | ||
}, { | ||
message: string; | ||
}>; | ||
}, "strip", z.ZodTypeAny, { | ||
type: "@w3m-frame/AWAIT_UPDATE_EMAIL_ERROR"; | ||
payload: { | ||
message: string; | ||
}; | ||
}, { | ||
type: "@w3m-frame/AWAIT_UPDATE_EMAIL_ERROR"; | ||
payload: { | ||
message: string; | ||
}; | ||
}>]>, z.ZodObject<{ | ||
type: z.ZodLiteral<"@w3m-frame/AWAIT_UPDATE_EMAIL_SUCCESS">; | ||
payload: z.ZodObject<{ | ||
email: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
email: string; | ||
}, { | ||
email: string; | ||
}>; | ||
}, "strip", z.ZodTypeAny, { | ||
type: "@w3m-frame/AWAIT_UPDATE_EMAIL_SUCCESS"; | ||
payload: { | ||
email: string; | ||
}; | ||
}, { | ||
type: "@w3m-frame/AWAIT_UPDATE_EMAIL_SUCCESS"; | ||
payload: { | ||
email: string; | ||
}; | ||
}>]>; | ||
}; |
import { z } from 'zod'; | ||
import { W3mFrameSchema, AppConnectEmailRequest, AppConnectOtpRequest, AppSwitchNetworkRequest, FrameConnectEmailResponse, FrameGetChainIdResponse, FrameGetUserResponse, FrameIsConnectedResponse, RpcPersonalSignRequest, RpcResponse, RpcEthSendTransactionRequest, RpcEthSignTypedDataV4, RpcEthAccountsRequest, RpcEthEstimateGas, RpcEthGasPrice, RpcGetBalance, FrameSession, AppGetUserRequest, AppUpdateEmail } from './W3mFrameSchema.js'; | ||
import { W3mFrameSchema, AppConnectEmailRequest, AppConnectOtpRequest, AppSwitchNetworkRequest, FrameConnectEmailResponse, FrameGetChainIdResponse, FrameGetUserResponse, FrameIsConnectedResponse, RpcPersonalSignRequest, RpcResponse, RpcEthSendTransactionRequest, RpcEthSignTypedDataV4, RpcEthAccountsRequest, RpcEthEstimateGas, RpcEthGasPrice, RpcGetBalance, FrameSession, AppGetUserRequest, AppUpdateEmailRequest, FrameAwaitUpdateEmailResponse } from './W3mFrameSchema.js'; | ||
export declare namespace W3mFrameTypes { | ||
@@ -11,3 +11,3 @@ type AppEvent = z.infer<typeof W3mFrameSchema.appEvent>; | ||
AppGetUserRequest: z.infer<typeof AppGetUserRequest>; | ||
AppUpdateEmail: z.infer<typeof AppUpdateEmail>; | ||
AppUpdateEmailRequest: z.infer<typeof AppUpdateEmailRequest>; | ||
} | ||
@@ -19,2 +19,3 @@ interface Responses { | ||
FrameIsConnectedResponse: z.infer<typeof FrameIsConnectedResponse>; | ||
FrameAwaitUpdateEmailResponse: z.infer<typeof FrameAwaitUpdateEmailResponse>; | ||
} | ||
@@ -21,0 +22,0 @@ interface Network { |
{ | ||
"name": "@web3modal/wallet", | ||
"version": "3.6.0-3e71d4e4", | ||
"version": "3.6.0-48f50850", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "main": "./dist/esm/index.js", |
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
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
80930
1505
1