-
Notifications
You must be signed in to change notification settings - Fork 162
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
feat: Default Wallets Module #379
Changes from 18 commits
c740b68
f1a7958
7f05261
d58d995
2d6e887
ebcb989
9abd721
ddfd11c
b1d660e
6ff46b2
df5f4d2
b10f628
145eadc
34f08c6
cb2bf03
afa1b4e
1a868db
2b86d85
0003c75
c74d9f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@nrwl/web/babel", | ||
{ | ||
"useBuiltIns": "usage" | ||
} | ||
] | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# @near-wallet-selector/default-wallets | ||
|
||
This is the Default Wallets package for NEAR Wallet Selector. | ||
|
||
This is the list of default wallets: | ||
|
||
- [My NEAR Wallet](https://www.npmjs.com/package/@near-wallet-selector/my-near-wallet) - Browser wallet. | ||
- [Ledger](https://www.npmjs.com/package/@near-wallet-selector/ledger) - Hardware wallet. | ||
- [WalletConnect](https://www.npmjs.com/package/@near-wallet-selector/wallet-connect) - Bridge wallet. | ||
|
||
|
||
## Installation and Usage | ||
|
||
The easiest way to use this package is to install it from the NPM registry, this package requires `near-api-js` v0.44.2 or above: | ||
|
||
```bash | ||
# Using Yarn | ||
yarn add near-api-js@^0.44.2 | ||
|
||
# Using NPM. | ||
npm install near-api-js@^0.44.2 | ||
``` | ||
```bash | ||
# Using Yarn | ||
yarn add @near-wallet-selector/default-wallets | ||
|
||
# Using NPM. | ||
npm install @near-wallet-selector/default-wallets | ||
``` | ||
|
||
Then use it in your dApp: | ||
|
||
```ts | ||
import { setupWalletSelector } from "@near-wallet-selector/core"; | ||
import { setupDefaultWallets } from "@near-wallet-selector/default-wallets"; | ||
|
||
const selector = await setupWalletSelector({ | ||
network: "testnet", | ||
modules: await setupDefaultWallets(), | ||
}); | ||
``` | ||
|
||
|
||
## Options | ||
|
||
The `setupDefaultWallets` does not take any options. </br> | ||
To customize any of the default wallets listed above, follow these steps for example customize setup for WalletConnect: | ||
|
||
>**Note**: In this case the customized wallet setup function must be placed before the `setupDefaultWallets` call. | ||
|
||
**Example** | ||
|
||
```ts | ||
// The same can be done for MyNearWallet and Ledger too. | ||
import { setupWalletSelector } from "@near-wallet-selector/core"; | ||
import { setupWalletConnect } from "@near-wallet-selector/wallet-connect"; | ||
import { setupDefaultWallets } from "@near-wallet-selector/default-wallets"; | ||
|
||
const selector = await setupWalletSelector({ | ||
network: "testnet", | ||
modules: [ | ||
setupWalletConnect({ | ||
projectId: "your-custom-project-id", | ||
metadata: { | ||
name: "NEAR Wallet Selector", | ||
description: "Example dApp used by NEAR Wallet Selector", | ||
url: "https://github.com/near/wallet-selector", | ||
icons: ["https://avatars.githubusercontent.com/u/37784886"], | ||
}, | ||
}), | ||
...(await setupDefaultWallets()) | ||
], | ||
}); | ||
``` | ||
|
||
## License | ||
|
||
This repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: "default-wallets", | ||
preset: "../../jest.preset.js", | ||
globals: { | ||
"ts-jest": { | ||
tsconfig: "<rootDir>/tsconfig.spec.json", | ||
}, | ||
}, | ||
transform: { | ||
"^.+\\.[tj]s$": "ts-jest", | ||
}, | ||
moduleFileExtensions: ["ts", "tsx", "js", "jsx"], | ||
coverageDirectory: "../../coverage/packages/default-wallets", | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "@near-wallet-selector/default-wallets", | ||
"version": "5.1.0" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/default-wallets/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nrwl/web:rollup", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/packages/default-wallets", | ||
"tsConfig": "packages/default-wallets/tsconfig.lib.json", | ||
"project": "packages/default-wallets/package.json", | ||
"entryFile": "packages/default-wallets/src/index.ts", | ||
"buildableProjectDepsInPackageJsonType": "dependencies", | ||
"compiler": "babel", | ||
"format": ["esm", "cjs"], | ||
"assets": [ | ||
{ | ||
"glob": "packages/default-wallets/README.md", | ||
"input": ".", | ||
"output": "." | ||
}, | ||
{ | ||
"glob": "packages/default-wallets/assets/*", | ||
"input": ".", | ||
"output": "assets" | ||
}, | ||
{ | ||
"glob": "**/*", | ||
"input": "packages/my-near-wallet/assets/", | ||
"output": "assets/" | ||
}, | ||
{ | ||
"glob": "**/*", | ||
"input": "packages/ledger/assets/", | ||
"output": "assets/" | ||
}, | ||
{ | ||
"glob": "**/*", | ||
"input": "packages/wallet-connect/assets/", | ||
"output": "assets/" | ||
} | ||
] | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nrwl/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["packages/default-wallets/**/*.ts"] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nrwl/jest:jest", | ||
"outputs": ["coverage/packages/default-wallets"], | ||
"options": { | ||
"jestConfig": "packages/default-wallets/jest.config.ts", | ||
"passWithNoTests": true | ||
} | ||
}, | ||
"deploy": { | ||
"executor": "ngx-deploy-npm:deploy", | ||
"options": { | ||
"access": "public" | ||
} | ||
} | ||
}, | ||
"tags": ["hardware-wallet"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { setupDefaultWallets } from "./lib/default-wallets"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { setupMyNearWallet } from "@near-wallet-selector/my-near-wallet"; | ||
import { setupLedger } from "@near-wallet-selector/ledger"; | ||
import { setupWalletConnect } from "@near-wallet-selector/wallet-connect"; | ||
import type { WalletModuleFactory } from "@near-wallet-selector/core"; | ||
|
||
export const setupDefaultWallets = async (): Promise< | ||
Array<WalletModuleFactory> | ||
> => { | ||
return [ | ||
setupMyNearWallet(), | ||
setupLedger(), | ||
setupWalletConnect({ | ||
projectId: "c8cb6204543639c31aef44ea4837a554", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm -- where did this projectId come from? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is coming from here: https://cloud.walletconnect.com/sign-in . Update: WalletConnect is one of those wallet options that would require a projectId which is different for each dApp. {
projectId: "c8cb6204543639c31aef44ea4837a554",
metadata: {
name: "NEAR Wallet Selector",
description: "Example dApp used by NEAR Wallet Selector",
url: "https://github.com/near/wallet-selector",
icons: ["https://avatars.githubusercontent.com/u/37784886"],
},
} |
||
metadata: { | ||
name: "NEAR Wallet Selector", | ||
description: "Example dApp used by NEAR Wallet Selector", | ||
url: "https://github.com/near/wallet-selector", | ||
icons: ["https://avatars.githubusercontent.com/u/37784886"], | ||
}, | ||
}), | ||
]; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"declaration": true, | ||
"types": [] | ||
}, | ||
"include": ["**/*.ts"], | ||
"exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious as to why this was removed - should we not still be alerting someone if they configure the selector with multiple instances of the same module -- unique
id
values are important because they are used as keys on an objectThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we add 2 wallets with the same id the last one this way will be skipped.
If we don't add
continue
here the initialization of the wallet selector insetupWalletSelector
will fail with the above error.This was done to prevent failing of
setupWalletSelector
when we want to override one of thedefault wallets
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Developers may want to override one of the default wallets in the list to add custom options in the setup function of that specific wallet.