@hydro-protocol/swap-sdk
Version:
Javascript SDK for Hydro Swap
81 lines (80 loc) • 3.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* A handler for a custom wallet definition.
*/
var CustomWallet = /** @class */ (function () {
/**
* @param name The name of your wallet in the dropdown.
* @param iconURL URL of an icon for the dropdown.
* Can be anything that would go into an img tag as src, e.g. url or data:image.
*/
function CustomWallet(name, iconURL) {
this.data = {
name: name,
iconURL: iconURL
};
this.functions = {};
}
Object.defineProperty(CustomWallet.prototype, "name", {
get: function () {
return this.data.name;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CustomWallet.prototype, "iconURL", {
get: function () {
return this.data.iconURL || "";
},
enumerable: true,
configurable: true
});
CustomWallet.prototype.approveTransaction = function (txData) {
if (!this.functions.approveTransaction) {
throw new Error("If requesting a custom wallet, you must define a approveTransaction handler");
}
return this.functions.approveTransaction(txData);
};
CustomWallet.prototype.getAccounts = function () {
if (!this.functions.getAccounts) {
throw new Error("If requesting a custom wallet, you must define a getAccounts handler");
}
return this.functions.getAccounts();
};
CustomWallet.prototype.signTransaction = function (txData) {
console.log(txData);
if (!this.functions.signTransaction) {
throw new Error("If requesting a custom wallet, you must define a signTransaction handler");
}
return this.functions.signTransaction(txData);
};
/**
* A handler for approving a transaction.
* @param approveTransaction A function which takes in web3 transaction data and returns a promise.
* The promise should resolve to true if the transaction is approved, and false otherwise.
*/
CustomWallet.prototype.handleApproveTransaction = function (approveTransaction) {
this.functions.approveTransaction = approveTransaction;
return this;
};
/**
* A handler for getting account addresses associated with this wallet
* @param getAccounts A function that returns a promise. The promise should resolve to an array of addresses.
*/
CustomWallet.prototype.handleGetAccounts = function (getAccounts) {
this.functions.getAccounts = getAccounts;
return this;
};
/**
* A handler for signing transaction data
* @param signTransaction A function which takes in web3 transaction data and returns a promise.
* The promise should resolve to a string representing the signed transaction data in hex format.
*/
CustomWallet.prototype.handleSignTransaction = function (signTransaction) {
this.functions.signTransaction = signTransaction;
return this;
};
return CustomWallet;
}());
exports.default = CustomWallet;