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 support for custom config #50

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
15 changes: 8 additions & 7 deletions src/constant.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TokenMetadata } from './types';
import { Config, TokenMetadata } from './types';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused, please remove


export const FEE_DIVISOR = 10000;

Expand All @@ -14,15 +14,16 @@ export function getConfig(
env: string | undefined = ENV ||
process.env.NEAR_ENV ||
process.env.REACT_APP_REF_SDK_ENV,
indexerUrl: string | undefined = INDEXER_URL
) {
indexerUrl: string | undefined = INDEXER_URL,
nodeUrl: string | undefined = ""
) {
ENV = env;
INDEXER_URL = indexerUrl;
switch (env) {
case 'mainnet':
return {
networkId: 'mainnet',
nodeUrl: 'https://rpc.mainnet.near.org',
nodeUrl: nodeUrl || 'https://rpc.mainnet.near.org',
walletUrl: 'https://wallet.near.org',
WRAP_NEAR_CONTRACT_ID: 'wrap.near',
REF_FI_CONTRACT_ID: 'v2.ref-finance.near',
Expand All @@ -34,7 +35,7 @@ export function getConfig(
case 'testnet':
return {
networkId: 'testnet',
nodeUrl: 'https://rpc.testnet.near.org',
nodeUrl: nodeUrl || 'https://rpc.testnet.near.org',
walletUrl: 'https://wallet.testnet.near.org',
indexerUrl: indexerUrl || 'https://testnet-indexer.ref-finance.com',
WRAP_NEAR_CONTRACT_ID: 'wrap.testnet',
Expand All @@ -46,7 +47,7 @@ export function getConfig(
case 'dev':
return {
networkId: 'testnet',
nodeUrl: 'https://rpc.testnet.near.org',
nodeUrl: nodeUrl || 'https://rpc.testnet.near.org',
walletUrl: 'https://wallet.testnet.near.org',
indexerUrl: indexerUrl || 'https://dev-indexer.ref-finance.com',
WRAP_NEAR_CONTRACT_ID: 'wrap.testnet',
Expand All @@ -58,7 +59,7 @@ export function getConfig(
default:
return {
networkId: 'mainnet',
nodeUrl: 'https://rpc.mainnet.near.org',
nodeUrl: nodeUrl || 'https://rpc.mainnet.near.org',
walletUrl: 'https://wallet.near.org',
REF_FI_CONTRACT_ID: 'v2.ref-finance.near',
WRAP_NEAR_CONTRACT_ID: 'wrap.near',
Expand Down
5 changes: 3 additions & 2 deletions src/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
TokenMetadata,
FTStorageBalance,
RefFiViewFunctionOptions,
Config,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused, please remove

} from './types';
import { AccountView, CodeResult } from 'near-api-js/lib/providers/provider';
import { Transaction } from './types';
Expand All @@ -47,11 +48,11 @@ let near = new Near({
headers: {},
...getConfig(),
});
export const init_env = (env: string, indexerUrl?: string) => {
export const init_env = (env: string, indexerUrl?: string, nodeUrl?: string) => {
near = new Near({
keyStore: getKeyStore(),
headers: {},
...getConfig(env, indexerUrl),
...getConfig(env, indexerUrl, nodeUrl),
});
return switchEnv();
};
Expand Down
12 changes: 12 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,15 @@ export interface FTStorageBalance {
total: string;
available: string;
}

export type Config = {
networkId: string;
nodeUrl: string;
walletUrl: string;
WRAP_NEAR_CONTRACT_ID: string;
REF_FI_CONTRACT_ID: string;
REF_TOKEN_ID: string;
indexerUrl: string;
explorerUrl: string;
REF_DCL_SWAP_CONTRACT_ID: string;
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused, please remove

3 changes: 1 addition & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
STORAGE_TO_REGISTER_WITH_MFT,
} from './constant';
import Big from 'big.js';
import { SignAndSendTransactionsParams } from '@near-wallet-selector/core/lib/wallet';
import { TokenMetadata } from './types';
import { PoolMode } from './v1-swap/swap';
import { getSwappedAmount } from './stable-swap';
Expand Down Expand Up @@ -289,7 +288,7 @@ export const WalletSelectorTransactions = (
};
});

return { transactions: parsedTransactions } as SignAndSendTransactionsParams;
return { transactions: parsedTransactions };
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure about this one?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Module '"@near-wallet-selector/core/lib/wallet"' has no exported member 'SignAndSendTransactionsParams'.ts(2305)

It was deleted and I can't run npm install it with this line:
near/wallet-selector@65ea358#diff-cf1e42785f014c407e1c8f9672f2d13774005ebee6c4b8b65927b56e0f72ecb0L46

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

export const separateRoutes = (
Expand Down