@reown/appkit-core-react-native 0.0.0-feat-wallet-features-20240925132010 → 0.0.0-fix-email-login-20241010173711
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/controllers/AccountController.js +1 -25
- package/lib/commonjs/controllers/AccountController.js.map +1 -1
- package/lib/commonjs/controllers/ApiController.js +3 -3
- package/lib/commonjs/controllers/ApiController.js.map +1 -1
- package/lib/commonjs/controllers/BlockchainApiController.js +0 -84
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectionController.js +0 -19
- package/lib/commonjs/controllers/ConnectionController.js.map +1 -1
- package/lib/commonjs/controllers/EventsController.js +15 -1
- package/lib/commonjs/controllers/EventsController.js.map +1 -1
- package/lib/commonjs/controllers/ModalController.js +1 -1
- package/lib/commonjs/controllers/ModalController.js.map +1 -1
- package/lib/commonjs/controllers/NetworkController.js +0 -3
- package/lib/commonjs/controllers/NetworkController.js.map +1 -1
- package/lib/commonjs/controllers/OptionsController.js +1 -1
- package/lib/commonjs/controllers/OptionsController.js.map +1 -1
- package/lib/commonjs/controllers/RouterController.js +1 -22
- package/lib/commonjs/controllers/RouterController.js.map +1 -1
- package/lib/commonjs/index.js +0 -35
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/ConstantsUtil.js +1 -2
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
- package/lib/commonjs/utils/CoreHelperUtil.js +0 -33
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
- package/lib/commonjs/utils/FetchUtil.js.map +1 -1
- package/lib/commonjs/utils/TypeUtil.js +0 -4
- package/lib/module/controllers/AccountController.js +1 -25
- package/lib/module/controllers/AccountController.js.map +1 -1
- package/lib/module/controllers/ApiController.js +3 -3
- package/lib/module/controllers/ApiController.js.map +1 -1
- package/lib/module/controllers/BlockchainApiController.js +0 -84
- package/lib/module/controllers/BlockchainApiController.js.map +1 -1
- package/lib/module/controllers/ConnectionController.js +0 -19
- package/lib/module/controllers/ConnectionController.js.map +1 -1
- package/lib/module/controllers/EventsController.js +15 -1
- package/lib/module/controllers/EventsController.js.map +1 -1
- package/lib/module/controllers/ModalController.js +1 -1
- package/lib/module/controllers/ModalController.js.map +1 -1
- package/lib/module/controllers/NetworkController.js +0 -3
- package/lib/module/controllers/NetworkController.js.map +1 -1
- package/lib/module/controllers/OptionsController.js +1 -1
- package/lib/module/controllers/OptionsController.js.map +1 -1
- package/lib/module/controllers/RouterController.js +1 -22
- package/lib/module/controllers/RouterController.js.map +1 -1
- package/lib/module/index.js +0 -6
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/ConstantsUtil.js +1 -2
- package/lib/module/utils/ConstantsUtil.js.map +1 -1
- package/lib/module/utils/CoreHelperUtil.js +0 -33
- package/lib/module/utils/CoreHelperUtil.js.map +1 -1
- package/lib/module/utils/FetchUtil.js.map +1 -1
- package/lib/module/utils/TypeUtil.js +1 -1
- package/lib/typescript/controllers/AccountController.d.ts +0 -4
- package/lib/typescript/controllers/AccountController.d.ts.map +1 -1
- package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/BlockchainApiController.d.ts +1 -6
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectionController.d.ts +1 -13
- package/lib/typescript/controllers/ConnectionController.d.ts.map +1 -1
- package/lib/typescript/controllers/EventsController.d.ts +6 -0
- package/lib/typescript/controllers/EventsController.d.ts.map +1 -1
- package/lib/typescript/controllers/NetworkController.d.ts +0 -1
- package/lib/typescript/controllers/NetworkController.d.ts.map +1 -1
- package/lib/typescript/controllers/RouterController.d.ts +1 -13
- package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +26 -18
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/ConstantsUtil.d.ts +0 -1
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/CoreHelperUtil.d.ts +0 -6
- package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
- package/lib/typescript/utils/FetchUtil.d.ts +0 -3
- package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
- package/lib/typescript/utils/TypeUtil.d.ts +0 -137
- package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
- package/package.json +5 -5
- package/readme.md +1 -1
- package/src/controllers/AccountController.ts +1 -35
- package/src/controllers/ApiController.ts +7 -3
- package/src/controllers/BlockchainApiController.ts +1 -88
- package/src/controllers/ConnectionController.ts +1 -37
- package/src/controllers/EventsController.ts +13 -1
- package/src/controllers/ModalController.ts +1 -1
- package/src/controllers/NetworkController.ts +0 -6
- package/src/controllers/OptionsController.ts +1 -1
- package/src/controllers/RouterController.ts +10 -52
- package/src/index.ts +30 -41
- package/src/utils/ConstantsUtil.ts +1 -3
- package/src/utils/CoreHelperUtil.ts +1 -38
- package/src/utils/FetchUtil.ts +0 -4
- package/src/utils/TypeUtil.ts +0 -169
- package/lib/commonjs/controllers/EnsController.js +0 -35
- package/lib/commonjs/controllers/EnsController.js.map +0 -1
- package/lib/commonjs/controllers/SendController.js +0 -176
- package/lib/commonjs/controllers/SendController.js.map +0 -1
- package/lib/commonjs/controllers/SwapController.js +0 -91
- package/lib/commonjs/controllers/SwapController.js.map +0 -1
- package/lib/commonjs/controllers/TransactionsController.js +0 -112
- package/lib/commonjs/controllers/TransactionsController.js.map +0 -1
- package/lib/commonjs/utils/ApiUtil.js +0 -18
- package/lib/commonjs/utils/ApiUtil.js.map +0 -1
- package/lib/commonjs/utils/SwapApiUtil.js +0 -23
- package/lib/commonjs/utils/SwapApiUtil.js.map +0 -1
- package/lib/commonjs/utils/SwapCalculationUtil.js +0 -24
- package/lib/commonjs/utils/SwapCalculationUtil.js.map +0 -1
- package/lib/module/controllers/EnsController.js +0 -30
- package/lib/module/controllers/EnsController.js.map +0 -1
- package/lib/module/controllers/SendController.js +0 -171
- package/lib/module/controllers/SendController.js.map +0 -1
- package/lib/module/controllers/SwapController.js +0 -86
- package/lib/module/controllers/SwapController.js.map +0 -1
- package/lib/module/controllers/TransactionsController.js +0 -107
- package/lib/module/controllers/TransactionsController.js.map +0 -1
- package/lib/module/utils/ApiUtil.js +0 -12
- package/lib/module/utils/ApiUtil.js.map +0 -1
- package/lib/module/utils/SwapApiUtil.js +0 -17
- package/lib/module/utils/SwapApiUtil.js.map +0 -1
- package/lib/module/utils/SwapCalculationUtil.js +0 -19
- package/lib/module/utils/SwapCalculationUtil.js.map +0 -1
- package/lib/typescript/controllers/EnsController.d.ts +0 -10
- package/lib/typescript/controllers/EnsController.d.ts.map +0 -1
- package/lib/typescript/controllers/SendController.d.ts +0 -41
- package/lib/typescript/controllers/SendController.d.ts.map +0 -1
- package/lib/typescript/controllers/SwapController.d.ts +0 -29
- package/lib/typescript/controllers/SwapController.d.ts.map +0 -1
- package/lib/typescript/controllers/TransactionsController.d.ts +0 -21
- package/lib/typescript/controllers/TransactionsController.d.ts.map +0 -1
- package/lib/typescript/utils/ApiUtil.d.ts +0 -5
- package/lib/typescript/utils/ApiUtil.d.ts.map +0 -1
- package/lib/typescript/utils/SwapApiUtil.d.ts +0 -4
- package/lib/typescript/utils/SwapApiUtil.d.ts.map +0 -1
- package/lib/typescript/utils/SwapCalculationUtil.d.ts +0 -5
- package/lib/typescript/utils/SwapCalculationUtil.d.ts.map +0 -1
- package/src/controllers/EnsController.ts +0 -39
- package/src/controllers/SendController.ts +0 -234
- package/src/controllers/SwapController.ts +0 -108
- package/src/controllers/TransactionsController.ts +0 -142
- package/src/utils/ApiUtil.ts +0 -18
- package/src/utils/SwapApiUtil.ts +0 -19
- package/src/utils/SwapCalculationUtil.ts +0 -21
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { subscribeKey as subKey } from 'valtio/utils';
|
|
2
|
-
import { proxy, subscribe as sub } from 'valtio';
|
|
3
|
-
|
|
4
|
-
import { ConstantsUtil } from '../utils/ConstantsUtil';
|
|
5
|
-
import { SwapApiUtil } from '../utils/SwapApiUtil';
|
|
6
|
-
import { NetworkController } from './NetworkController';
|
|
7
|
-
import { BlockchainApiController } from './BlockchainApiController';
|
|
8
|
-
import { OptionsController } from './OptionsController';
|
|
9
|
-
import { SwapCalculationUtil } from '../utils/SwapCalculationUtil';
|
|
10
|
-
|
|
11
|
-
// -- Constants ---------------------------------------- //
|
|
12
|
-
export const INITIAL_GAS_LIMIT = 150000;
|
|
13
|
-
export const TO_AMOUNT_DECIMALS = 6;
|
|
14
|
-
|
|
15
|
-
// -- Types --------------------------------------------- //
|
|
16
|
-
|
|
17
|
-
export interface SwapControllerState {
|
|
18
|
-
// Input values
|
|
19
|
-
networkPrice: string;
|
|
20
|
-
networkTokenSymbol: string;
|
|
21
|
-
|
|
22
|
-
// Tokens
|
|
23
|
-
tokensPriceMap: Record<string, number>;
|
|
24
|
-
|
|
25
|
-
// Calculations
|
|
26
|
-
gasFee: string;
|
|
27
|
-
gasPriceInUSD?: number;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
type StateKey = keyof SwapControllerState;
|
|
31
|
-
|
|
32
|
-
// -- State --------------------------------------------- //
|
|
33
|
-
const initialState: SwapControllerState = {
|
|
34
|
-
// Input values
|
|
35
|
-
networkPrice: '0',
|
|
36
|
-
networkTokenSymbol: '',
|
|
37
|
-
|
|
38
|
-
// Tokens
|
|
39
|
-
tokensPriceMap: {},
|
|
40
|
-
|
|
41
|
-
// Calculations
|
|
42
|
-
gasFee: '0',
|
|
43
|
-
gasPriceInUSD: 0
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const state = proxy<SwapControllerState>(initialState);
|
|
47
|
-
|
|
48
|
-
// -- Controller ---------------------------------------- //
|
|
49
|
-
export const SwapController = {
|
|
50
|
-
state,
|
|
51
|
-
|
|
52
|
-
subscribe(callback: (newState: SwapControllerState) => void) {
|
|
53
|
-
return sub(state, () => callback(state));
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
subscribeKey<K extends StateKey>(key: K, callback: (value: SwapControllerState[K]) => void) {
|
|
57
|
-
return subKey(state, key, callback);
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
getParams() {
|
|
61
|
-
const caipNetwork = NetworkController.state.caipNetwork;
|
|
62
|
-
const networkAddress = `${caipNetwork?.id}:${ConstantsUtil.NATIVE_TOKEN_ADDRESS}`;
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
networkAddress
|
|
66
|
-
};
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
resetState() {
|
|
70
|
-
state.tokensPriceMap = initialState.tokensPriceMap;
|
|
71
|
-
state.networkPrice = initialState.networkPrice;
|
|
72
|
-
state.networkTokenSymbol = initialState.networkTokenSymbol;
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
//this
|
|
76
|
-
async getNetworkTokenPrice() {
|
|
77
|
-
const { networkAddress } = this.getParams();
|
|
78
|
-
|
|
79
|
-
const response = await BlockchainApiController.fetchTokenPrice({
|
|
80
|
-
projectId: OptionsController.state.projectId,
|
|
81
|
-
addresses: [networkAddress]
|
|
82
|
-
});
|
|
83
|
-
const token = response?.fungibles?.[0];
|
|
84
|
-
const price = token?.price.toString() || '0';
|
|
85
|
-
state.tokensPriceMap[networkAddress] = parseFloat(price);
|
|
86
|
-
state.networkTokenSymbol = token?.symbol || '';
|
|
87
|
-
state.networkPrice = price;
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
//this
|
|
91
|
-
async getInitialGasPrice() {
|
|
92
|
-
const res = await SwapApiUtil.fetchGasPrice();
|
|
93
|
-
|
|
94
|
-
if (!res) {
|
|
95
|
-
return { gasPrice: null, gasPriceInUsd: null };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const value = res.standard;
|
|
99
|
-
const gasFee = BigInt(value);
|
|
100
|
-
const gasLimit = BigInt(INITIAL_GAS_LIMIT);
|
|
101
|
-
const gasPrice = SwapCalculationUtil.getGasPriceInUSD(state.networkPrice, gasLimit, gasFee);
|
|
102
|
-
|
|
103
|
-
state.gasFee = value;
|
|
104
|
-
state.gasPriceInUSD = gasPrice;
|
|
105
|
-
|
|
106
|
-
return { gasPrice: gasFee, gasPriceInUSD: state.gasPriceInUSD };
|
|
107
|
-
}
|
|
108
|
-
};
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import type { Transaction } from '@reown/appkit-common-react-native';
|
|
2
|
-
import { proxy, subscribe as sub } from 'valtio/vanilla';
|
|
3
|
-
import { OptionsController } from './OptionsController';
|
|
4
|
-
import { EventsController } from './EventsController';
|
|
5
|
-
import { SnackController } from './SnackController';
|
|
6
|
-
import { NetworkController } from './NetworkController';
|
|
7
|
-
import { BlockchainApiController } from './BlockchainApiController';
|
|
8
|
-
|
|
9
|
-
// -- Types --------------------------------------------- //
|
|
10
|
-
type TransactionByMonthMap = Record<string, Transaction[]>;
|
|
11
|
-
type TransactionByYearMap = Record<string, TransactionByMonthMap>;
|
|
12
|
-
|
|
13
|
-
export interface TransactionsControllerState {
|
|
14
|
-
transactions: Transaction[];
|
|
15
|
-
loading: boolean;
|
|
16
|
-
empty: boolean;
|
|
17
|
-
next: string | undefined;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// -- State --------------------------------------------- //
|
|
21
|
-
const state = proxy<TransactionsControllerState>({
|
|
22
|
-
transactions: [],
|
|
23
|
-
loading: false,
|
|
24
|
-
empty: false,
|
|
25
|
-
next: undefined
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// -- Controller ---------------------------------------- //
|
|
29
|
-
export const TransactionsController = {
|
|
30
|
-
state,
|
|
31
|
-
|
|
32
|
-
subscribe(callback: (newState: TransactionsControllerState) => void) {
|
|
33
|
-
return sub(state, () => callback(state));
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
async fetchTransactions(accountAddress?: string, reset?: boolean) {
|
|
37
|
-
const { projectId } = OptionsController.state;
|
|
38
|
-
|
|
39
|
-
if (!projectId || !accountAddress) {
|
|
40
|
-
throw new Error("Transactions can't be fetched without a projectId and an accountAddress");
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
state.loading = true;
|
|
44
|
-
|
|
45
|
-
if (reset) {
|
|
46
|
-
state.next = undefined;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
const response = await BlockchainApiController.fetchTransactions({
|
|
51
|
-
account: accountAddress,
|
|
52
|
-
projectId,
|
|
53
|
-
cursor: state.next
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
const nonSpamTransactions = this.filterSpamTransactions(response?.data ?? []);
|
|
57
|
-
let filteredTransactions = [...state.transactions, ...nonSpamTransactions];
|
|
58
|
-
filteredTransactions = [...state.transactions, ...nonSpamTransactions];
|
|
59
|
-
|
|
60
|
-
if (reset) {
|
|
61
|
-
filteredTransactions = nonSpamTransactions;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
state.loading = false;
|
|
65
|
-
|
|
66
|
-
state.transactions = filteredTransactions;
|
|
67
|
-
|
|
68
|
-
state.empty = nonSpamTransactions.length === 0;
|
|
69
|
-
state.next = response?.next ? response.next : undefined;
|
|
70
|
-
} catch (error) {
|
|
71
|
-
EventsController.sendEvent({
|
|
72
|
-
type: 'track',
|
|
73
|
-
event: 'ERROR_FETCH_TRANSACTIONS',
|
|
74
|
-
properties: {
|
|
75
|
-
address: accountAddress,
|
|
76
|
-
projectId,
|
|
77
|
-
cursor: state.next,
|
|
78
|
-
isSmartAccount: false
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
SnackController.showError('Failed to fetch transactions');
|
|
82
|
-
state.loading = false;
|
|
83
|
-
state.empty = true;
|
|
84
|
-
state.next = undefined;
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
getTransactionsByYearAndMonth(transactions: Transaction[]) {
|
|
89
|
-
const grouped: TransactionByYearMap = {};
|
|
90
|
-
let filteredTransactions = this.filterByConnectedChain(transactions);
|
|
91
|
-
|
|
92
|
-
filteredTransactions.forEach(transaction => {
|
|
93
|
-
const year = new Date(transaction.metadata.minedAt).getFullYear();
|
|
94
|
-
const month = new Date(transaction.metadata.minedAt).getMonth();
|
|
95
|
-
|
|
96
|
-
const yearTransactions = grouped[year] ?? {};
|
|
97
|
-
const monthTransactions = yearTransactions[month] ?? [];
|
|
98
|
-
|
|
99
|
-
// If there's a transaction with the same id, remove the old one
|
|
100
|
-
const newMonthTransactions = monthTransactions.filter(tx => tx.id !== transaction.id);
|
|
101
|
-
|
|
102
|
-
grouped[year] = {
|
|
103
|
-
...yearTransactions,
|
|
104
|
-
[month]: [...newMonthTransactions, transaction].sort(
|
|
105
|
-
(a, b) => new Date(b.metadata.minedAt).getTime() - new Date(a.metadata.minedAt).getTime()
|
|
106
|
-
)
|
|
107
|
-
};
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
return grouped;
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
filterSpamTransactions(transactions: Transaction[]) {
|
|
114
|
-
return transactions.filter(transaction => {
|
|
115
|
-
const isAllSpam = transaction.transfers.every(
|
|
116
|
-
transfer => transfer.nft_info?.flags.is_spam === true
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
return !isAllSpam;
|
|
120
|
-
});
|
|
121
|
-
},
|
|
122
|
-
|
|
123
|
-
filterByConnectedChain(transactions: Transaction[]) {
|
|
124
|
-
const chainId = NetworkController.state.caipNetwork?.id;
|
|
125
|
-
const filteredTransactions = transactions.filter(
|
|
126
|
-
transaction => transaction.metadata.chain === chainId
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
return filteredTransactions;
|
|
130
|
-
},
|
|
131
|
-
|
|
132
|
-
clearCursor() {
|
|
133
|
-
state.next = undefined;
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
resetTransactions() {
|
|
137
|
-
state.transactions = [];
|
|
138
|
-
state.loading = false;
|
|
139
|
-
state.empty = false;
|
|
140
|
-
state.next = undefined;
|
|
141
|
-
}
|
|
142
|
-
};
|
package/src/utils/ApiUtil.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Platform } from 'react-native';
|
|
2
|
-
import { CoreHelperUtil } from './CoreHelperUtil';
|
|
3
|
-
|
|
4
|
-
export const ApiUtil = {
|
|
5
|
-
getOrigin() {
|
|
6
|
-
return CoreHelperUtil.getBundleId();
|
|
7
|
-
},
|
|
8
|
-
|
|
9
|
-
getUserAgent() {
|
|
10
|
-
const reactNativeVersion = [
|
|
11
|
-
Platform.constants.reactNativeVersion.major,
|
|
12
|
-
Platform.constants.reactNativeVersion.minor,
|
|
13
|
-
Platform.constants.reactNativeVersion.patch
|
|
14
|
-
].join('.');
|
|
15
|
-
|
|
16
|
-
return `${Platform.OS}-${Platform.Version}@rn-${reactNativeVersion}`;
|
|
17
|
-
}
|
|
18
|
-
};
|
package/src/utils/SwapApiUtil.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { BlockchainApiController } from '../controllers/BlockchainApiController';
|
|
2
|
-
import { OptionsController } from '../controllers/OptionsController';
|
|
3
|
-
import { NetworkController } from '../controllers/NetworkController';
|
|
4
|
-
|
|
5
|
-
export const SwapApiUtil = {
|
|
6
|
-
async fetchGasPrice() {
|
|
7
|
-
const projectId = OptionsController.state.projectId;
|
|
8
|
-
const caipNetwork = NetworkController.state.caipNetwork;
|
|
9
|
-
|
|
10
|
-
if (!caipNetwork) {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return await BlockchainApiController.fetchGasPrice({
|
|
15
|
-
projectId,
|
|
16
|
-
chainId: caipNetwork.id
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// -- Types --------------------------------------------- //
|
|
2
|
-
|
|
3
|
-
import { NumberUtil } from '@reown/appkit-common-react-native';
|
|
4
|
-
|
|
5
|
-
// -- Util ---------------------------------------- //
|
|
6
|
-
export const SwapCalculationUtil = {
|
|
7
|
-
getGasPriceInEther(gas: bigint, gasPrice: bigint) {
|
|
8
|
-
const totalGasCostInWei = gasPrice * gas;
|
|
9
|
-
const totalGasCostInEther = Number(totalGasCostInWei) / 1e18;
|
|
10
|
-
|
|
11
|
-
return totalGasCostInEther;
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
getGasPriceInUSD(networkPrice: string, gas: bigint, gasPrice: bigint) {
|
|
15
|
-
const totalGasCostInEther = SwapCalculationUtil.getGasPriceInEther(gas, gasPrice);
|
|
16
|
-
const networkPriceInUSD = NumberUtil.bigNumber(networkPrice);
|
|
17
|
-
const gasCostInUSD = networkPriceInUSD.multipliedBy(totalGasCostInEther);
|
|
18
|
-
|
|
19
|
-
return gasCostInUSD.toNumber();
|
|
20
|
-
}
|
|
21
|
-
};
|