Skip to content

Commit

Permalink
Merge branch 'release/v0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Luphia1984 committed Jan 17, 2023
2 parents 8201f71 + e694425 commit bcebeb7
Show file tree
Hide file tree
Showing 33 changed files with 2,923 additions and 6,482 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ typings/
# parcel-bundler cache (https://parceljs.org/)
.cache

# Typescript build output
build

# Next.js build output
.next

Expand Down
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 120,
"trailingComma": "all",
"singleQuote": true
}
4 changes: 0 additions & 4 deletions babel.config.js

This file was deleted.

2 changes: 0 additions & 2 deletions build/lunar.js

This file was deleted.

8 changes: 0 additions & 8 deletions build/lunar.js.LICENSE.txt

This file was deleted.

29 changes: 29 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import IAsset from "./src/interfaces/iasset";
import IBlockchain from "./src/interfaces/iblockchain";
import IConnector from "./src/interfaces/iconnector";
import IEnv from "./src/interfaces/ienv";

export class Lunar {
static version: string;
static Blockchains: IBlockchain[];
static Wallets: string[];
static listBlockchain(isTestnet: boolean | undefined): IBlockchain[];
static findBlockchain(chainId: number): IBlockchain;

env: IEnv;
isConnected: boolean;
address: string;
blockchain: IBlockchain;

on(event: string, callback: Function): void;
findConnector({ walletType }: { walletType: string }): IConnector|undefined;
connect({ wallet, blockchain }: { wallet?: string, blockchain?: IBlockchain }): Promise<boolean>;
switchBlockchain({ blockchain }: { blockchain: IBlockchain }): Promise<boolean>;
disconnect(): Promise<boolean>;
getAsset({ contract }: { contract?: string }): Promise<IAsset | undefined>;
getBalance({ contract, address }: { contract?: string, address?: string }): Promise<string>;
getAllowance({ contract, owner, spender }: { contract: string, owner: string, spender: string }): Promise<string>;
getData({ contract, func, params, data }: { contract: string, data?: string, func?: string, params?: string[], state?: string }): Promise<string>;
send({ to, amount, data }: { to: string, amount: number, data:string }): Promise<string>;
interfaceOf({ contract, abi }: { contract: string, abi: any }): Promise<any>;
}
7 changes: 7 additions & 0 deletions jestconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"transform": {
"^.+\\.(t|j)sx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"]
}
5,046 changes: 2,424 additions & 2,622 deletions package-lock.json

Large diffs are not rendered by default.

40 changes: 25 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
{
"name": "@cafeca/lunar",
"version": "0.3.6",
"version": "0.4.0",
"description": "Blockchain Connect Module",
"main": "./build/lunar.js",
"main": "./build/src/index.js",
"types": "./build/src/index.d.ts",
"files": [
"build"
],
"scripts": {
"dev": "webpack --mode development",
"build": "webpack --mode production"
"build": "tsc",
"format": "prettier -write \"src/**/*.ts\" \"src/**/*.js\"",
"lint": "tslint -p tsconfig.json",
"test": "jest --config jestconfig.json",
"version": "npm run format && git add -A src",
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"preversion": "npm run lint"
},
"repository": {
"type": "git",
Expand All @@ -26,17 +36,17 @@
"url": "https://github.com/CAFECA-IO/Lunar/issues"
},
"homepage": "https://github.com/CAFECA-IO/Lunar#readme",
"dependencies": {},
"dependencies": {
"@cafeca/keccak": "^0.8.7",
"bignumber.js": "^9.1.1"
},
"devDependencies": {
"@babel/core": "^7.15.8",
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/preset-env": "^7.15.8",
"@babel/preset-typescript": "^7.15.0",
"babel-loader": "^8.2.3",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"regenerator-runtime": "^0.13.9",
"webpack": "^5.58.1",
"webpack-cli": "^4.9.0"
"@types/jest": "^29.2.5",
"jest": "^29.3.1",
"prettier": "^2.8.2",
"ts-jest": "^29.0.3",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.9.4"
}
}
36 changes: 0 additions & 36 deletions src/connectors/connector.js

This file was deleted.

63 changes: 63 additions & 0 deletions src/connectors/connector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Blockchains, Blockchain } from "../constants/blockchains";
import Wallets from "../constants/wallets";
import IAsset from "../interfaces/iasset";

class Connector {
_isConnected: boolean = false;
_address: string = '0x';
_blockchain: Blockchain = Blockchains.BOLT;
_type: string = Wallets.TideWallet;
_assets: string[] = [];

constructor() {}
get isConnected() {
return this._isConnected;
}
get blockchain() {
return this._blockchain;
}
get address() {
return this._address;
}
get type() {
return this._type;
}
get chainId() {
return this._blockchain.chainId;
}

async init() {}
on(event:Event, callback:Function) {}
async connect({ blockchain }: { blockchain?: Blockchain } = {}): Promise<boolean> {
return true;
}
async switchBlockchain({ blockchain }: { blockchain: Blockchain }): Promise<boolean> {
return true;
}
async disconnect(): Promise<boolean> {
return true;
}
async send({ to, amount, data }: { to: string, amount: number, data:string }): Promise<string> {
return "0x";
}
async getAsset({ contract }: { contract?: string }): Promise<IAsset> {
return { name: '', symbol: '', decimals: 18, totalSupply: '0' };
}
async getAllowance({ contract, owner, spender }: { contract: string, owner: string, spender: string }): Promise<string> {
return '0';
}
async getContractBalance({ contract, address, state }: { contract: string, address: string, state?: string }): Promise<string> {
return "0x";
}
async getBalance({ contract, address, state }: { contract?: string, address?: string, state?: string } = {}): Promise<string> {
return "0x";
}
async getData({ contract, data, func, params, state }: { contract: string, data?: string, func?: string, params?: string[], state?: string }): Promise<string> {
return "0x";
}
async interfaceOf({ contract, abi }: { contract: string, abi: any }): Promise<any> {
return;
}
}

export default Connector;
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import Wallets from '../constants/wallets.js';
import TideWallet from './tidewallet.js';
import ImToken from './imtoken.js';
import Metamask from './metamask.js';
import Connector from './connector.js';

class ConnectorFactory {
static get types() {
return [ 'TideWallet', 'Metamask', 'imToken' ];
}

static create(wallet = '') {
static create(wallet = ''): Connector {
let connector
switch(wallet) {
case Wallets.TideWallet:
Expand Down
26 changes: 0 additions & 26 deletions src/connectors/imtoken.js

This file was deleted.

11 changes: 11 additions & 0 deletions src/connectors/imtoken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Wallets from '../constants/wallets.js';
import SmartContract from '../libs/smartcontract.js';
import Metamask from './metamask.js'

declare let ethereum: any;

class ImToken extends Metamask {
_type = Wallets.imToken;
}

export default ImToken;
Loading

0 comments on commit bcebeb7

Please sign in to comment.