From 7e2565220240abe319c34fcdf54d403cd4d4c17f Mon Sep 17 00:00:00 2001 From: leon mandel Date: Sun, 22 Sep 2024 10:51:42 +0200 Subject: [PATCH 1/5] add support for custom config --- src/constant.ts | 13 ++++++++++--- src/types.ts | 12 ++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/constant.ts b/src/constant.ts index b045b88..a9b0053 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -1,4 +1,4 @@ -import { TokenMetadata } from './types'; +import { Config, TokenMetadata } from './types'; export const FEE_DIVISOR = 10000; @@ -10,12 +10,19 @@ export const FT_MINIMUM_STORAGE_BALANCE_LARGE = "12500000000000000000000" export const ONE_YOCTO_NEAR = '0.000000000000000000000001'; let ENV: string | undefined = ''; let INDEXER_URL: string | undefined = ''; +let CONFIG: Config | undefined = undefined; 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, + custom_config: Config | undefined = CONFIG + ): Config { + if (custom_config) { + CONFIG = custom_config; + return custom_config; + } + { ENV = env; INDEXER_URL = indexerUrl; switch (env) { diff --git a/src/types.ts b/src/types.ts index ca730bf..64dd39a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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; +}; From 1bbedb50d012184e7bc0f7417e517bcacf065272 Mon Sep 17 00:00:00 2001 From: leon mandel Date: Sun, 22 Sep 2024 11:24:19 +0200 Subject: [PATCH 2/5] fix pr --- src/constant.ts | 8 +++----- src/ref.ts | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/constant.ts b/src/constant.ts index a9b0053..860c4b9 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -10,17 +10,15 @@ export const FT_MINIMUM_STORAGE_BALANCE_LARGE = "12500000000000000000000" export const ONE_YOCTO_NEAR = '0.000000000000000000000001'; let ENV: string | undefined = ''; let INDEXER_URL: string | undefined = ''; -let CONFIG: Config | undefined = undefined; export function getConfig( env: string | undefined = ENV || process.env.NEAR_ENV || process.env.REACT_APP_REF_SDK_ENV, indexerUrl: string | undefined = INDEXER_URL, - custom_config: Config | undefined = CONFIG + customConfig: Config | undefined ): Config { - if (custom_config) { - CONFIG = custom_config; - return custom_config; + if (customConfig) { + return customConfig; } { ENV = env; diff --git a/src/ref.ts b/src/ref.ts index 000729b..b4d7e18 100644 --- a/src/ref.ts +++ b/src/ref.ts @@ -47,7 +47,7 @@ let near = new Near({ headers: {}, ...getConfig(), }); -export const init_env = (env: string, indexerUrl?: string) => { +export const init_env = (env: string, indexerUrl?: string, config?: Config) => { near = new Near({ keyStore: getKeyStore(), headers: {}, From 4ac4b75224613072c2424a9a1985c5ffa9313472 Mon Sep 17 00:00:00 2001 From: leon mandel Date: Sun, 22 Sep 2024 15:14:21 +0200 Subject: [PATCH 3/5] tested config update changes --- package.json | 24 +++++++++++++++++++++++- src/constant.ts | 12 +++++++----- src/ref.ts | 3 ++- src/utils.ts | 3 +-- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index f98834a..208b546 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,29 @@ "typescript": "^4.7.4" }, "dependencies": { - "@near-wallet-selector/core": "^7.0.0", + "@near-wallet-selector/bitget-wallet": "^8.9.13", + "@near-wallet-selector/bitte-wallet": "^8.9.13", + "@near-wallet-selector/coin98-wallet": "^8.9.13", + "@near-wallet-selector/core": "^7.3.0", + "@near-wallet-selector/ethereum-wallets": "^8.9.13", + "@near-wallet-selector/here-wallet": "^8.9.13", + "@near-wallet-selector/ledger": "^8.9.13", + "@near-wallet-selector/math-wallet": "^8.9.13", + "@near-wallet-selector/meteor-wallet": "^8.9.13", + "@near-wallet-selector/mintbase-wallet": "^8.9.13", + "@near-wallet-selector/my-near-wallet": "^8.9.13", + "@near-wallet-selector/narwallets": "^8.9.13", + "@near-wallet-selector/near-mobile-wallet": "^8.9.13", + "@near-wallet-selector/near-snap": "^8.9.13", + "@near-wallet-selector/nearfi": "^8.9.13", + "@near-wallet-selector/neth": "^8.9.13", + "@near-wallet-selector/nightly": "^8.9.13", + "@near-wallet-selector/okx-wallet": "^8.9.13", + "@near-wallet-selector/ramper-wallet": "^8.9.13", + "@near-wallet-selector/sender": "^8.9.13", + "@near-wallet-selector/wallet-connect": "^8.9.13", + "@near-wallet-selector/welldone-wallet": "^8.9.13", + "@near-wallet-selector/xdefi": "^8.9.13", "@react-icons/all-files": "^4.1.0", "@types/big.js": "^6.1.5", "@types/bn.js": "^5.1.1", diff --git a/src/constant.ts b/src/constant.ts index 860c4b9..baf1237 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -10,17 +10,19 @@ export const FT_MINIMUM_STORAGE_BALANCE_LARGE = "12500000000000000000000" export const ONE_YOCTO_NEAR = '0.000000000000000000000001'; let ENV: string | undefined = ''; let INDEXER_URL: string | undefined = ''; +let CONFIG: Config | undefined = undefined; export function getConfig( env: string | undefined = ENV || process.env.NEAR_ENV || process.env.REACT_APP_REF_SDK_ENV, - indexerUrl: string | undefined = INDEXER_URL, - customConfig: Config | undefined + indexerUrl: string | undefined = INDEXER_URL, + custom_config: Config | undefined = CONFIG ): Config { - if (customConfig) { - return customConfig; + if (custom_config) { + CONFIG = custom_config; + return custom_config; } - { + ENV = env; INDEXER_URL = indexerUrl; switch (env) { diff --git a/src/ref.ts b/src/ref.ts index b4d7e18..d54154e 100644 --- a/src/ref.ts +++ b/src/ref.ts @@ -21,6 +21,7 @@ import { TokenMetadata, FTStorageBalance, RefFiViewFunctionOptions, + Config, } from './types'; import { AccountView, CodeResult } from 'near-api-js/lib/providers/provider'; import { Transaction } from './types'; @@ -51,7 +52,7 @@ export const init_env = (env: string, indexerUrl?: string, config?: Config) => { near = new Near({ keyStore: getKeyStore(), headers: {}, - ...getConfig(env, indexerUrl), + ...getConfig(env, indexerUrl, config), }); return switchEnv(); }; diff --git a/src/utils.ts b/src/utils.ts index d4e92ff..f8047cd 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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'; @@ -289,7 +288,7 @@ export const WalletSelectorTransactions = ( }; }); - return { transactions: parsedTransactions } as SignAndSendTransactionsParams; + return { transactions: parsedTransactions }; }; export const separateRoutes = ( From 37f58a8315734cf352f2612403588b3102a85ee1 Mon Sep 17 00:00:00 2001 From: leon mandel Date: Sun, 22 Sep 2024 16:13:23 +0200 Subject: [PATCH 4/5] fix pr --- package.json | 24 +----------------------- src/constant.ts | 18 ++++++------------ src/ref.ts | 4 ++-- 3 files changed, 9 insertions(+), 37 deletions(-) diff --git a/package.json b/package.json index 208b546..f98834a 100644 --- a/package.json +++ b/package.json @@ -65,29 +65,7 @@ "typescript": "^4.7.4" }, "dependencies": { - "@near-wallet-selector/bitget-wallet": "^8.9.13", - "@near-wallet-selector/bitte-wallet": "^8.9.13", - "@near-wallet-selector/coin98-wallet": "^8.9.13", - "@near-wallet-selector/core": "^7.3.0", - "@near-wallet-selector/ethereum-wallets": "^8.9.13", - "@near-wallet-selector/here-wallet": "^8.9.13", - "@near-wallet-selector/ledger": "^8.9.13", - "@near-wallet-selector/math-wallet": "^8.9.13", - "@near-wallet-selector/meteor-wallet": "^8.9.13", - "@near-wallet-selector/mintbase-wallet": "^8.9.13", - "@near-wallet-selector/my-near-wallet": "^8.9.13", - "@near-wallet-selector/narwallets": "^8.9.13", - "@near-wallet-selector/near-mobile-wallet": "^8.9.13", - "@near-wallet-selector/near-snap": "^8.9.13", - "@near-wallet-selector/nearfi": "^8.9.13", - "@near-wallet-selector/neth": "^8.9.13", - "@near-wallet-selector/nightly": "^8.9.13", - "@near-wallet-selector/okx-wallet": "^8.9.13", - "@near-wallet-selector/ramper-wallet": "^8.9.13", - "@near-wallet-selector/sender": "^8.9.13", - "@near-wallet-selector/wallet-connect": "^8.9.13", - "@near-wallet-selector/welldone-wallet": "^8.9.13", - "@near-wallet-selector/xdefi": "^8.9.13", + "@near-wallet-selector/core": "^7.0.0", "@react-icons/all-files": "^4.1.0", "@types/big.js": "^6.1.5", "@types/bn.js": "^5.1.1", diff --git a/src/constant.ts b/src/constant.ts index baf1237..bfbb467 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -10,26 +10,20 @@ export const FT_MINIMUM_STORAGE_BALANCE_LARGE = "12500000000000000000000" export const ONE_YOCTO_NEAR = '0.000000000000000000000001'; let ENV: string | undefined = ''; let INDEXER_URL: string | undefined = ''; -let CONFIG: Config | undefined = undefined; export function getConfig( env: string | undefined = ENV || process.env.NEAR_ENV || process.env.REACT_APP_REF_SDK_ENV, indexerUrl: string | undefined = INDEXER_URL, - custom_config: Config | undefined = CONFIG - ): Config { - if (custom_config) { - CONFIG = custom_config; - return custom_config; - } - + 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', @@ -41,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', @@ -53,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', @@ -65,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', diff --git a/src/ref.ts b/src/ref.ts index d54154e..e8341a5 100644 --- a/src/ref.ts +++ b/src/ref.ts @@ -48,11 +48,11 @@ let near = new Near({ headers: {}, ...getConfig(), }); -export const init_env = (env: string, indexerUrl?: string, config?: Config) => { +export const init_env = (env: string, indexerUrl?: string, nodeUrl?: string) => { near = new Near({ keyStore: getKeyStore(), headers: {}, - ...getConfig(env, indexerUrl, config), + ...getConfig(env, indexerUrl, nodeUrl), }); return switchEnv(); }; From c861bbaa25dc4f716f22d2883923f451223927c4 Mon Sep 17 00:00:00 2001 From: leon mandel Date: Sun, 22 Sep 2024 16:25:53 +0200 Subject: [PATCH 5/5] fix pr --- src/constant.ts | 2 +- src/ref.ts | 1 - src/types.ts | 12 ------------ src/utils.ts | 2 +- 4 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/constant.ts b/src/constant.ts index bfbb467..4b39d25 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -1,4 +1,4 @@ -import { Config, TokenMetadata } from './types'; +import { TokenMetadata } from './types'; export const FEE_DIVISOR = 10000; diff --git a/src/ref.ts b/src/ref.ts index e8341a5..5b88a1b 100644 --- a/src/ref.ts +++ b/src/ref.ts @@ -21,7 +21,6 @@ import { TokenMetadata, FTStorageBalance, RefFiViewFunctionOptions, - Config, } from './types'; import { AccountView, CodeResult } from 'near-api-js/lib/providers/provider'; import { Transaction } from './types'; diff --git a/src/types.ts b/src/types.ts index 64dd39a..ca730bf 100644 --- a/src/types.ts +++ b/src/types.ts @@ -139,15 +139,3 @@ 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; -}; diff --git a/src/utils.ts b/src/utils.ts index f8047cd..3472431 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -288,7 +288,7 @@ export const WalletSelectorTransactions = ( }; }); - return { transactions: parsedTransactions }; + return { transactions: parsedTransactions } ; }; export const separateRoutes = (