Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPMify! #91

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ on:
jobs:
build-api:
runs-on: ubuntu-latest


steps:
- uses: actions/checkout@main
- run: |
Expand Down
9 changes: 4 additions & 5 deletions apps/bot/src/commands/Send.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Message } from 'discord.js';
import { Command } from '../Command';
import { BotClient } from '../types';
import { formatNativeTokenAmountToIndivisibleUnit } from '@baf-wallet/multi-chain';
import { createApproveRedirectURL } from '@baf-wallet/redirect-generator';
import { environment } from '../environments/environment';
import { getTokenInfo } from '@baf-wallet/chain-info';
import {
Chain,
GenericTxParams,
GenericTxSupportedActions,
} from '@baf-wallet/interfaces';
import { tokenAmountToIndivisible } from '@baf-wallet/utils';

export default class SendMoney extends Command {
constructor(protected client: BotClient) {
Expand Down Expand Up @@ -72,16 +73,14 @@ export default class SendMoney extends Command {
const recipientUserReadable = `${recipientUser.username}#${recipientUser.discriminator}`;

try {
const nearInfo = await getTokenInfo(Chain.NEAR);
const tx: GenericTxParams = {
recipientUserId: recipientParsed,
recipientUserIdReadable: recipientUserReadable,
actions: [
{
type: GenericTxSupportedActions.TRANSFER,
amount: formatNativeTokenAmountToIndivisibleUnit(
amount,
Chain.NEAR
),
amount: tokenAmountToIndivisible(amount, nearInfo.decimals),
},
],
oauthProvider: 'discord',
Expand Down
12 changes: 6 additions & 6 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ module.exports = {
'<rootDir>/libs/crypto',
'<rootDir>/libs/base-components',
'<rootDir>/libs/errors',
'<rootDir>/libs/t',
'<rootDir>/libs/core-publishable',
],
};
4 changes: 4 additions & 0 deletions libs/baf-contract/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@baf-wallet/baf-contract",
"version": "0.0.5"
}
3 changes: 1 addition & 2 deletions libs/baf-contract/src/lib/baf-contract.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Account, Contract, Near } from 'near-api-js';
import { BafError } from '@baf-wallet/errors';
import ContractConfig from '../../config.json';
import { ec as EC } from 'elliptic';
import {
PublicKey,
RustEncodedSecpSig,
secp256k1,
NearAccountID
} from '@baf-wallet/interfaces';
import { NearAccountID } from '@baf-wallet/near';
import { pkToArray } from '@baf-wallet/crypto';

interface BafContract {
Expand Down
4 changes: 4 additions & 0 deletions libs/chain-info/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@baf-wallet/chain-info",
"version": "0.0.9"
}
12 changes: 6 additions & 6 deletions libs/chain-info/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios';
import { BafError } from '@baf-wallet/errors';
import 'reflect-metadata';
import { jsonObject, jsonMember, TypedJSON, jsonArrayMember } from 'typedjson';
import { Chain } from '@baf-wallet/interfaces';
import { Chain, ChainAsType } from '@baf-wallet/interfaces';

const baseRawUrl = 'https://raw.githubusercontent.com/bafnetwork/assets/master';
const contentsApiUrl =
Expand Down Expand Up @@ -49,7 +49,7 @@ class _TokenInfo {
}

export interface TokenInfo extends _TokenInfo {
chain: Chain;
chain: Chain | ChainAsType;
}

// TODO: have some intelligent way to get the rest
Expand Down Expand Up @@ -87,16 +87,16 @@ export type DappUrl =
| 'uniswap.exchange'
| 'yearn.finance';

export const getChainFolderPrefix = (chain: Chain): string =>
export const getChainFolderPrefix = (chain: Chain | ChainAsType): string =>
`${baseRawUrl}/blockchains/${chain}`;

const getNonNativeTokenInfoUrl = (
chain: Chain,
chain: Chain | ChainAsType,
contractAddress: string
): string =>
`${getChainFolderPrefix(chain)}/assets/${contractAddress}/info.json`;

const getChainInfoUrl = (chain: Chain): string =>
const getChainInfoUrl = (chain: Chain | ChainAsType): string =>
`${getChainFolderPrefix(chain)}/info/info.json`;

const getNonNativeTokenLogoUrl = (
Expand Down Expand Up @@ -137,7 +137,7 @@ export async function getContractAddresses(
}

export async function getTokenInfo(
chain: Chain,
chain: Chain | ChainAsType,
contractAddress?: string
): Promise<TokenInfo> {
const tokenIsChain = chain === contractAddress || !contractAddress;
Expand Down
3 changes: 3 additions & 0 deletions libs/core-publishable/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@nrwl/web/babel"]
}
21 changes: 21 additions & 0 deletions libs/core-publishable/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"parserOptions": {
"project": ["libs/core-publishable/tsconfig.*?.json"]
},
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions libs/core-publishable/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# core-publishable

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test core-publishable` to execute the unit tests via [Jest](https://jestjs.io).
14 changes: 14 additions & 0 deletions libs/core-publishable/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
displayName: 'core-publishable',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsConfig: '<rootDir>/tsconfig.spec.json',
},
},
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/libs/core-publishable',
};
4 changes: 4 additions & 0 deletions libs/core-publishable/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@baf-wallet/core",
"version": "0.0.28"
}
1 change: 1 addition & 0 deletions libs/core-publishable/src/errors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@baf-wallet/errors';
3 changes: 3 additions & 0 deletions libs/core-publishable/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from '@baf-wallet/crypto';
export * from '@baf-wallet/chain-info';
Lev-Stambler marked this conversation as resolved.
Show resolved Hide resolved
export * from '@baf-wallet/multi-chain';
1 change: 1 addition & 0 deletions libs/core-publishable/src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@baf-wallet/interfaces';
1 change: 1 addition & 0 deletions libs/core-publishable/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@baf-wallet/utils';
14 changes: 14 additions & 0 deletions libs/core-publishable/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"compilerOptions": {},
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
11 changes: 11 additions & 0 deletions libs/core-publishable/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"exclude": ["**/*.spec.ts"],
"include": ["**/*.ts"]
}
15 changes: 15 additions & 0 deletions libs/core-publishable/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"**/*.spec.ts",
"**/*.spec.tsx",
"**/*.spec.js",
"**/*.spec.jsx",
"**/*.d.ts"
]
}
4 changes: 4 additions & 0 deletions libs/crypto/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@baf-wallet/crypto",
"version": "0.0.12"
}
2 changes: 1 addition & 1 deletion libs/crypto/src/lib/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export function sha256(msg: Buffer): Buffer {
return Buffer.from(js_sha256(msg), 'hex');
}

// add more wrappers here as needed
// add more wrappers here as we need
4 changes: 3 additions & 1 deletion libs/crypto/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../dist/out-tsc",
"types": []
"declaration": true,
"types": ["node"]
},
"include": ["**/*.ts"],
"exclude": ["**/*.spec.ts"]
Expand Down
12 changes: 12 additions & 0 deletions libs/dist/libs/interfaces/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@baf-wallet/interfaces",
"version": "0.0.12",
"main": "src/index.js",
"typings": "src/index.d.ts",
"dependencies": {
"near-api-js": "^0.39.0",
"buffer": "^5.7.1",
"@toruslabs/torus-direct-web-sdk": "^4.11.1"
},
"peerDependencies": {}
}
4 changes: 4 additions & 0 deletions libs/errors/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@baf-wallet/errors",
"version": "0.0.7"
}
13 changes: 13 additions & 0 deletions libs/interfaces/dist/libs/interfaces/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@baf-wallet/interfaces",
"version": "0.0.3",
"license": "MIT",
"main": "src/index.js",
"typings": "src/index.d.ts",
"dependencies": {
"near-api-js": "^0.39.0",
"buffer": "^5.7.1",
"@toruslabs/torus-direct-web-sdk": "^4.11.1"
},
"peerDependencies": {}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an exports property here so that we can import it like @baf-wallet/core/interfaces instead of having to do @baf-wallet/core/src/interfaces to get interfaces (and similarly for other non-default libs)?

see https://webpack.js.org/guides/package-exports/ for more information

4 changes: 4 additions & 0 deletions libs/interfaces/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@baf-wallet/interfaces",
"version": "0.0.14"
}
2 changes: 2 additions & 0 deletions libs/interfaces/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ export * from './lib/keysource';
export * from './lib/crypto';
export * from './lib/frontend';
export * from './lib/tx';
export * from './lib/misc';
export * from './lib/near'
4 changes: 3 additions & 1 deletion libs/interfaces/src/lib/chains.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { PublicKey, SecretKey, KeyPair, secp256k1, ed25519 } from './crypto';
import { Pair } from '@baf-wallet/utils';
import { Account as NearAccount } from 'near-api-js';
import { GenericTxAction, GenericTxParams } from './tx';
import { Env } from './configs';
import { Pair } from './misc';

export type ChainAsType = 'near' | 'ethereum';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly does this do? Is this for code I wrote a long time ago that expected it to be a type and not a enum?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just to make the api easier for the library. Like you can do tokenInfo('near') instead of Chains.Near

export enum Chain {
NEAR = 'near',
ETHEREUM = 'ethereum',
}

// Or the type with all the supported chain account types
Expand Down
4 changes: 4 additions & 0 deletions libs/interfaces/src/lib/misc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type Pair<T, U> = {
fst: T;
snd: U;
};
1 change: 1 addition & 0 deletions libs/interfaces/src/lib/near.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type NearAccountID = string;
4 changes: 4 additions & 0 deletions libs/multi-chain/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@baf-wallet/multi-chain",
"version": "0.0.1"
}
1 change: 0 additions & 1 deletion libs/multi-chain/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './types';
export * from './switches';
export * from './utils';
Loading