-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/eth http poll #308
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
base: dev
Are you sure you want to change the base?
Feat/eth http poll #308
Changes from all commits
c4d79e9
1a1b34b
e98ce6b
b182f89
67f4978
695f17a
f102336
d445d27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -271,9 +271,12 @@ const getMarketplaceFee = async function (data, { api }) { | |
| return api.contracts.getMarketplaceFee(data); | ||
| }; | ||
|
|
||
| function refreshAllContracts({ }, { api }) { | ||
| const walletId = wallet.getAddress().address; | ||
| return api.contracts.refreshContracts(null, walletId); | ||
| function refreshAllContracts({}, { api }) { | ||
| return api.contracts.refreshContracts(); | ||
| } | ||
|
|
||
| function startWatchingContracts({}, { api }) { | ||
| return api.contracts.startWatching(); | ||
| } | ||
|
|
||
| function refreshTransaction({ hash, address }, { api }) { | ||
|
|
@@ -336,6 +339,10 @@ const getLocalIp = async ({ }, { api }) => api["proxy-router"].getLocalIp(); | |
|
|
||
| const isProxyPortPublic = async (data, { api }) => api["proxy-router"].isProxyPortPublic(data); | ||
|
|
||
| const getContractHistory = async (data, { api }) => { | ||
| return api.contracts.getContractHistory(data); | ||
| } | ||
|
|
||
| const logout = async (data) => { | ||
| return cleanupDb(); | ||
| }; | ||
|
|
@@ -361,12 +368,13 @@ const revealSecretPhrase = async (password) => { | |
| } | ||
|
|
||
| function getPastTransactions({ address, page, pageSize }, { api }) { | ||
| return api.explorer.getPastCoinTransactions(0, undefined, address, page, pageSize); | ||
| return api.explorer.syncTransactions(0, undefined, page, pageSize, address); | ||
alex-sandrk marked this conversation as resolved.
Show resolved
Hide resolved
alex-sandrk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| module.exports = { | ||
| // refreshAllSockets, | ||
| refreshAllSockets, | ||
| refreshAllContracts, | ||
| startWatchingContracts, | ||
| purchaseContract, | ||
| createContract, | ||
| cancelContract, | ||
|
|
@@ -400,4 +408,5 @@ module.exports = { | |
| getMarketplaceFee, | ||
| isProxyPortPublic, | ||
| stopProxyRouter, | ||
| getContractHistory, | ||
| }; | ||
|
Comment on lines
408
to
412
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The exported object at the end of the file includes |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,9 @@ const { | |
| } = require("./handlers/single-core"); | ||
|
|
||
| const { runProxyRouter, isProxyRouterHealthy } = require("./proxyRouter"); | ||
|
|
||
| let interval; | ||
|
|
||
| function startCore({ chain, core, config: coreConfig }, webContent) { | ||
| logger.verbose(`Starting core ${chain}`); | ||
| const { emitter, events, api } = core.start(coreConfig); | ||
|
Comment on lines
22
to
24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Recommended solution: Wrap the core startup logic in a try-catch block and handle any potential exceptions appropriately. This could include logging the error, retrying the startup process, or notifying the user of the failure. |
||
|
|
@@ -35,6 +37,7 @@ function startCore({ chain, core, config: coreConfig }, webContent) { | |
| "transactions-scan-finished", | ||
| "contracts-scan-started", | ||
| "contracts-scan-finished", | ||
| "contracts-updated", | ||
| 'contract-updated', | ||
| ); | ||
|
|
||
|
|
@@ -65,10 +68,10 @@ function startCore({ chain, core, config: coreConfig }, webContent) { | |
| return api.explorer | ||
| .syncTransactions( | ||
| 0, | ||
| address, | ||
| (number) => storage.setSyncBlock(number, chain), | ||
| 'latest', | ||
| page, | ||
| pageSize | ||
| pageSize, | ||
| address | ||
| ) | ||
| .then(function () { | ||
| send("transactions-scan-finished", { success: true }); | ||
alex-sandrk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
@@ -91,7 +94,11 @@ function startCore({ chain, core, config: coreConfig }, webContent) { | |
| }); | ||
| } | ||
|
|
||
| emitter.on("open-wallet", syncTransactions); | ||
| emitter.on("open-wallet", (props) => { | ||
| syncTransactions(props); | ||
| api.contracts.startWatching({}); | ||
| api.explorer.startWatching({ walletAddress: props.address }); | ||
alex-sandrk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| emitter.on("wallet-error", function (err) { | ||
| logger.warn( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,8 +41,7 @@ function BuyerHub({ | |
| address, | ||
| client, | ||
| contractsRefresh, | ||
| allowSendTransaction, | ||
| ...props | ||
| allowSendTransaction | ||
| }) { | ||
| const contractsToShow = contracts.filter( | ||
| x => x.buyer === address && x.seller !== address | ||
|
Comment on lines
46
to
47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
@@ -95,8 +94,7 @@ function BuyerHub({ | |
| const [showHashrateModal, setShowHashrateModal] = useState(false); | ||
| const [contactToShowHashrate, setContactToShowHashrate] = useState(); | ||
|
|
||
| const contractsWithHistory = contracts.filter(c => c.history.length); | ||
| const showHistory = contractsWithHistory.length; | ||
| const hasContractsWithHistory = true; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable |
||
| const onHistoryOpen = () => setIsHistoryModalOpen(true); | ||
alex-sandrk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return ( | ||
|
|
@@ -106,10 +104,12 @@ function BuyerHub({ | |
| address={address} | ||
| copyToClipboard={copyToClipboard} | ||
| > | ||
| <HistoryBtn disabled={!showHistory} onClick={onHistoryOpen}> | ||
| <HistoryBtn disabled={!hasContractsWithHistory} onClick={onHistoryOpen}> | ||
| <span | ||
| style={{ display: 'flex' }} | ||
| data-rh={showHistory ? null : `You have no purchase history`} | ||
| data-rh={ | ||
| hasContractsWithHistory ? null : `You have no purchase history` | ||
| } | ||
| > | ||
| <IconHistory style={{ display: 'inline-block' }} /> History | ||
| </span> | ||
alex-sandrk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
@@ -132,7 +132,8 @@ function BuyerHub({ | |
|
|
||
| <HistoryModal | ||
| isActive={isHistoryModalOpen} | ||
| historyContracts={contractsWithHistory} | ||
| contracts={contracts} | ||
| address={address} | ||
| close={() => { | ||
| setIsHistoryModalOpen(false); | ||
| }} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,18 +10,49 @@ import { | |
| } from '../CreateContractModal.styles'; | ||
| import HistoryRow from './HistoryRow'; | ||
| import { withClient } from '../../../../store/hocs/clientContext'; | ||
| import { lmrDecimals } from '../../../../utils/coinValue'; | ||
| import Spinner from '../../../common/Spinner'; | ||
|
|
||
| function HistroyModal(props) { | ||
| const { isActive, close, historyContracts, client } = props; | ||
| const { isActive, close, client, contracts, address } = props; | ||
|
|
||
| const [historyContracts, setHistory] = useState({}); | ||
| const [isLoading, setLoading] = useState(false); | ||
| useEffect(() => { | ||
| if (!isActive) { | ||
| return; | ||
| } | ||
| if (contracts.length) { | ||
| setLoading(true); | ||
| } | ||
| let loaded = 0; | ||
| for (let i = 0; i < contracts.length; i += 1) { | ||
| const c = contracts[i]; | ||
| client | ||
| .getContractHistory({ contractAddr: c.id, walletAddress: address }) | ||
| .then(history => { | ||
| if (history.length > 0) { | ||
| setHistory(prev => ({ | ||
| ...prev, | ||
| [c.id]: history | ||
| })); | ||
| } | ||
| }) | ||
| .catch(err => {}) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The To improve error handling, implement proper error logging within the |
||
| .finally(() => { | ||
| loaded += 1; | ||
| if (loaded === contracts.length) { | ||
| setLoading(false); | ||
| } | ||
| }); | ||
| } | ||
| }, [isActive]); | ||
|
Comment on lines
+18
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The To resolve this issue, consider using |
||
|
|
||
| const handleClose = e => { | ||
| close(e); | ||
| }; | ||
| const handlePropagation = e => e.stopPropagation(); | ||
|
|
||
| const history = historyContracts | ||
| .map(hc => hc.history) | ||
| const history = Object.values(historyContracts) | ||
| .flat() | ||
| .map(h => { | ||
| return { | ||
|
|
@@ -48,10 +79,7 @@ function HistroyModal(props) { | |
| } | ||
|
|
||
| const rowRenderer = historyContracts => ({ key, index, style }) => ( | ||
| <HistoryRow | ||
| key={historyContracts[index].id} | ||
| contract={historyContracts[index]} | ||
| /> | ||
| <HistoryRow key={`${index}`} contract={historyContracts[index]} /> | ||
| ); | ||
|
|
||
| return ( | ||
|
|
@@ -61,6 +89,12 @@ function HistroyModal(props) { | |
| <TitleWrapper> | ||
| <Title>Purchase history</Title> | ||
| </TitleWrapper> | ||
| {isLoading && !history.length && ( | ||
| <Subtitle> | ||
| Loading... <Spinner size="16px"></Spinner> | ||
| </Subtitle> | ||
| )} | ||
| {!isLoading && !history.length && <Subtitle>No history found</Subtitle>} | ||
| <AutoSizer width={400}> | ||
| {({ width, height }) => ( | ||
| <RVList | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
logoutfunction is callingcleanupDb()without passing any arguments or handling the result or potential errors. IfcleanupDbis intended to clean up database resources specific to the user session, it should likely be passed the necessary user/session data to perform its task correctly. Additionally, there is no error handling, which could lead to uncaught exceptions ifcleanupDbfails. It is recommended to pass the necessary data tocleanupDband implement proper error handling to ensure resources are cleaned up safely and errors are managed appropriately.