Skip to content

Commit

Permalink
Fixed most of the manual errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis-sqa committed Feb 4, 2022
1 parent 272ef8d commit d192319
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 37 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
lib/
example/
example/
jest.config.ts
9 changes: 6 additions & 3 deletions __tests__/example.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React from "react";
import { render } from "@testing-library/react";


it("works", () => {
const component = render(<div><span>Hello World!</span></div>);
const component = render(
<div>
<span>Hello World!</span>
</div>
);
const text = component.getByText("Hello World!");

expect(text).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion jest.init.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Add custom matches specifically related to DOM assertions.
// More info here: https://testing-library.com/docs/ecosystem-jest-dom/
import "@testing-library/jest-dom";
import "@testing-library/jest-dom";
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const config: PlaywrightTestConfig = {
testMatch: /.*\.e2e\.ts/,
timeout: 30 * 1000,
expect: {
timeout: 5000
timeout: 5000,
},
forbidOnly: runningInCI,
retries: runningInCI ? 2 : 0,
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/WalletController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class WalletController {
return null;
}

on(event: EventList, callback: () => {}) {
on(event: EventList, callback: () => void) {
this.emitter.on(event, callback);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/NearWalletSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class NearWalletSelector {
return this.walletController.getAccount();
}

on(event: EventList, callback: () => {}) {
on(event: EventList, callback: () => void) {
this.emitter.on(event, callback);
}
}
14 changes: 7 additions & 7 deletions src/modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,11 @@ function Modal(): JSX.Element {
const [state, setState] = useState(getState());

useEffect(() => {
window.updateWalletSelector = (state) => {
setState(state);
window.updateWalletSelector = (nextState) => {
setState(nextState);
};
}, []);

function handleCloseModal(event: any) {
event.preventDefault();
if (event.target === event.currentTarget) onCloseModalHandler();
}

function onCloseModalHandler() {
updateState((prevState) => ({
...prevState,
Expand All @@ -44,6 +39,11 @@ function Modal(): JSX.Element {
setWalletInfoVisible(false);
}

function handleCloseModal(event: any) {
event.preventDefault();
if (event.target === event.currentTarget) onCloseModalHandler();
}

function getThemeClass(theme: string | null) {
let themeClass = "";
switch (theme) {
Expand Down
6 changes: 3 additions & 3 deletions src/types/CustomWalletOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ type CustomWalletOptions = {
name: string;
description: string;
icon: string;
onConnectFunction: Function;
onDisconnectFunction: Function;
isConnectedFunction: Function;
onConnectFunction: () => void;
onDisconnectFunction: () => void;
isConnectedFunction: () => boolean;
};

export default CustomWalletOptions;
8 changes: 4 additions & 4 deletions src/utils/EventsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ type EventMap = Record<EventList, unknown>;
type EventKey = keyof EventMap;

export interface Emitter<T extends EventMap = EventMap> {
on<K extends EventKey>(eventName: K, callback: () => {}): void;
on<K extends EventKey>(eventName: K, callback: () => void): void;

off<K extends EventKey>(eventName: K, callback: () => {}): void;
off<K extends EventKey>(eventName: K, callback: () => void): void;

emit<K extends EventKey>(eventName: K, params?: T[K]): void;
}

export class EventHandler<T extends EventMap> implements Emitter<T> {
private emitter = new EventEmitter();
on<K extends EventKey>(eventName: K, callback: () => {}) {
on<K extends EventKey>(eventName: K, callback: () => void) {
this.emitter.on(eventName, callback);
}

off<K extends EventKey>(eventName: K, callback: () => {}) {
off<K extends EventKey>(eventName: K, callback: () => void) {
this.emitter.off(eventName, callback);
}

Expand Down
34 changes: 21 additions & 13 deletions src/wallets/CustomWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import BaseWallet from "./BaseWallet";

// TODO: Needs to have CustomWallet for every wallet type, also when developer is adding new wallet a type is needed
export default class CustomWallet extends BaseWallet {
private onConnectFunction: Function;
private onDisconnectFunction: Function;
private isConnectedFunction: Function;
private onConnectFunction: () => void;
private onDisconnectFunction: () => void;
private isConnectedFunction: () => boolean;

constructor(
emitter: Emitter,
id: string,
name: string,
description: string,
icon: string,
onConnectFunction: Function,
onDisconnectFunction: Function,
isConnectedFunction: Function
onConnectFunction: () => void,
onDisconnectFunction: () => void,
isConnectedFunction: () => boolean
) {
super(emitter, id, name, description, icon);

Expand All @@ -24,15 +24,15 @@ export default class CustomWallet extends BaseWallet {
this.setIsConnectedFunction(isConnectedFunction);
}

setOnConnectFunction(onConnectFunction: Function) {
setOnConnectFunction(onConnectFunction: () => void) {
this.onConnectFunction = onConnectFunction;
}

setOnDisconnectFunction(onDisconnectFunction: Function) {
setOnDisconnectFunction(onDisconnectFunction: () => void) {
this.onDisconnectFunction = onDisconnectFunction;
}

setIsConnectedFunction(isConnectedFunction: Function) {
setIsConnectedFunction(isConnectedFunction: () => boolean) {
this.isConnectedFunction = isConnectedFunction;
}

Expand All @@ -52,11 +52,19 @@ export default class CustomWallet extends BaseWallet {
return this.isConnectedFunction();
}

async signIn() {}
async signIn() {
throw new Error("Not implemented");
}

async getAccount() {}
async getAccount() {
throw new Error("Not implemented");
}

async view() {}
async view() {
throw new Error("Not implemented");
}

async call() {}
async call() {
throw new Error("Not implemented");
}
}
15 changes: 13 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true
},
"include": ["src"],
"exclude": ["node_modules", "lib"]
"include": [
"__tests__",
"e2e",
"src",
"jest.config.ts",
"jest.init.ts",
"playwright.config.ts"
],
"exclude": [
"node_modules",
"lib",
"example"
]
}

0 comments on commit d192319

Please sign in to comment.