@pontem/wallet-adapter-plugin
Version:
Pontem plugin to use with Aptos Wallet Adapter
186 lines (184 loc) • 8.77 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
PontemWallet: () => PontemWallet,
PontemWalletName: () => PontemWalletName
});
module.exports = __toCommonJS(src_exports);
var import_wallet_adapter_core = require("@aptos-labs/wallet-adapter-core");
var PontemNetworkNameMapping = {
"Aptos mainnet": import_wallet_adapter_core.NetworkName.Mainnet,
"Aptos testnet": import_wallet_adapter_core.NetworkName.Testnet,
"Aptos devnet": import_wallet_adapter_core.NetworkName.Devnet
};
var PontemWalletName = "Pontem";
var PontemWallet = class {
constructor() {
this.name = PontemWalletName;
this.url = "https://onelink.to/t3sae5";
this.icon = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzYiIGhlaWdodD0iMzYiIHZpZXdCb3g9IjAgMCAzNiAzNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTE4IDBDOC4wNzMwNCAwIDAgOC4wNzEzOSAwIDE3Ljk5NjNDMCAyNS4xMjk4IDQuMTczMTYgMzEuMzEwOCAxMC4yMDc2IDM0LjIyMDNWMzQuMjM1MUgxMC4yMzcyQzEyLjU4NiAzNS4zNjQ5IDE1LjIyMjggMzY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c3RvcC1jb2xvcj0iI0E5MkZBQyIvPgo8c3RvcCBvZmZzZXQ9IjAuNzQxMyIgc3RvcC1jb2xvcj0iI0NBMzc5MyIvPgo8c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiNGMDNGNzciLz4KPC9saW5lYXJHcmFkaWVudD4KPC9kZWZzPgo8L3N2Zz4K";
this.provider = typeof window !== "undefined" ? window.pontem : void 0;
}
deeplinkProvider(data) {
return `pontem-wallet://link?url=${data.url}`;
}
async connect() {
var _a;
try {
const accountInfo = await ((_a = this.provider) == null ? void 0 : _a.connect());
if (!accountInfo)
throw `${PontemWalletName} Address Info Error`;
return accountInfo;
} catch (error) {
throw error;
}
}
async account() {
var _a, _b, _c;
const response = await ((_a = this.provider) == null ? void 0 : _a.account());
if (!response)
throw `${PontemWalletName} Account Error`;
let publicKey = "";
if ((_b = this.provider) == null ? void 0 : _b.publicKey) {
publicKey = await ((_c = this.provider) == null ? void 0 : _c.publicKey());
}
return { ...response, publicKey };
}
async disconnect() {
var _a;
try {
await ((_a = this.provider) == null ? void 0 : _a.disconnect());
} catch (error) {
throw error;
}
}
async signAndSubmitTransaction(transaction, options) {
var _a, _b, _c;
try {
if (!((_a = this.provider) == null ? void 0 : _a.signAndSubmit)) {
throw `${PontemWalletName} Sign and Submit failed`;
}
const response = await ((_c = this.provider) == null ? void 0 : _c.signAndSubmit(
transaction,
{ ...options, max_gas_amount: (_b = options == null ? void 0 : options.max_gas_amount) == null ? void 0 : _b.toString() }
));
if (!response || !response.success) {
throw new Error("No response");
}
if (response == null ? void 0 : response.code) {
throw new Error(response == null ? void 0 : response.message);
}
const hash = response.result.hash;
return { hash };
} catch (error) {
const errMsg = error.message;
throw errMsg;
}
}
async signMessage(message) {
var _a;
try {
if (typeof message !== "object" || !message.nonce) {
`${PontemWalletName} Invalid signMessage Payload`;
}
const response = await ((_a = this.provider) == null ? void 0 : _a.signMessage(message));
if (response) {
return response;
} else {
throw `${PontemWalletName} Sign Message failed`;
}
} catch (error) {
const errMsg = error.message;
throw errMsg;
}
}
async network() {
var _a;
try {
const response = await ((_a = this.provider) == null ? void 0 : _a.network());
if (!response)
throw `${PontemWalletName} Network Error`;
if (typeof response === "object" && (response == null ? void 0 : response.name)) {
return {
name: PontemNetworkNameMapping[response.name],
chainId: (response == null ? void 0 : response.chainId) ?? void 0,
api: (response == null ? void 0 : response.api) ?? void 0
};
}
return response;
} catch (error) {
throw error;
}
}
async onNetworkChange(callback) {
var _a;
try {
const handleNetworkChange = async (newNetwork) => {
if (newNetwork == null ? void 0 : newNetwork.name) {
callback({
name: PontemNetworkNameMapping[newNetwork.name],
chainId: (newNetwork == null ? void 0 : newNetwork.chainId) ?? void 0,
api: (newNetwork == null ? void 0 : newNetwork.api) ?? void 0
});
}
if (newNetwork == null ? void 0 : newNetwork.networkName) {
callback({
name: newNetwork.networkName,
chainId: void 0,
api: void 0
});
}
};
await ((_a = this.provider) == null ? void 0 : _a.onNetworkChange(handleNetworkChange));
} catch (error) {
const errMsg = error.message;
throw errMsg;
}
}
async onAccountChange(callback) {
var _a;
try {
const handleAccountChange = async (newAccount) => {
if (newAccount == null ? void 0 : newAccount.publicKey) {
callback({
publicKey: newAccount.publicKey,
address: newAccount.address
});
} else {
const response = await this.connect();
callback({
address: response == null ? void 0 : response.address,
publicKey: response == null ? void 0 : response.publicKey
});
}
};
await ((_a = this.provider) == null ? void 0 : _a.onAccountChange(handleAccountChange));
} catch (error) {
const errMsg = error.message;
throw errMsg;
}
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PontemWallet,
PontemWalletName
});