Skip to content

Commit

Permalink
feat: introducing hub, our new wallet management
Browse files Browse the repository at this point in the history
  • Loading branch information
yeager-eren committed Aug 17, 2024
1 parent 4f06666 commit 97222bc
Show file tree
Hide file tree
Showing 69 changed files with 5,262 additions and 381 deletions.
2 changes: 1 addition & 1 deletion examples/queue-manager-demo/src/flows/rango/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type {
} from 'rango-types';

import { SUPPORTED_ETH_CHAINS as XDEFI_WALLET_SUPPORTED_EVM_CHAINS } from '@rango-dev/provider-xdefi';
import { legacyReadAccountAddress as readAccountAddress } from '@rango-dev/wallets-core';
import { legacyReadAccountAddress as readAccountAddress } from '@rango-dev/wallets-core/legacy';
import {
Networks,
WalletTypes,
Expand Down
2 changes: 1 addition & 1 deletion examples/wallets-demo/src/components/List/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Tooltip,
Typography,
} from '@rango-dev/ui';
import { legacyReadAccountAddress as readAccountAddress } from '@rango-dev/wallets-core';
import { legacyReadAccountAddress as readAccountAddress } from '@rango-dev/wallets-core/legacy';
import { useWallets } from '@rango-dev/wallets-react';
import { detectInstallLink, Networks } from '@rango-dev/wallets-shared';
import React, { useState } from 'react';
Expand Down
2 changes: 1 addition & 1 deletion examples/wallets-demo/src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Network } from '@rango-dev/wallets-shared';
import type { BlockchainMeta } from 'rango-sdk';

import { legacyReadAccountAddress as readAccountAddress } from '@rango-dev/wallets-core';
import { legacyReadAccountAddress as readAccountAddress } from '@rango-dev/wallets-core/legacy';
import { Networks } from '@rango-dev/wallets-shared';
import { isEvmBlockchain } from 'rango-sdk';

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
"@vercel/routing-utils": "^3.1.0",
"@vitest/coverage-v8": "^0.33.0",
"@vitest/coverage-v8": "^2.0.5",
"buffer": "^5.5.0",
"chalk": "^5.2.0",
"command-line-args": "^5.2.1",
Expand Down Expand Up @@ -113,7 +113,7 @@
"stream-browserify": "^3.0.0",
"tty-browserify": "^0.0.1",
"util": "^0.12.3",
"vitest": "^0.33.0",
"vitest": "^2.0.5",
"vm-browserify": "^1.1.2"
},
"resolutions": {
Expand Down
27 changes: 24 additions & 3 deletions wallets/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,47 @@
"./legacy": {
"types": "./dist/legacy/mod.d.ts",
"default": "./dist/legacy/mod.js"
},
"./utils": {
"types": "./dist/utils/mod.d.ts",
"default": "./dist/utils/mod.js"
},
"./namespaces/common": {
"types": "./dist/namespaces/common/mod.d.ts",
"default": "./dist/namespaces/common/mod.js"
},
"./namespaces/evm": {
"types": "./dist/namespaces/evm/mod.d.ts",
"default": "./dist/namespaces/evm/mod.js"
},
"./namespaces/solana": {
"types": "./dist/namespaces/solana/mod.d.ts",
"default": "./dist/namespaces/solana/mod.js"
}
},
"files": [
"dist",
"src"
],
"scripts": {
"build": "node ../../scripts/build/command.mjs --path wallets/core --inputs src/mod.ts,src/legacy/mod.ts",
"build": "node ../../scripts/build/command.mjs --path wallets/core --inputs src/mod.ts,src/utils/mod.ts,src/legacy/mod.ts,src/namespaces/evm/mod.ts,src/namespaces/solana/mod.ts,src/namespaces/common/mod.ts",
"ts-check": "tsc --declaration --emitDeclarationOnly -p ./tsconfig.json",
"clean": "rimraf dist",
"format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
"lint": "eslint \"**/*.{ts,tsx}\" --ignore-path ../../.eslintignore"
"lint": "eslint \"**/*.{ts,tsx}\" --ignore-path ../../.eslintignore",
"test": "vitest",
"coverage": "vitest run --coverage"
},
"peerDependencies": {
"@types/react": "^17.0.0 || ^18.0.0",
"react": "^17.0.0 || ^18.0.0",
"react-dom": "^17.0.0 || ^18.0.0"
},
"dependencies": {
"rango-types": "^0.1.69"
"caip": "^1.1.1",
"immer": "^10.0.4",
"rango-types": "^0.1.69",
"zustand": "^4.5.2"
},
"publishConfig": {
"access": "public"
Expand Down
86 changes: 86 additions & 0 deletions wallets/core/src/builders/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import type { Actions, Context, Operators } from '../hub/namespaces/types.js';
import type { AnyFunction, FunctionWithContext } from '../types/actions.js';

export interface ActionByBuilder<T, Context> {
actionName: keyof T;
and: Operators<T>;
or: Operators<T>;
after: Operators<T>;
before: Operators<T>;
action: FunctionWithContext<T[keyof T], Context>;
}

/*
* TODO:
* Currently, to use this builder you will write something like this:
* new ActionBuilder<EvmActions, 'disconnect'>('disconnect').after(....)
*
* I couldn't figure it out to be able typescript infer the constructor value as key of actions.
* Ideal usage:
* new ActionBuilder<EvmActions>('disconnect').after(....)
*
*/
export class ActionBuilder<T extends Actions<T>, K extends keyof T> {
readonly name: K;
#and: Operators<T> = new Map();
#or: Operators<T> = new Map();
#after: Operators<T> = new Map();
#before: Operators<T> = new Map();
#action: FunctionWithContext<T[keyof T], Context<T>> | undefined;

constructor(name: K) {
this.name = name;
}

public and(action: FunctionWithContext<AnyFunction, Context<T>>) {
if (!this.#and.has(this.name)) {
this.#and.set(this.name, []);
}
this.#and.get(this.name)?.push(action);
return this;
}

public or(action: FunctionWithContext<AnyFunction, Context<T>>) {
if (!this.#or.has(this.name)) {
this.#or.set(this.name, []);
}
this.#or.get(this.name)?.push(action);
return this;
}

public before(action: FunctionWithContext<AnyFunction, Context<T>>) {
if (!this.#before.has(this.name)) {
this.#before.set(this.name, []);
}
this.#before.get(this.name)?.push(action);
return this;
}

public after(action: FunctionWithContext<AnyFunction, Context<T>>) {
if (!this.#after.has(this.name)) {
this.#after.set(this.name, []);
}
this.#after.get(this.name)?.push(action);
return this;
}

public action(action: FunctionWithContext<T[keyof T], Context<T>>) {
this.#action = action;
return this;
}

public build(): ActionByBuilder<T, Context<T>> {
if (!this.#action) {
throw new Error('Your action builder should includes an action.');
}

return {
actionName: this.name,
action: this.#action,
before: this.#before,
after: this.#after,
and: this.#and,
or: this.#or,
};
}
}
5 changes: 5 additions & 0 deletions wallets/core/src/builders/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type { ProxiedNamespace, FindProxiedNamespace } from './types.js';

export { NamespaceBuilder } from './namespace.js';
export { ProviderBuilder } from './provider.js';
export { ActionBuilder } from './action.js';
Loading

0 comments on commit 97222bc

Please sign in to comment.