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 node url #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lyomagma
Copy link

No description provided.

@@ -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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants