Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
BenKurrek committed Apr 17, 2023
1 parent a17efa6 commit 4a3d7c4
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 26 deletions.
1 change: 1 addition & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { useKeypom, KeypomContextProvider, } from './components/KeypomContext';
export { createDrop, deleteDrops, } from "./lib/drops";
export { createTrialAccountDrop, claimTrialAccountDrop } from "./lib/trial-accounts/pre-trial";
export { trialSignAndSendTxns, trialCallMethod, canExitTrial } from "./lib/trial-accounts/trial-active";
export { wrapTxnParamsForTrial } from "./lib/trial-accounts/utils";
export { addKeys, deleteKeys } from "./lib/keys";
export { claim, } from "./lib/claims";
export {
Expand Down
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.supportedLinkdropClaimPages = exports.updateFunder = exports.updateKeypomContractId = exports.getEnv = exports.initKeypom = exports.execute = exports.claim = exports.deleteKeys = exports.addKeys = exports.canExitTrial = exports.trialCallMethod = exports.trialSignAndSendTxns = exports.claimTrialAccountDrop = exports.createTrialAccountDrop = exports.deleteDrops = exports.createDrop = exports.KeypomContextProvider = exports.useKeypom = exports.formatNearAmount = exports.parseNearAmount = exports.nearAPI = exports.formatLinkdropUrl = exports.createNFTSeries = exports.getPubFromSecret = exports.getFTMetadata = exports.getNFTMetadata = exports.accountExists = exports.hashPassword = exports.nftTransferCall = exports.ftTransferCall = exports.getStorageBase = exports.estimateRequiredDeposit = exports.generateKeys = exports.withdrawBalance = exports.addToBalance = exports.setupKeypom = void 0;
exports.supportedLinkdropClaimPages = exports.updateFunder = exports.updateKeypomContractId = exports.getEnv = exports.initKeypom = exports.execute = exports.claim = exports.deleteKeys = exports.addKeys = exports.wrapTxnParamsForTrial = exports.canExitTrial = exports.trialCallMethod = exports.trialSignAndSendTxns = exports.claimTrialAccountDrop = exports.createTrialAccountDrop = exports.deleteDrops = exports.createDrop = exports.KeypomContextProvider = exports.useKeypom = exports.formatNearAmount = exports.parseNearAmount = exports.nearAPI = exports.formatLinkdropUrl = exports.createNFTSeries = exports.getPubFromSecret = exports.getFTMetadata = exports.getNFTMetadata = exports.accountExists = exports.hashPassword = exports.nftTransferCall = exports.ftTransferCall = exports.getStorageBase = exports.estimateRequiredDeposit = exports.generateKeys = exports.withdrawBalance = exports.addToBalance = exports.setupKeypom = void 0;
var setup_1 = require("./lib/selector/core/setup");
Object.defineProperty(exports, "setupKeypom", { enumerable: true, get: function () { return setup_1.setupKeypom; } });
var balances_1 = require("./lib/balances");
Expand Down Expand Up @@ -53,6 +53,8 @@ var trial_active_1 = require("./lib/trial-accounts/trial-active");
Object.defineProperty(exports, "trialSignAndSendTxns", { enumerable: true, get: function () { return trial_active_1.trialSignAndSendTxns; } });
Object.defineProperty(exports, "trialCallMethod", { enumerable: true, get: function () { return trial_active_1.trialCallMethod; } });
Object.defineProperty(exports, "canExitTrial", { enumerable: true, get: function () { return trial_active_1.canExitTrial; } });
var utils_1 = require("./lib/trial-accounts/utils");
Object.defineProperty(exports, "wrapTxnParamsForTrial", { enumerable: true, get: function () { return utils_1.wrapTxnParamsForTrial; } });
var keys_1 = require("./lib/keys");
Object.defineProperty(exports, "addKeys", { enumerable: true, get: function () { return keys_1.addKeys; } });
Object.defineProperty(exports, "deleteKeys", { enumerable: true, get: function () { return keys_1.deleteKeys; } });
Expand Down
14 changes: 12 additions & 2 deletions lib/lib/selector/core/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,21 @@ var KeypomWallet = /** @class */ (function () {
console.log("e: ".concat(JSON.stringify(e_4)));
switch (e_4) {
case utils_1.TRIAL_ERRORS.EXIT_EXPECTED: {
this.modal.show({ id: modal_types_1.MODAL_TYPE_IDS.TRIAL_OVER });
this.modal.show({
id: modal_types_1.MODAL_TYPE_IDS.TRIAL_OVER,
meta: {
accountId: this.trialAccountId,
secretKey: this.trialSecretKey
}
});
break;
}
case utils_1.TRIAL_ERRORS.INVALID_ACTION: {
this.modal.show({ id: modal_types_1.MODAL_TYPE_IDS.ERROR });
this.modal.show({ id: modal_types_1.MODAL_TYPE_IDS.ACTION_ERROR });
break;
}
case utils_1.TRIAL_ERRORS.INSUFFICIENT_BALANCE: {
this.modal.show({ id: modal_types_1.MODAL_TYPE_IDS.INSUFFICIENT_BALANCE });
break;
}
default: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from "react";
interface InsufficientBalanceProps {
hide: () => void;
}
export declare const InsufficientBalance: React.FC<InsufficientBalanceProps>;
export {};
18 changes: 18 additions & 0 deletions lib/lib/selector/modal/src/lib/components/InsufficientBalance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InsufficientBalance = void 0;
var react_1 = __importDefault(require("react"));
var modal_types_1 = require("../modal.types");
var MainBody_1 = require("./MainBody");
var InsufficientBalance = function (_a) {
var hide = _a.hide;
return (react_1.default.createElement("div", { className: "nws-modal", style: { width: "70%", height: "27%" } },
react_1.default.createElement("div", { className: "modal-right", style: { width: "100%" } },
react_1.default.createElement(MainBody_1.MainBody, { title: modal_types_1.MODAL_DEFAULTS.insufficientBalance.title, body: modal_types_1.MODAL_DEFAULTS.insufficientBalance.body, headerOne: null, headerTwo: null, onCloseModal: function () {
return hide();
} }))));
};
exports.InsufficientBalance = InsufficientBalance;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var InvalidActions = function (_a) {
var hide = _a.hide;
return (react_1.default.createElement("div", { className: "nws-modal", style: { width: "70%", height: "27%" } },
react_1.default.createElement("div", { className: "modal-right", style: { width: "100%" } },
react_1.default.createElement(MainBody_1.MainBody, { title: modal_types_1.MODAL_DEFAULTS.error.title, body: modal_types_1.MODAL_DEFAULTS.error.body, headerOne: null, headerTwo: null, onCloseModal: function () {
react_1.default.createElement(MainBody_1.MainBody, { title: modal_types_1.MODAL_DEFAULTS.invalidAction.title, body: modal_types_1.MODAL_DEFAULTS.invalidAction.body, headerOne: null, headerTwo: null, onCloseModal: function () {
return hide();
} }))));
};
Expand Down
1 change: 0 additions & 1 deletion lib/lib/selector/modal/src/lib/handleModalType.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/// <reference types="react" />
import { ModalOptions, ModalType } from "./modal.types";
export declare const renderModalType: (modalType: ModalType, options: ModalOptions, hide: () => void) => JSX.Element | null;
7 changes: 5 additions & 2 deletions lib/lib/selector/modal/src/lib/handleModalType.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.renderModalType = void 0;
var react_1 = __importDefault(require("react"));
var ClaimTrial_1 = require("./components/ClaimTrial");
var InsufficientBalance_1 = require("./components/InsufficientBalance");
var InvalidActions_1 = require("./components/InvalidActions");
var TrialOver_1 = require("./components/TrialOver");
var modal_types_1 = require("./modal.types");
var renderModalType = function (modalType, options, hide) {
switch (modalType.id) {
case modal_types_1.MODAL_TYPE_IDS.TRIAL_OVER:
return (react_1.default.createElement(TrialOver_1.TrialOver, { modulesTitle: options.modulesTitle, modules: options.modules, accountId: options.accountId, secretKey: options.secretKey, mainTitle: options.mainTitle, mainBody: options.mainBody, headerOne: options.headerOne, headerTwo: options.headerTwo, button: options.button, hide: hide }));
case modal_types_1.MODAL_TYPE_IDS.ERROR:
return (react_1.default.createElement(TrialOver_1.TrialOver, { modulesTitle: options.modulesTitle, modules: options.modules, accountId: modalType.meta.accountId, secretKey: modalType.meta.secretKey, mainTitle: options.mainTitle, mainBody: options.mainBody, headerOne: options.headerOne, headerTwo: options.headerTwo, button: options.button, hide: hide }));
case modal_types_1.MODAL_TYPE_IDS.ACTION_ERROR:
return react_1.default.createElement(InvalidActions_1.InvalidActions, { hide: hide });
case modal_types_1.MODAL_TYPE_IDS.INSUFFICIENT_BALANCE:
return react_1.default.createElement(InsufficientBalance_1.InsufficientBalance, { hide: hide });
case modal_types_1.MODAL_TYPE_IDS.CLAIM_TRIAL:
return react_1.default.createElement(ClaimTrial_1.ClaimTrial, { hide: hide, secretKey: modalType.meta.secretKey, redirectUrlBase: modalType.meta.redirectUrlBase, delimiter: modalType.meta.delimiter });
default: return null;
Expand Down
9 changes: 7 additions & 2 deletions lib/lib/selector/modal/src/lib/modal.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export interface ModalType {
export declare const MODAL_TYPE_IDS: {
CLAIM_TRIAL: string;
TRIAL_OVER: string;
ERROR: string;
ACTION_ERROR: string;
INSUFFICIENT_BALANCE: string;
};
export declare const MODAL_DEFAULTS: {
claimTrial: {
Expand All @@ -67,7 +68,11 @@ export declare const MODAL_DEFAULTS: {
modulesTitle: string;
};
};
error: {
invalidAction: {
title: string;
body: string;
};
insufficientBalance: {
title: string;
body: string;
};
Expand Down
9 changes: 7 additions & 2 deletions lib/lib/selector/modal/src/lib/modal.types.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ exports.MODAL_DEFAULTS = exports.MODAL_TYPE_IDS = void 0;
exports.MODAL_TYPE_IDS = {
CLAIM_TRIAL: "claim-trial",
TRIAL_OVER: "trial-over",
ERROR: "action-error"
ACTION_ERROR: "action-error",
INSUFFICIENT_BALANCE: "insufficient-balance"
};
exports.MODAL_DEFAULTS = {
claimTrial: {
Expand All @@ -30,8 +31,12 @@ exports.MODAL_DEFAULTS = {
modulesTitle: "Choose a Wallet",
}
},
error: {
invalidAction: {
title: "Invalid Action",
body: "Your trial does not allow you to perform this action. For more information, please contact the site administrator."
},
insufficientBalance: {
title: "Insufficient Balance",
body: "Your account does not have enough balance for the action you are trying to perform. Please try again with a different action. For more information, please contact the site administrator."
}
};
36 changes: 24 additions & 12 deletions lib/lib/trial-accounts/trial-active.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ var utils_1 = require("./utils");
var trialSignAndSendTxns = function (_a) {
var trialAccountId = _a.trialAccountId, trialAccountSecretKey = _a.trialAccountSecretKey, txns = _a.txns;
return __awaiter(void 0, void 0, void 0, function () {
var _b, near, keyStore, networkId, exitExpected, _c, methodDataToValidate, executeArgs, isValidTxn, trialKeyPair, pubKey, account, gasToAttach, transformedTransactions, promises;
var _b, near, keyStore, networkId, exitExpected, _c, methodDataToValidate, executeArgs, totalAttachedYocto, totalGasForTxns, isValidTxn, hasBal, trialKeyPair, pubKey, account, gasToAttach, transformedTransactions, promises;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
Expand All @@ -148,21 +148,27 @@ var trialSignAndSendTxns = function (_a) {
}
return [4 /*yield*/, (0, utils_1.generateExecuteArgs)({ desiredTxns: txns })];
case 2:
_c = _d.sent(), methodDataToValidate = _c.methodDataToValidate, executeArgs = _c.executeArgs;
_c = _d.sent(), methodDataToValidate = _c.methodDataToValidate, executeArgs = _c.executeArgs, totalAttachedYocto = _c.totalAttachedYocto, totalGasForTxns = _c.totalGasForTxns;
return [4 /*yield*/, (0, utils_1.validateDesiredMethods)({ methodData: methodDataToValidate, trialAccountId: trialAccountId })];
case 3:
isValidTxn = _d.sent();
console.log('isValidTxn: ', isValidTxn);
if (isValidTxn == false) {
throw utils_1.TRIAL_ERRORS.INVALID_ACTION;
}
return [4 /*yield*/, (0, utils_1.hasEnoughBalance)({ trialAccountId: trialAccountId, totalAttachedYocto: totalAttachedYocto, totalGasForTxns: totalGasForTxns })];
case 4:
hasBal = _d.sent();
if (hasBal == false) {
throw utils_1.TRIAL_ERRORS.INSUFFICIENT_BALANCE;
}
trialKeyPair = near_api_js_1.KeyPair.fromString(trialAccountSecretKey);
pubKey = trialKeyPair.getPublicKey();
return [4 /*yield*/, keyStore.setKey(networkId, trialAccountId, trialKeyPair)];
case 4:
case 5:
_d.sent();
return [4 /*yield*/, near.account(trialAccountId)];
case 5:
case 6:
account = _d.sent();
gasToAttach = (0, utils_1.estimateTrialGas)({ executeArgs: executeArgs });
return [4 /*yield*/, (0, keypom_utils_1.createTransactions)({
Expand All @@ -180,13 +186,13 @@ var trialSignAndSendTxns = function (_a) {
}]
}]
})];
case 6:
case 7:
transformedTransactions = _d.sent();
console.log("debugging");
console.log('transformedTransactions: ', transformedTransactions);
promises = transformedTransactions.map(function (tx) { return account.signAndSendTransaction(tx); });
return [4 /*yield*/, Promise.all(promises)];
case 7: return [2 /*return*/, _d.sent()];
case 8: return [2 /*return*/, _d.sent()];
}
});
});
Expand Down Expand Up @@ -257,7 +263,7 @@ exports.trialSignAndSendTxns = trialSignAndSendTxns;
var trialCallMethod = function (_a) {
var trialAccountId = _a.trialAccountId, trialAccountSecretKey = _a.trialAccountSecretKey, contractId = _a.contractId, methodName = _a.methodName, args = _a.args, attachedGas = _a.attachedGas, attachedDeposit = _a.attachedDeposit;
return __awaiter(void 0, void 0, void 0, function () {
var _b, near, keyStore, networkId, exitExpected, txns, _c, methodDataToValidate, executeArgs, isValidTxn, trialKeyPair, pubKey, account, gasToAttach, transformedTransactions, promises;
var _b, near, keyStore, networkId, exitExpected, txns, _c, methodDataToValidate, executeArgs, totalAttachedYocto, totalGasForTxns, isValidTxn, hasBal, trialKeyPair, pubKey, account, gasToAttach, transformedTransactions, promises;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
Expand Down Expand Up @@ -285,21 +291,27 @@ var trialCallMethod = function (_a) {
console.log("txns: ".concat(JSON.stringify(txns)));
return [4 /*yield*/, (0, utils_1.generateExecuteArgs)({ desiredTxns: txns })];
case 2:
_c = _d.sent(), methodDataToValidate = _c.methodDataToValidate, executeArgs = _c.executeArgs;
_c = _d.sent(), methodDataToValidate = _c.methodDataToValidate, executeArgs = _c.executeArgs, totalAttachedYocto = _c.totalAttachedYocto, totalGasForTxns = _c.totalGasForTxns;
return [4 /*yield*/, (0, utils_1.validateDesiredMethods)({ methodData: methodDataToValidate, trialAccountId: trialAccountId })];
case 3:
isValidTxn = _d.sent();
console.log('isValidTxn: ', isValidTxn);
if (isValidTxn == false) {
throw utils_1.TRIAL_ERRORS.INVALID_ACTION;
}
return [4 /*yield*/, (0, utils_1.hasEnoughBalance)({ trialAccountId: trialAccountId, totalAttachedYocto: totalAttachedYocto, totalGasForTxns: totalGasForTxns })];
case 4:
hasBal = _d.sent();
if (hasBal == false) {
throw utils_1.TRIAL_ERRORS.INSUFFICIENT_BALANCE;
}
trialKeyPair = near_api_js_1.KeyPair.fromString(trialAccountSecretKey);
pubKey = trialKeyPair.getPublicKey();
return [4 /*yield*/, keyStore.setKey(networkId, trialAccountId, trialKeyPair)];
case 4:
case 5:
_d.sent();
return [4 /*yield*/, near.account(trialAccountId)];
case 5:
case 6:
account = _d.sent();
gasToAttach = (0, utils_1.estimateTrialGas)({ executeArgs: executeArgs });
return [4 /*yield*/, (0, keypom_utils_1.createTransactions)({
Expand All @@ -317,13 +329,13 @@ var trialCallMethod = function (_a) {
}]
}]
})];
case 6:
case 7:
transformedTransactions = _d.sent();
console.log("debugging");
console.log('transformedTransactions: ', transformedTransactions);
promises = transformedTransactions.map(function (tx) { return account.signAndSendTransaction(tx); });
return [4 /*yield*/, Promise.all(promises)];
case 7: return [2 /*return*/, _d.sent()];
case 8: return [2 /*return*/, _d.sent()];
}
});
});
Expand Down
8 changes: 8 additions & 0 deletions lib/lib/trial-accounts/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export declare const TRIAL_ERRORS: {
EXIT_EXPECTED: string;
INVALID_ACTION: string;
INSUFFICIENT_BALANCE: string;
};
export declare const validateDesiredMethods: ({ methodData, trialAccountId }: {
methodData: {
Expand Down Expand Up @@ -35,6 +36,8 @@ export declare const generateExecuteArgs: ({ desiredTxns }: {
}[];
}[];
}) => {
totalAttachedYocto: any;
totalGasForTxns: any;
executeArgs: any;
methodDataToValidate: any;
};
Expand Down Expand Up @@ -65,3 +68,8 @@ export declare const isUnclaimedTrialDrop: ({ keypomContractId, secretKey }: {
keypomContractId: any;
secretKey: any;
}) => Promise<boolean>;
export declare const hasEnoughBalance: ({ trialAccountId, totalGasForTxns, totalAttachedYocto }: {
trialAccountId: string;
totalGasForTxns: string;
totalAttachedYocto: string;
}) => Promise<any>;
Loading

0 comments on commit 4a3d7c4

Please sign in to comment.