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

feat(wallets): make wallet provider blockchains prop optional #345

Open
wants to merge 4 commits into
base: next
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@
],
"@typescript-eslint/no-throw-literal": "error",
"@typescript-eslint/no-magic-numbers": [
"error",
"warn",
{
"ignore": [0, 1, 2]
"ignore": [-1, 0, 1, 2, 3, 200]
}
],
"@typescript-eslint/consistent-type-exports": "error",
Expand Down
2 changes: 1 addition & 1 deletion examples/queue-manager-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"bignumber.js": "^9.1.1",
"ethers": "^5.7.2",
"rango-sdk-basic": "^0.1.34",
"rango-types": "^0.1.46"
"rango-types": "^0.1.54"
}
}
2 changes: 1 addition & 1 deletion queue-manager/rango-preset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"dependencies": {
"@sentry/browser": "^6.12.0",
"mitt": "^3.0.0",
"rango-types": "^0.1.46",
"rango-types": "^0.1.54",
"uuid": "^9.0.0"
},
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions queue-manager/rango-preset/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,8 @@ export async function isNetworkMatchedForTransaction(
if (!fromBlockChain) return false;

if (
meta.evmBasedChains.find(
(evmBlochain) => evmBlochain.name === fromBlockChain
Object.values(meta.blockchains).find(
(blockchain) => blockchain.id === fromBlockChain
)
) {
try {
Expand Down
33 changes: 8 additions & 25 deletions queue-manager/rango-preset/src/shared.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Network, WalletType } from '@rango-dev/wallets-shared';
import {
StdBlockchainInfo,
Network,
WalletType,
} from '@rango-dev/wallets-shared';
import {
CosmosTransaction,
EvmTransaction,
Expand All @@ -12,19 +16,12 @@ import {
MetaResponse,
Token,
SwapResult,
BlockchainMeta,
} from 'rango-sdk';

import { PrettyError } from './shared-errors';
import BigNumber from 'bignumber.js';
import { numberToString } from './numbers';
import {
TonTransaction,
isCosmosBlockchain,
isEvmBlockchain,
isStarknetBlockchain,
isTronBlockchain,
} from 'rango-types';
import { TonTransaction } from 'rango-types';

export interface PendingSwapWithQueueID {
id: string;
Expand Down Expand Up @@ -254,27 +251,13 @@ export const getCurrentBlockchainOf = (
return blockchain;
};

const getBlockchainMetaExplorerBaseUrl = (
blockchainMeta: BlockchainMeta
): string | undefined => {
if (isCosmosBlockchain(blockchainMeta))
return blockchainMeta.info?.explorerUrlToTx;
else if (
isEvmBlockchain(blockchainMeta) ||
isStarknetBlockchain(blockchainMeta) ||
isTronBlockchain(blockchainMeta)
)
return blockchainMeta.info.transactionUrl;
return;
};

export const getScannerUrl = (
txHash: string,
network: Network,
blockchainMetaMap: { [key: string]: BlockchainMeta }
blockchainMetaMap: { [key: string]: StdBlockchainInfo }
): string | undefined => {
const blockchainMeta = blockchainMetaMap[network];
const baseUrl = getBlockchainMetaExplorerBaseUrl(blockchainMeta);
const baseUrl = blockchainMeta.transactionUrl;
if (!baseUrl) return;
if (baseUrl.indexOf('/{txHash}') !== -1)
return baseUrl.replace('{txHash}', txHash?.toLowerCase());
Expand Down
2 changes: 1 addition & 1 deletion signers/signer-cosmos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@keplr-wallet/cosmos": "^0.9.12",
"cosmjs-types": "^0.5.2",
"long": "^5.2.1",
"rango-types": "^0.1.46"
"rango-types": "^0.1.54"
},
"devDependencies": {
"@keplr-wallet/types": "^0.9.12"
Expand Down
2 changes: 1 addition & 1 deletion signers/signer-evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@ethersproject/abstract-provider": "^5.7.0",
"eth-rpc-errors": "^4.0.3",
"ethers": "^5.7.2",
"rango-types": "^0.1.46"
"rango-types": "^0.1.54"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion signers/signer-solana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"@solana/web3.js": "^1.67.2",
"rango-types": "^0.1.46"
"rango-types": "^0.1.54"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion signers/signer-starknet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"lint": "eslint \"**/*.{ts,tsx}\" --ignore-path ../../.eslintignore"
},
"dependencies": {
"rango-types": "^0.1.46"
"rango-types": "^0.1.54"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion signers/signer-terra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"@terra-money/terra.js": "^3.1.7",
"rango-types": "^0.1.46"
"rango-types": "^0.1.54"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion signers/signer-tron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"lint": "eslint \"**/*.{ts,tsx}\" --ignore-path ../../.eslintignore"
},
"dependencies": {
"rango-types": "^0.1.46"
"rango-types": "^0.1.54"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion wallets/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"dependencies": {
"@rango-dev/wallets-shared": "^0.15.1-next.1",
"rango-types": "^0.1.46"
"rango-types": "^0.1.54"
},
"publishConfig": {
"access": "public"
Expand Down
16 changes: 8 additions & 8 deletions wallets/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Network, WalletType, WalletInfo } from '@rango-dev/wallets-shared';
import { State as WalletState } from './wallet';
import { SignerFactory, BlockchainMeta } from 'rango-types';
import { SignerFactory, StdBlockchainInfo } from 'rango-types';

export type State = {
[key: string]: WalletState | undefined;
Expand Down Expand Up @@ -31,7 +31,7 @@ export type ProviderConnectResult = {
export type GetInstanceOptions = {
network?: Network;
currentProvider: any;
meta: BlockchainMeta[];
meta: StdBlockchainInfo[];
getState: () => WalletState;
/**
* We always get the instance once and reuse it whenever we needs. By using this option
Expand All @@ -54,7 +54,7 @@ export type TryGetInstance =
export type Connect = (options: {
instance: any;
network?: Network;
meta: BlockchainMeta[];
meta: StdBlockchainInfo[];
}) => Promise<ProviderConnectResult | ProviderConnectResult[]>;

export type Disconnect = (options: {
Expand All @@ -65,7 +65,7 @@ export type Disconnect = (options: {
export type Subscribe = (options: {
instance: any;
state: WalletState;
meta: BlockchainMeta[];
meta: StdBlockchainInfo[];
updateChainId: (chainId: string) => void;
updateAccounts: (accounts: string[], chainId?: string) => void;
connect: (network?: Network) => void;
Expand All @@ -75,19 +75,19 @@ export type Subscribe = (options: {
export type SwitchNetwork = (options: {
instance: any;
network: Network;
meta: BlockchainMeta[];
meta: StdBlockchainInfo[];
newInstance?: TryGetInstance;
}) => Promise<void>;

export type CanSwitchNetwork = (options: {
network: Network;
meta: BlockchainMeta[];
meta: StdBlockchainInfo[];
provider: any;
}) => boolean;

export type CanEagerConnect = (options: {
instance: any;
meta: BlockchainMeta[];
meta: StdBlockchainInfo[];
}) => Promise<boolean>;

export interface WalletActions {
Expand All @@ -102,7 +102,7 @@ export interface WalletActions {
getSigners: (provider: any) => SignerFactory;
canSwitchNetworkTo?: CanSwitchNetwork;
canEagerConnect?: CanEagerConnect;
getWalletInfo(allBlockChains: BlockchainMeta[]): WalletInfo;
getWalletInfo(allBlockChains: StdBlockchainInfo[]): WalletInfo;
}

export interface WalletConfig {
Expand Down
12 changes: 6 additions & 6 deletions wallets/core/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import {
Networks,
WalletType,
} from '@rango-dev/wallets-shared';
import { StdBlockchainInfo } from 'rango-types';
import { accountAddressesWithNetwork, needsCheckInstallation } from './helpers';
import {
Events,
GetInstanceOptions,
WalletActions,
WalletConfig,
} from './types';
import { BlockchainMeta } from 'rango-types';

export type EventHandler = (
type: WalletType,
event: Events,
value: any,
coreState: State,
supportedChains: BlockchainMeta[]
supportedChains: StdBlockchainInfo[]
) => void;

export interface State {
Expand All @@ -39,7 +39,7 @@ class Wallet<InstanceType = any> {
private actions: WalletActions;
private state: State;
private options: Options;
private meta: BlockchainMeta[];
private meta: StdBlockchainInfo[];
public provider: InstanceType | null;

constructor(options: Options, actions: WalletActions) {
Expand Down Expand Up @@ -242,7 +242,7 @@ class Wallet<InstanceType = any> {
getSigners(provider: any) {
return this.actions.getSigners(provider);
}
getWalletInfo(allBlockChains: BlockchainMeta[]) {
getWalletInfo(allBlockChains: StdBlockchainInfo[]) {
return this.actions.getWalletInfo(allBlockChains);
}
canSwitchNetworkTo(network: Network, provider: any) {
Expand Down Expand Up @@ -297,7 +297,7 @@ class Wallet<InstanceType = any> {
}
}

setMeta(value: BlockchainMeta[]) {
setMeta(value: StdBlockchainInfo[]) {
this.meta = value;
}

Expand Down Expand Up @@ -385,7 +385,7 @@ class Wallet<InstanceType = any> {
force?: boolean;
}) {
let instance = null;
// For switching network on Trust Wallet (WalletConnect),
// For switching network on WalletConnect,
// We only kill the session (and not restting the whole state)
// So we are relying on this.provider for achieving this functionality.
this.setProvider(null);
Expand Down
2 changes: 1 addition & 1 deletion wallets/provider-argentx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@rango-dev/signer-starknet": "^0.15.0",
"@rango-dev/wallets-shared": "^0.15.1-next.1",
"rango-types": "^0.1.46"
"rango-types": "^0.1.54"
},
"publishConfig": {
"access": "public"
Expand Down
22 changes: 14 additions & 8 deletions wallets/provider-argentx/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import type {
CanEagerConnect,
CanSwitchNetwork,
Connect,
StdBlockchainInfo,
Subscribe,
WalletInfo,
} from '@rango-dev/wallets-shared';
import type { BlockchainMeta, SignerFactory } from 'rango-types';
import type { SignerFactory } from 'rango-types';

import { Networks, WalletTypes } from '@rango-dev/wallets-shared';
import { starknetBlockchain } from 'rango-types';
import {
filterBlockchains,
Networks,
WalletTypes,
} from '@rango-dev/wallets-shared';

import { argentx as argentx_instances } from './helpers';
import signer from './signer';
Expand Down Expand Up @@ -61,10 +65,12 @@ export const getSigners: (provider: any) => SignerFactory = signer;
export const canEagerConnect: CanEagerConnect = ({ instance }) =>
instance.isPreauthorized();

export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
allBlockChains
) => {
const starknet = starknetBlockchain(allBlockChains);
export const getWalletInfo: (
allBlockChains: StdBlockchainInfo[]
) => WalletInfo = (allBlockChains) => {
const blockchains = filterBlockchains(allBlockChains, {
ids: [Networks.STARKNET],
});
return {
name: 'ArgentX',
img: 'https://raw.githubusercontent.com/rango-exchange/rango-assets/main/wallets/argentx/icon.svg',
Expand All @@ -78,6 +84,6 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
},

color: '#96e7ed',
supportedChains: starknet,
supportedBlockchains: blockchains,
};
};
2 changes: 1 addition & 1 deletion wallets/provider-binance-chain-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@binance-chain/javascript-sdk": "^4.1.1",
"@rango-dev/signer-evm": "^0.15.1-next.0",
"@rango-dev/wallets-shared": "^0.15.1-next.1",
"rango-types": "^0.1.46"
"rango-types": "^0.1.54"
},
"publishConfig": {
"access": "public"
Expand Down
Loading