@coinbase/onchaintestkit
Version:
End-to-end testing toolkit for blockchain applications, powered by Playwright
85 lines (84 loc) • 3.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NotificationPage = exports.NotificationPageType = void 0;
const utils_1 = require("../../../../utils");
const BasePage_1 = require("../BasePage");
const actions_1 = require("./actions");
const confirmEvent_1 = require("./actions/confirmEvent");
/**
* Types of notifications that can appear in the Phantom Wallet
*/
var NotificationPageType;
(function (NotificationPageType) {
NotificationPageType["CONNECT"] = "connect";
NotificationPageType["SIGNATURE"] = "signature";
NotificationPageType["TOKEN_PERMISSION"] = "token_permission";
NotificationPageType["SPENDING_CAP"] = "spending_cap";
})(NotificationPageType || (exports.NotificationPageType = NotificationPageType = {}));
// Constants for Phantom notification page
const NOTIFICATION_PAGE_PATH = "notification.html";
const DEFAULT_VIEWPORT = { width: 360, height: 580 };
/**
* Represents the notification popup page in Phantom Wallet
* This page handles various notifications like:
* - Connect to dapp requests
* - Transaction approvals
* - Token permissions
* - Message signing
*/
class NotificationPage extends BasePage_1.BasePage {
/**
* Helper method to get notification page URL
*/
getNotificationUrl(extensionId) {
return `chrome-extension://${extensionId}/${NOTIFICATION_PAGE_PATH}`;
}
/**
* Helper method to wait for notification page
*/
async getNotificationPage(extensionId) {
return (0, utils_1.waitForPage)(this.page.context(), this.getNotificationUrl(extensionId), DEFAULT_VIEWPORT);
}
/**
* Handles the connect to dapp notification
*/
async connectToDapp(extensionId) {
const notificationPage = await this.getNotificationPage(extensionId);
await (0, actions_1.connectToDapp)(notificationPage);
}
/**
* Confirms a transaction
*/
async confirmTransaction(extensionId) {
const notificationPage = await this.getNotificationPage(extensionId);
await (0, confirmEvent_1.confirmEvent)(notificationPage);
}
/**
* Rejects a transaction
*/
async rejectTransaction(extensionId) {
const notificationPage = await this.getNotificationPage(extensionId);
await (0, confirmEvent_1.rejectEvent)(notificationPage);
}
/**
* Signs a message
*/
async signMessage(extensionId) {
const notificationPage = await this.getNotificationPage(extensionId);
await (0, confirmEvent_1.confirmEvent)(notificationPage);
}
// TODO: Implement other notification methods for Phantom
async approveTokenPermission(_extensionId) {
console.log("Token permission approval for Phantom not yet implemented");
}
async rejectTokenPermission(_extensionId) {
console.log("Token permission rejection for Phantom not yet implemented");
}
async confirmSpendingCapRemoval(_extensionId) {
console.log("Spending cap removal for Phantom not yet implemented");
}
async rejectSpendingCapRemoval(_extensionId) {
console.log("Spending cap rejection for Phantom not yet implemented");
}
}
exports.NotificationPage = NotificationPage;