Skip to content

Commit

Permalink
Merge pull request #46 from keypom/ben/modal-cleanup
Browse files Browse the repository at this point in the history
Final Modal Cleanup
  • Loading branch information
BenKurrek authored Apr 21, 2023
2 parents 033dee7 + 81f1816 commit 894c9d1
Show file tree
Hide file tree
Showing 33 changed files with 1,280 additions and 136 deletions.
28 changes: 23 additions & 5 deletions docs-advanced-tutorials/trial-accounts/create-trial-drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,18 @@ async function createTrialAccount() {

// What contracts can the trial account call?
const callableContracts = [
'guest-book.examples.keypom.testnet'
'guest-book.examples.keypom.testnet',
'v1.social08.testnet'
]
// What is the maximum amount of $NEAR that can be attached to a call for each callable contract?
const maxAttachableNEARPerContract = [
'1',
'1'
]
// What methods can the trial account call?
const callableMethods = [
['*'],
['*']
]

const wasmDirectory = `${require('path').resolve(__dirname, '..')}/trial-accounts/ext-wasm/trial-accounts.wasm`
Expand All @@ -56,25 +59,40 @@ async function createTrialAccount() {
numKeys: 1,
contractBytes: [...readFileSync(wasmDirectory)],
// How much $NEAR should be made available to the trial account when it's created?
startingBalanceNEAR: 0.05,
startingBalanceNEAR: 0.5,
callableContracts,
callableMethods,
maxAttachableNEARPerContract,
// repayAmountNEAR: 0.6,
// repayTo: "dennis.near",
// Once the trial account has spent this much $NEAR, the trial will be over.
trialEndFloorNEAR: .01
})
trialEndFloorNEAR: 0.01
})



const guestBookInstance = "http://localhost:1234/keypom-url#"
const keypomContractId = "v2.keypom.testnet"
const delimiter = "/"
const secretKey = keys.secretKeys[0]
const desiredAccountId = `trial-account-${Date.now()}.testnet`

// await keypom.claimTrialAccountDrop({
// secretKey,
// desiredAccountId
// })

const alphaInstance = "http://localhost:3030/#"
const alphaInstance = "http://localhost:3000/#"
const mnwInstance = "https://testnet-preview.mynearwallet.com/linkdrop/"

console.log(`
Guest-Book App:
${guestBookInstance}${keypomContractId}${delimiter}${secretKey}
Alpha:
${alphaInstance}${keypomContractId}${delimiter}${secretKey}
Good Luck!
`)
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class Wallet {
setupKeypom({
trialBaseUrl: "http://localhost:1234/keypom-url#",
networkId: this.network,
trialSplitDelim: "/",
signInContractId: this.createAccessKeyFor,
modalOptions: KEYPOM_OPTIONS
})
Expand Down
9 changes: 8 additions & 1 deletion lib/lib/selector/core/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { InstantLinkWallet, NetworkId, Transaction } from "@near-wallet-selector/core";
import BN from "bn.js";
import { FinalExecutionOutcome } from "near-api-js/lib/providers";
import { BeginTrialCustomizations, InsufficientBalanceCustomizations, InvalidActionCustomizations, OffboardingWallet, TrialOverCustomizations } from "../modal/src/lib/modal.types";
import { KeypomWallet } from "./wallet";
export declare const FAILED_EXECUTION_OUTCOME: FinalExecutionOutcome;
export interface SignInOptions {
Expand All @@ -22,7 +23,13 @@ export interface KeypomParams {
iconUrl?: string;
deprecated?: boolean;
trialSplitDelim?: string;
modalOptions?: any;
modalOptions?: {
wallets: OffboardingWallet[];
beginTrial?: BeginTrialCustomizations;
trialOver?: TrialOverCustomizations;
invalidAction?: InvalidActionCustomizations;
insufficientBalance?: InsufficientBalanceCustomizations;
};
}
export type KeypomWalletInstant = InstantLinkWallet & {
networkId: string;
Expand Down
16 changes: 7 additions & 9 deletions lib/lib/selector/core/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ var utils_1 = require("../../trial-accounts/utils");
var src_1 = require("../modal/src");
var modal_types_1 = require("../modal/src/lib/modal.types");
var selector_utils_1 = require("../utils/selector-utils");
var selector_utils_2 = require("../utils/selector-utils");
var selector_utils_3 = require("../utils/selector-utils");
var types_1 = require("./types");
var KeypomWallet = /** @class */ (function () {
function KeypomWallet(_a) {
Expand All @@ -89,7 +87,7 @@ var KeypomWallet = /** @class */ (function () {
_this.modal.show(modalType);
};
this.checkValidTrialInfo = function () {
return _this.parseUrl() !== undefined || (0, selector_utils_3.getLocalStorageKeypomEnv)() != null;
return _this.parseUrl() !== undefined || (0, selector_utils_1.getLocalStorageKeypomEnv)() != null;
};
console.log('Keypom constructor called.');
this.networkId = networkId;
Expand Down Expand Up @@ -130,7 +128,7 @@ var KeypomWallet = /** @class */ (function () {
parsedData = this.parseUrl();
if (!(parsedData !== undefined)) return [3 /*break*/, 11];
accountId = parsedData.accountId, secretKey = parsedData.secretKey;
isOriginalLink = (0, selector_utils_3.updateKeypomContractIfValid)(accountId);
isOriginalLink = (0, selector_utils_1.updateKeypomContractIfValid)(accountId);
console.log("isOriginalLink: ", isOriginalLink);
if (!isOriginalLink) return [3 /*break*/, 8];
_b.label = 2;
Expand All @@ -142,7 +140,7 @@ var KeypomWallet = /** @class */ (function () {
console.log("isUnclaimed: ", isUnclaimed);
if (!(isUnclaimed === true)) return [3 /*break*/, 4];
this.modal.show({
id: modal_types_1.MODAL_TYPE_IDS.CLAIM_TRIAL,
id: modal_types_1.MODAL_TYPE_IDS.BEGIN_TRIAL,
meta: {
secretKey: secretKey,
redirectUrlBase: this.trialBaseUrl,
Expand All @@ -153,7 +151,7 @@ var KeypomWallet = /** @class */ (function () {
case 4:
// If the drop is claimed, we should attempt to recover the drop
console.log("DROP IS CLAIMED. RECOVERY TODO");
return [4 /*yield*/, (0, selector_utils_2.getAccountFromMap)(secretKey)];
return [4 /*yield*/, (0, selector_utils_1.getAccountFromMap)(secretKey)];
case 5:
accountId = _b.sent();
_b.label = 6;
Expand All @@ -179,7 +177,7 @@ var KeypomWallet = /** @class */ (function () {
console.log('e: ', e_2);
return [3 /*break*/, 11];
case 11:
curEnvData = (0, selector_utils_3.getLocalStorageKeypomEnv)();
curEnvData = (0, selector_utils_1.getLocalStorageKeypomEnv)();
console.log('trial info invalid. Cur env data: ', curEnvData);
// If there is any
if (curEnvData != null) {
Expand All @@ -204,7 +202,7 @@ var KeypomWallet = /** @class */ (function () {
return [4 /*yield*/, this.keyStore.removeKey(this.networkId, this.trialAccountId)];
case 1:
_a.sent();
localStorage.removeItem("".concat(selector_utils_3.KEYPOM_LOCAL_STORAGE_KEY, ":envData"));
localStorage.removeItem("".concat(selector_utils_1.KEYPOM_LOCAL_STORAGE_KEY, ":envData"));
return [2 /*return*/];
}
});
Expand Down Expand Up @@ -345,7 +343,7 @@ var KeypomWallet = /** @class */ (function () {
accountId: accountId,
secretKey: secretKey
};
(0, selector_utils_3.setLocalStorageKeypomEnv)(dataToWrite);
(0, selector_utils_1.setLocalStorageKeypomEnv)(dataToWrite);
return [4 /*yield*/, this.keyStore.setKey(this.networkId, accountId, near_api_js_1.KeyPair.fromString(secretKey))];
case 1:
_a.sent();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
export const ACCOUNT_CHECK_TIMEOUT: 500;
export default AccountFormAccountId;
declare class AccountFormAccountId extends React.Component<any, any, any> {
constructor(props: any);
constructor(props: any, context: any);
state: {
accountId: any;
invalidAccountIdLength: boolean;
wrongChar: boolean;
};
checkAccountAvailabilityTimer: null;
canvas: null;
suffix: React.RefObject<any>;
componentDidMount: () => void;
updateSuffix: (userValue: any) => void;
getTextWidth: (text: any, font: any) => any;
handleChangeAccountId: ({ userValue, el }: {
userValue: any;
el: any;
}) => false | undefined;
checkAccountIdLength: (accountId: any) => boolean;
handleAccountIdLengthState: (accountId: any) => void;
handleCheckAvailability: (accountId: any, type: any) => any;
isImplicitAccount: (accountId: any) => boolean;
get loaderLocalAlert(): {
messageCode: string;
};
get accountIdLengthLocalAlert(): {
success: boolean;
messageCode: string;
};
get sameAccountLocalAlert(): {
success: boolean;
show: boolean;
messageCode: string;
};
get implicitAccountLocalAlert(): {
success: boolean;
messageCode: string;
};
get localAlertWithFormValidation(): any;
render(): JSX.Element;
}
declare namespace AccountFormAccountId {
namespace propTypes {
const handleChange: PropTypes.Validator<(...args: any[]) => any>;
const checkAvailability: PropTypes.Validator<(...args: any[]) => any>;
const defaultAccountId: PropTypes.Requireable<string>;
const autoFocus: PropTypes.Requireable<boolean>;
const accountIdSuffix: PropTypes.Validator<string>;
}
namespace defaultProps {
const autoFocus_1: boolean;
export { autoFocus_1 as autoFocus };
export const pattern: RegExp;
export const type: string;
const accountIdSuffix_1: string;
export { accountIdSuffix_1 as accountIdSuffix };
}
}
import React from "react";
import PropTypes from "prop-types";
Loading

0 comments on commit 894c9d1

Please sign in to comment.