Skip to content
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
13 changes: 7 additions & 6 deletions src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,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
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';

Choose a reason for hiding this comment

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

Why has this line been changed? It has nothing to do with custom node url.

Choose a reason for hiding this comment

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

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;
};

let ENV: string | undefined;

export function getConfig(
  env: string | undefined = ENV ||
    process.env.NEAR_ENV ||
    process.env.REACT_APP_REF_SDK_ENV
): Config {
  ENV = env;

  switch (env) {
    case 'mainnet':
      return {
        networkId: 'mainnet',
        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',
        REF_TOKEN_ID: 'token.v2.ref-finance.near',
        indexerUrl: 'https://indexer.ref.finance',
        explorerUrl: 'https://nearblocks.io',
        REF_DCL_SWAP_CONTRACT_ID: 'dclv2.ref-labs.near',
      };
    case 'testnet':
      return {
        networkId: 'testnet',
        nodeUrl: 'https://rpc.testnet.near.org',
        walletUrl: 'https://wallet.testnet.near.org',
        indexerUrl: 'https://testnet-indexer.ref-finance.com',
        WRAP_NEAR_CONTRACT_ID: 'wrap.testnet',
        REF_FI_CONTRACT_ID: 'ref-finance-101.testnet',
        REF_TOKEN_ID: 'ref.fakes.testnet',
        explorerUrl: 'https://testnet.nearblocks.io',
        REF_DCL_SWAP_CONTRACT_ID: 'dclv2.ref-dev.testnet',
      };
    default:
      return {
        networkId: 'mainnet',
        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',
        REF_TOKEN_ID: 'token.v2.ref-finance.near',
        indexerUrl: 'https://indexer.ref.finance',
        explorerUrl: 'https://nearblocks.io',
        REF_DCL_SWAP_CONTRACT_ID: 'dclv2.ref-labs.near',
      };
  }
}

Key Changes Made:

  • Type Definition: A Config type has been created to define the structure of the returned object.
  • Declaration of ENV: The ENV variable is declared at the top of the file.
  • Return Type: The return type of the getConfig function is explicitly set to Config.

This should ensure that the function runs properly and returns the expected configuration

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 };
};

export const separateRoutes = (
Expand Down