forked from near/wallet-selector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from luoquanquan/feat/integrate-okx-wallet
Feat/integrate okx wallet
- Loading branch information
Showing
21 changed files
with
713 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@nrwl/js/babel", | ||
{ | ||
"useBuiltIns": "usage" | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# @near-wallet-selector/okx-wallet | ||
|
||
This is the [OKX Wallet](https://chromewebstore.google.com/detail/%E6%AC%A7%E6%98%93-web3-%E9%92%B1%E5%8C%85/mcohilncbfahbmgdjkbpemcciiolgcge) package for NEAR Wallet Selector. | ||
|
||
## Install OKX Wallet | ||
|
||
- [Chrome](https://chromewebstore.google.com/detail/%E6%AC%A7%E6%98%93-web3-%E9%92%B1%E5%8C%85/mcohilncbfahbmgdjkbpemcciiolgcge) | ||
- [Safari](https://apps.apple.com/us/app/okx-wallet/id6463797825) | ||
- [Edge](https://microsoftedge.microsoft.com/addons/detail/%E6%AC%A7%E6%98%93-web3-%E9%92%B1%E5%8C%85/pbpjkcldjiffchgbbndmhojiacbgflha) | ||
|
||
## Installation and Usage | ||
|
||
The easiest way to use this package is to install it from the NPM registry, this package requires `near-api-js` v1.0.0 or above: | ||
|
||
```bash | ||
# Using Yarn | ||
yarn add near-api-js | ||
|
||
# Using NPM. | ||
npm install near-api-js | ||
``` | ||
```bash | ||
# Using Yarn | ||
yarn add @near-wallet-selector/okx-wallet | ||
|
||
# Using NPM. | ||
npm install @near-wallet-selector/okx-wallet | ||
``` | ||
|
||
Then use it in your dApp: | ||
|
||
```ts | ||
import { setupWalletSelector } from "@near-wallet-selector/core"; | ||
import { setupOKXWallet } from "@near-wallet-selector/okx-wallet"; | ||
|
||
// OKX Wallet for Wallet Selector can be setup without any params or it can take few optional params, see options below. | ||
const okxWallet = setupOKXWallet({ | ||
iconUrl: "https://<Wallet Icon URL Here>" // optional | ||
}); | ||
|
||
const selector = await setupWalletSelector({ | ||
network: "mainnet", // OKX Wallet only supports NEAR Mainnet at the moment. | ||
modules: [okxWallet], | ||
}); | ||
``` | ||
|
||
## Options | ||
|
||
- `iconUrl`: (`string?`): Image URL for the icon shown in the modal. This can also be a relative path or base64 encoded image. Defaults is `./assets/okx-wallet.png`. | ||
- `deprecated`: (`boolean?`): Deprecated is optional. Default is `false`. | ||
|
||
## Assets | ||
|
||
Assets such as icons can be found in the `/assets` directory of the package. Below is an example using Webpack: | ||
|
||
```ts | ||
import { setupOKXWallet } from "@near-wallet-selector/okx-wallet"; | ||
import okxIconUrl from "@near-wallet-selector/okx-wallet/assets/okx-wallet.png"; | ||
|
||
const okxWallet = setupOKXWallet({ | ||
iconUrl: okxIconUrl | ||
}); | ||
``` | ||
|
||
## Tip | ||
|
||
OKX Wallet only supports NEAR Mainnet at the moment. | ||
|
||
## License | ||
|
||
This repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0). |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: "okx-wallet", | ||
preset: "../../jest.preset.js", | ||
globals: {}, | ||
transform: { | ||
"^.+\\.[tj]s$": [ | ||
"ts-jest", | ||
{ | ||
tsconfig: "<rootDir>/tsconfig.spec.json", | ||
}, | ||
], | ||
}, | ||
moduleFileExtensions: ["ts", "tsx", "js", "jsx"], | ||
coverageDirectory: "../../coverage/packages/okx-wallet", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "@near-wallet-selector/okx-wallet", | ||
"version": "1.0.0", | ||
"description": "OKX Wallet package for NEAR Wallet Selector.", | ||
"keywords": [ | ||
"near", | ||
"blockchain", | ||
"wallets", | ||
"dapps", | ||
"near-protocol", | ||
"near-blockchain", | ||
"wallet selector", | ||
"injected wallet", | ||
"okx wallet" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/near/wallet-selector.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/near/wallet-selector/issues" | ||
}, | ||
"homepage": "https://github.com/near/wallet-selector/tree/main/packages/okx-wallet", | ||
"peerDependencies": { | ||
"near-api-js": "^1.0.0 || ^2.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"name": "okx-wallet", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/okx-wallet/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nrwl/rollup:rollup", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/packages/okx-wallet", | ||
"tsConfig": "packages/okx-wallet/tsconfig.lib.json", | ||
"project": "packages/okx-wallet/package.json", | ||
"entryFile": "packages/okx-wallet/src/index.ts", | ||
"buildableProjectDepsInPackageJsonType": "dependencies", | ||
"compiler": "babel", | ||
"format": ["esm", "cjs"], | ||
"assets": [ | ||
{ | ||
"glob": "packages/okx-wallet/README.md", | ||
"input": ".", | ||
"output": "." | ||
}, | ||
{ | ||
"glob": "packages/okx-wallet/assets/*", | ||
"input": ".", | ||
"output": "assets" | ||
} | ||
] | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["packages/okx-wallet/**/*.ts"] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/packages/okx-wallet"], | ||
"options": { | ||
"jestConfig": "packages/okx-wallet/jest.config.ts", | ||
"passWithNoTests": true | ||
} | ||
}, | ||
"deploy": { | ||
"executor": "ngx-deploy-npm:deploy", | ||
"options": { | ||
"access": "public" | ||
}, | ||
"dependsOn": ["^deploy"] | ||
} | ||
}, | ||
"tags": ["injected-wallet"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { setupOKXWallet } from "./lib/okx-wallet"; | ||
export type { OKXWalletParams } from "./lib/okx-wallet"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQ4AAAEOCAYAAAB4sfmlAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAsuSURBVHgB7d0/exvXlQfgo6RJJ7rbctRtZ6pLZ6jLVma63YrMJ1i53Grtap+tRH0CSV22it1tKsJdOlFdOkw+AakuqZC5HMCCIP7BIQlyBvd9n+eQtEjJHAzmh3Pv3Bk8id2w19V+V01XXy/+u1nU8vt7AQ+j7ep8pT4sPp8u6jxG7kmM0yT6oPgmPgUGjEUbfYD8vPg8jZEZS3CUbuGoq2+jDwrdA7ukdCDTrn5afG5j4IYcHKthMQmox7SrdzHgEBlicEy6OuzqIHQW8DY+hQiXmHR10tVcKfVFvY++A2dh0tUsxrUTlXqsmkXlATIJHYZSt61ZVDb314TAUOq+6k08wnKEX8fD+s+u/tjVvwZwH8ryhKOufhP9upAH8VBnVZrok3ESwLa0Xb2IBziF+xAdhy4DHsZy7dM/uvpLbNE2g6NsxP909X30bR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CEHx6om+vD4dvHZXcfYJSUcyvLwQYfFqrEEx7pJ9Kdzv1l8bgLGo40+KH5efJ7GyIw1ONaVDmR/UeXrrxefl9UEPIzz+NQxtIsql12cxqfAGP0iyH8CbFx/Rn8af3IAAAAASUVORK5CYII=`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
export interface AccessKey { | ||
publicKey: string; | ||
secretKey: string; | ||
} | ||
|
||
interface RequestSignInResponse { | ||
accessKey: AccessKey; | ||
accountId: string; | ||
error: string | { type: string }; | ||
} | ||
|
||
export type SignOutResponse = true | { error: string | { type: string } }; | ||
|
||
interface RequestSignInParams { | ||
contractId?: string; | ||
methodNames?: Array<string>; | ||
} | ||
|
||
interface Action { | ||
methodName: string; | ||
args: object; | ||
gas: string; | ||
deposit: string; | ||
} | ||
|
||
interface SignAndSendTransactionParams { | ||
receiverId: string; | ||
actions: Array<Action>; | ||
} | ||
|
||
export interface SignAndSendTransactionResponse { | ||
method: string; | ||
txHash: string; | ||
code: number; | ||
} | ||
|
||
interface Transaction { | ||
receiverId: string; | ||
actions: Array<Action>; | ||
} | ||
|
||
interface RequestSignTransactionsParams { | ||
transactions: Array<Transaction>; | ||
} | ||
|
||
interface RequestSignTransactionsResponse { | ||
txs: Array<{ | ||
signedTx: string; | ||
}>; | ||
} | ||
|
||
export interface OkxEvents { | ||
signIn: () => void; | ||
signOut: () => void; | ||
accountChanged: (changedAccountId: string) => void; | ||
} | ||
|
||
export interface InjectedOkx { | ||
getAccountId: () => string | null; | ||
requestSignIn: ( | ||
params: RequestSignInParams | ||
) => Promise<RequestSignInResponse>; | ||
signOut: () => Promise<SignOutResponse>; | ||
isSignedIn: () => boolean; | ||
on: <Event extends keyof OkxEvents>( | ||
event: Event, | ||
callback: OkxEvents[Event] | ||
) => void; | ||
signTransaction: (params: SignAndSendTransactionParams) => Promise<string>; | ||
requestSignTransactions: ( | ||
params: RequestSignTransactionsParams | ||
) => Promise<RequestSignTransactionsResponse>; | ||
} |
Oops, something went wrong.