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

Add okx wallet #1110

Merged
merged 8 commits into from
Jun 14, 2024
Merged
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
5 changes: 5 additions & 0 deletions examples/angular/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
"glob": "**/*",
"input": "packages/near-mobile-wallet/assets/",
"output": "assets/"
},
{
"glob": "**/*",
"input": "packages/okx-wallet/assets/",
"output": "assets/"
}
],
"styles": ["examples/angular/src/styles.scss"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { setupRamperWallet } from "@near-wallet-selector/ramper-wallet";
import { setupLedger } from "@near-wallet-selector/ledger";
import { setupNearMobileWallet } from "@near-wallet-selector/near-mobile-wallet";
import { setupMintbaseWallet } from "@near-wallet-selector/mintbase-wallet";
import { setupOKXWallet } from "@near-wallet-selector/okx-wallet";
import { CONTRACT_ID } from "../../../constants";

declare global {
Expand Down Expand Up @@ -55,6 +56,7 @@ export class WalletSelectorComponent implements OnInit {
network: "testnet",
debug: true,
modules: [
setupOKXWallet(),
setupMyNearWallet(),
setupLedger(),
setupSender(),
Expand Down
2 changes: 2 additions & 0 deletions examples/react/contexts/WalletSelectorContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { setupXDEFI } from "@near-wallet-selector/xdefi";
import { setupRamperWallet } from "@near-wallet-selector/ramper-wallet";
import { setupNearMobileWallet } from "@near-wallet-selector/near-mobile-wallet";
import { setupMintbaseWallet } from "@near-wallet-selector/mintbase-wallet";
import { setupOKXWallet } from "@near-wallet-selector/okx-wallet";

import type { ReactNode } from "react";
import React, {
Expand Down Expand Up @@ -65,6 +66,7 @@ export const WalletSelectorContextProvider: React.FC<{
network: "testnet",
debug: true,
modules: [
setupOKXWallet(),
setupMyNearWallet(),
setupLedger(),
setupSender(),
Expand Down
5 changes: 5 additions & 0 deletions examples/react/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
"glob": "**/*",
"input": "packages/near-mobile-wallet/assets/",
"output": "assets/"
},
{
"glob": "**/*",
"input": "packages/okx-wallet/assets/",
"output": "assets/"
}
]
},
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"welldone-wallet",
"ramper-wallet",
"near-mobile-wallet",
"mintbase-wallet"
"mintbase-wallet",
"okx-wallet"
],
"homepage": "https://github.com/near/wallet-selector#README",
"bugs": {
Expand Down Expand Up @@ -64,6 +65,7 @@
"build:ramper-wallet": "nx run-many --target=build --projects=ramper-wallet --configuration=production",
"build:near-mobile-wallet": "nx run-many --target=build --projects=near-mobile-wallet --configuration=production",
"build:mintbase-wallet": "nx run-many --target=build --projects=mintbase-wallet --configuration=production",
"build:okx-wallet": "nx run-many --target=build --projects=okx-wallet --configuration=production",
"examples:vanillajs:generateimportmap": "(cd examples/vanillajs && jspm link index.html -o index.html)",
"serve:vanillajs": "yarn examples:vanillajs:generateimportmap && http-server -c-1 examples/vanillajs",
"lint": "nx workspace-lint && nx run-many --target=lint --all --parallel",
Expand Down
10 changes: 10 additions & 0 deletions packages/okx-wallet/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"@nrwl/js/babel",
{
"useBuiltIns": "usage"
}
]
]
}
18 changes: 18 additions & 0 deletions packages/okx-wallet/.eslintrc.json
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": {}
}
]
}
71 changes: 71 additions & 0 deletions packages/okx-wallet/README.md
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).
Binary file added packages/okx-wallet/assets/okx-wallet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions packages/okx-wallet/jest.config.ts
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",
};
27 changes: 27 additions & 0 deletions packages/okx-wallet/package.json
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"
}
}
56 changes: 56 additions & 0 deletions packages/okx-wallet/project.json
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"]
}
2 changes: 2 additions & 0 deletions packages/okx-wallet/src/index.ts
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";
1 change: 1 addition & 0 deletions packages/okx-wallet/src/lib/icon.ts
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+jDwrdA7ukdCDTrn5afG5j4IYcHKthMQ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DF9i2adxxYdemtjVUWddGP3QpNz9Or4sHrlWOqe9ii0OTddseqqybdvV/0V+a7+pauLtpV/8WiXtpjN0k+neLmyul0nUSld/K8ygEiFKb1izc+/czR9Hf03QsO1Cph6yTGFBgPNRZlYxJ9CFyGFC3MulZ3qrgXQzsjdGGGBxLTfQhchhaM+oy7eqn6C9IG+RZyCEHx6om+vD4dvHZXcfYJSUcyvLwQYfFqrEEx7pJ9Kdzv1l8bgLGo40+KH5efJ7GyIw1ONaVDmR/UeXrrxefl9UEPIzz+NQxtIsql12cxqfAGP0iyH8CbFx/Rn8af3IAAAAASUVORK5CYII=`;
73 changes: 73 additions & 0 deletions packages/okx-wallet/src/lib/injected-okx-wallet.ts
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>;
}
Loading
Loading