Skip to content

Commit 0d6b75d

Browse files
authored
Merge pull request #42 from blocknative/feature/typescript
Convert to TypeScript
2 parents ad5883a + 6f33100 commit 0d6b75d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1477
-2020
lines changed

.babelrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

.circleci/config.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ jobs:
77
- checkout
88
- restore_cache:
99
keys:
10-
- v1-dependencies-{{ checksum "package.json" }}
11-
- v1-dependencies-
10+
- v1-dependencies-{{ checksum "package.json" }}
11+
- v1-dependencies-
1212
- run: yarn
1313
- run: yarn test
1414
- run: yarn build
@@ -28,13 +28,13 @@ jobs:
2828
- run: sudo npm i -g npm-cli-login
2929
- run: NPM_USER=$NPM_USERNAME NPM_EMAIL=$NPM_EMAIL NPM_PASS=$NPM_PASSWORD npm-cli-login
3030
- run: npm publish --dry-run
31-
- run: gzip -9 ./dist/iife/onboard.js
32-
- run: mv ./dist/iife/onboard.js.gz ./dist/iife/onboard.js
31+
- run: gzip -9 ./dist/bnc-onboard.js
32+
- run: mv ./dist/bnc-onboard.js.gz ./dist/bnc-onboard.js
3333
- run: ls -al
3434
- run: echo export VERSION=`awk '/version/{gsub(/("|",)/,"",$2);print $2};' package.json | sed 's/\./-/g'` >> $BASH_ENV
3535
- run: mkdir /root/project/deploy-temp
3636
- run: mkdir /root/project/deploy-temp/${VERSION}
37-
- run: mv /root/project/dist/iife/*.js /root/project/deploy-temp/${VERSION}/
37+
- run: mv /root/project/dist/*.js /root/project/deploy-temp/${VERSION}/
3838
- run: aws s3 sync /root/project/deploy-temp/${VERSION}/ s3://staging.onboard.blocknative.com/${VERSION}/ --content-type "text/javascript" --content-encoding "gzip" --cache-control "max-age=31536000" --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
3939
deploy_prod:
4040
docker:
@@ -48,13 +48,13 @@ jobs:
4848
- run: sudo npm i -g add npm-cli-login
4949
- run: NPM_USER=$NPM_USERNAME NPM_EMAIL=$NPM_EMAIL NPM_PASS=$NPM_PASSWORD npm-cli-login
5050
- run: npm publish
51-
- run: gzip -9 ./dist/iife/onboard.js
52-
- run: mv ./dist/iife/onboard.js.gz ./dist/iife/onboard.js
51+
- run: gzip -9 ./dist/bnc-onboard.js
52+
- run: mv ./dist/bnc-onboard.js.gz ./dist/bnc-onboard.js
5353
- run: ls -al
5454
- run: echo export VERSION=`awk '/version/{gsub(/("|",)/,"",$2);print $2};' package.json | sed 's/\./-/g'` >> $BASH_ENV
5555
- run: mkdir /root/project/deploy-temp
5656
- run: mkdir /root/project/deploy-temp/${VERSION}
57-
- run: mv /root/project/dist/iife/*.js /root/project/deploy-temp/${VERSION}/
57+
- run: mv /root/project/dist/*.js /root/project/deploy-temp/${VERSION}/
5858
- run: aws s3 sync /root/project/deploy-temp/${VERSION}/ s3://onboard.blocknative.com/${VERSION}/ --content-type "text/javascript" --content-encoding "gzip" --cache-control "max-age=31536000" --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
5959
workflows:
6060
version: 2

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.DS_Store
22
node_modules
3-
dist
4-
settings.json
3+
dist/
4+
package-lock.json
5+
.rpt2_cache

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ JavaScript library to easily onboard users to ethereum apps by enabling wallet s
99
## Quick Start with Default Modules
1010

1111
```javascript
12-
import Onboard from "bn-onboard"
12+
import Onboard from "bnc-onboard"
1313

1414
// initialize onboard
1515
const onboard = Onboard.init({

package.json

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
11
{
22
"name": "bnc-onboard",
33
"version": "0.2.4",
4-
"main": "dist/cjs/index.js",
5-
"module": "dist/esm/index.js",
4+
"description": "Onboard users to web3 by allowing them to select a wallet, get that wallet ready to transact and have access to synced wallet state.",
5+
"keywords": [
6+
"ethereum",
7+
"web3",
8+
"blocknative",
9+
"wallet"
10+
],
11+
"main": "dist/bnc-onboard.js",
12+
"module": "dist/bnc-onboard.es5.js",
13+
"typings": "dist/src/onboard.d.ts",
614
"files": [
7-
"dist/esm/*",
8-
"dist/cjs/*"
15+
"dist"
916
],
10-
"types": "./types.d.ts",
17+
"author": "Aaron Barnard <abarnard@protonmail.com>",
18+
"repository": {
19+
"type": "git",
20+
"url": "https://github.com/blocknative/onboard"
21+
},
1122
"license": "MIT",
1223
"devDependencies": {
13-
"@babel/core": "^7.5.5",
14-
"@babel/preset-env": "^7.5.5",
24+
"@pyoner/svelte-ts-preprocess": "^1.2.1",
25+
"@types/node": "^12.12.3",
1526
"@joseph184/rollup-plugin-node-builtins": "^2.1.4",
16-
"babel-eslint": "^7.1.1",
17-
"babel-plugin-external-helpers": "^6.18.0",
1827
"rollup": "^1.12.0",
19-
"rollup-plugin-babel": "^4.3.3",
2028
"rollup-plugin-commonjs": "^10.0.0",
2129
"rollup-plugin-img": "^1.1.0",
2230
"rollup-plugin-json": "^4.0.0",
23-
"rollup-plugin-livereload": "^1.0.0",
2431
"rollup-plugin-node-globals": "^1.4.0",
2532
"rollup-plugin-node-resolve": "^5.2.0",
2633
"rollup-plugin-svelte": "^5.0.3",
2734
"rollup-plugin-terser": "^4.0.4",
28-
"svelte": "^3.0.0"
35+
"rollup-plugin-typescript2": "0.21.0",
36+
"svelte": "^3.12.1",
37+
"svelte-i18n": "^1.1.2-beta",
38+
"typescript": "^3.6.4"
2939
},
3040
"dependencies": {
3141
"@portis/web3": "^2.0.0-beta.42",
@@ -36,9 +46,7 @@
3646
"bowser": "^2.5.2",
3747
"fortmatic": "^0.8.2",
3848
"promise-cancelable": "^2.1.1",
39-
"regenerator-runtime": "^0.13.3",
40-
"squarelink": "^1.1.3",
41-
"svelte-i18n": "^1.1.2-beta"
49+
"squarelink": "^1.1.3"
4250
},
4351
"scripts": {
4452
"build": "rollup -c",

rollup.config.js

Lines changed: 62 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,74 @@
11
import svelte from "rollup-plugin-svelte"
22
import resolve from "rollup-plugin-node-resolve"
3-
import babel from "rollup-plugin-babel"
4-
import commonjs from "rollup-plugin-commonjs"
5-
import globals from "rollup-plugin-node-globals"
63
import json from "rollup-plugin-json"
74
import image from "rollup-plugin-img"
5+
import commonjs from "rollup-plugin-commonjs"
6+
import globals from "rollup-plugin-node-globals"
87
import builtins from "@joseph184/rollup-plugin-node-builtins"
98
import { terser } from "rollup-plugin-terser"
9+
import typescript from "rollup-plugin-typescript2"
10+
11+
import {
12+
preprocess,
13+
createEnv,
14+
readConfigFile
15+
} from "@pyoner/svelte-ts-preprocess"
16+
17+
const env = createEnv()
18+
const compilerOptions = readConfigFile(env)
19+
const opts = {
20+
env,
21+
compilerOptions: {
22+
...compilerOptions,
23+
allowNonTsExtensions: true
24+
}
25+
}
1026

1127
export default [
1228
{
13-
input: "src/index.js",
29+
input: "src/onboard.ts",
1430
output: {
15-
format: "iife",
31+
sourcemap: true,
32+
format: "umd",
1633
name: "onboard",
17-
file: "dist/iife/onboard.js",
18-
esModule: false
34+
file: "dist/bnc-onboard.js"
35+
},
36+
moduleContext: id => {
37+
const thisAsWindowForModules = [
38+
"node_modules/intl-messageformat/lib/core.js",
39+
"node_modules/intl-messageformat/lib/compiler.js"
40+
]
41+
42+
if (thisAsWindowForModules.some(id_ => id.trimRight().endsWith(id_))) {
43+
return "window"
44+
}
1945
},
2046
plugins: [
2147
image(),
2248
json(),
23-
svelte(),
49+
svelte({
50+
preprocess: preprocess(opts)
51+
}),
2452
resolve({
25-
preferBuiltins: true,
2653
browser: true,
54+
preferBuiltins: true,
2755
dedupe: importee =>
2856
importee === "svelte" || importee.startsWith("svelte/")
2957
}),
3058
commonjs(),
3159
globals(),
32-
babel({ exclude: "node_modules/**" }),
3360
builtins(),
61+
typescript(),
3462
terser()
35-
],
63+
]
64+
},
65+
{
66+
input: "src/onboard.ts",
67+
output: {
68+
sourcemap: true,
69+
format: "es",
70+
file: "dist/bnc-onboard.es5.js"
71+
},
3672
moduleContext: id => {
3773
const thisAsWindowForModules = [
3874
"node_modules/intl-messageformat/lib/core.js",
@@ -42,49 +78,31 @@ export default [
4278
if (thisAsWindowForModules.some(id_ => id.trimRight().endsWith(id_))) {
4379
return "window"
4480
}
45-
}
46-
},
47-
{
48-
input: "src/index.js",
81+
},
82+
plugins: [
83+
json(),
84+
image(),
85+
svelte({
86+
preprocess: preprocess(opts)
87+
}),
88+
resolve({
89+
browser: true,
90+
dedupe: importee =>
91+
importee === "svelte" || importee.startsWith("svelte/")
92+
}),
93+
commonjs(),
94+
typescript()
95+
],
4996
external: [
5097
"bowser",
5198
"bnc-sdk",
5299
"bignumber.js",
53100
"promise-cancelable",
54-
"regenerator-runtime/runtime",
55101
"@portis/web3",
56102
"@walletconnect/web3-provider",
57103
"fortmatic",
58104
"squarelink",
59105
"authereum"
60-
],
61-
plugins: [
62-
svelte(),
63-
json(),
64-
image(),
65-
resolve(),
66-
commonjs(),
67-
babel({ exclude: "node_modules/**" })
68-
],
69-
moduleContext: id => {
70-
const thisAsWindowForModules = [
71-
"node_modules/intl-messageformat/lib/core.js",
72-
"node_modules/intl-messageformat/lib/compiler.js"
73-
]
74-
75-
if (thisAsWindowForModules.some(id_ => id.trimRight().endsWith(id_))) {
76-
return "window"
77-
}
78-
},
79-
output: [
80-
{
81-
dir: "dist/esm",
82-
format: "esm"
83-
},
84-
{
85-
dir: "dist/cjs",
86-
format: "cjs"
87-
}
88106
]
89107
}
90108
]

src/@types/images.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare module "*.png"
2+
declare module "*.svg"

src/@types/libraries.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
declare module "promise-cancelable" {
2+
export default class Cancelable extends Promise<any> {
3+
constructor(executor: any)
4+
cancel(): any
5+
isFulfilled(): any
6+
isResolved(): any
7+
isRejected(): any
8+
}
9+
}
10+
declare module "@walletconnect/web3-provider"
11+
declare module "squarelink"
12+
declare module "fortmatic"

src/@types/svelte-i18n.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
declare module 'svelte-i18n' {
2+
interface Options {
3+
fallback: string
4+
navigator: boolean
5+
}
6+
export function getClientLocale(options: Options): string
7+
8+
export namespace _ {
9+
export function subscribe(dictionary: any): void
10+
}
11+
12+
export namespace dictionary {
13+
export function set(dictionary: any): void
14+
}
15+
16+
export namespace locale {
17+
export function set(locale: string): void
18+
}
19+
}

src/components/Modal.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<script>
1+
<script lang="ts">
22
import { fade } from "svelte/transition";
33
import { app } from "../stores";
4-
export let closeModal;
4+
export let closeModal: () => void;
55
6-
let closeHovered;
6+
let closeHovered: boolean;
77
</script>
88

99
<style>

0 commit comments

Comments
 (0)