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

Feat/eth http poll #308

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions public/main/client/handlers/single-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ function refreshAllContracts({}, { api }) {
return api.contracts.refreshContracts(null, walletId);
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved
}

function startWatchingContracts({}, { api }) {
const walletId = wallet.getAddress().address;
return api.contracts.startWatching();
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved
}
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved

function refreshTransaction({ hash, address }, { api }) {
return pTimeout(
api.explorer.refreshTransaction(hash, address),
Expand Down Expand Up @@ -372,6 +377,7 @@ function getPastTransactions({ address, page, pageSize }, { api }) {
module.exports = {
// refreshAllSockets,
refreshAllContracts,
startWatchingContracts,
purchaseContract,
createContract,
cancelContract,
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
12 changes: 8 additions & 4 deletions public/main/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ function startCore({ chain, core, config: coreConfig }, webContent) {
"transactions-scan-started",
"transactions-scan-finished",
"contracts-scan-started",
"contracts-scan-finished"
"contracts-scan-finished",
"contracts-updated",
);

function send(eventName, data) {
Expand Down Expand Up @@ -59,10 +60,10 @@ function startCore({ chain, core, config: coreConfig }, webContent) {
return api.explorer
.syncTransactions(
0,
address,
(number) => storage.setSyncBlock(number, chain),
page,
pageSize
pageSize,
address
)
.then(function() {
send("transactions-scan-finished", { success: true });
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -87,7 +88,10 @@ function startCore({ chain, core, config: coreConfig }, webContent) {
});
}

emitter.on("open-wallet", syncTransactions);
emitter.on("open-wallet", (props) => {
syncTransactions(props);
api.contracts.startWatching({});
});
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved

emitter.on("wallet-error", function(err) {
logger.warn(
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
1 change: 1 addition & 0 deletions public/main/client/subscriptions/single-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const listeners = {
"login-submit": handlers.onLoginSubmit,
// 'refresh-all-sockets': handlers.refreshAllSockets,
"refresh-all-contracts": handlers.refreshAllContracts,
"start-watching-contracts": handlers.startWatchingContracts,
"refresh-all-transactions": handlers.refreshAllTransactions,
"refresh-transaction": handlers.refreshTransaction,
"get-gas-limit": handlers.getGasLimit,
Expand Down
4 changes: 4 additions & 0 deletions src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ const createClient = function(createStore) {
'refresh-all-contracts',
120000
),
startWatchingContracts: utils.forwardToMainProcess(
'start-watching-contracts',
120000
),
onOnboardingCompleted: utils.forwardToMainProcess('onboarding-completed'),
recoverFromMnemonic: utils.forwardToMainProcess('recover-from-mnemonic'),
getTokenGasLimit: utils.forwardToMainProcess('get-token-gas-limit'),
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion src/components/contracts/BuyerHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function BuyerHub({

const [isHistoryModalOpen, setIsHistoryModalOpen] = useState(false);

const contractsWithHistory = contracts.filter(c => c.history.length);
const contractsWithHistory = contracts.filter(c => c.history?.length);
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved
const showHistory = contractsWithHistory.length;
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved
const onHistoryOpen = () => setIsHistoryModalOpen(true);
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
11 changes: 11 additions & 0 deletions src/store/reducers/contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ const reducer = handleActions(
};
},

'contracts-updated': (state, { payload }) => {
const idContractMap = keyBy(payload.actives, 'id');
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved

return {
...state,
actives: { ...state.actives, ...idContractMap },
lastUpdated: parseInt(Date.now() / 1000, 10),
syncStatus: 'up-to-date'
};
},

'remove-draft': (state, { payload }) => ({
...state,
drafts: Object.assign(state.drafts, []).filter(
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
9 changes: 5 additions & 4 deletions src/store/reducers/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export const initialState = {
* Should filter transactions without receipt if we received ones
*/
const mergeTransactions = (stateTxs, payloadTxs) => {
console.log(
'🚀 ~ file: wallet.js:29 ~ mergeTransactions ~ payloadTxs:',
payloadTxs
);
const txWithReceipts = payloadTxs.filter(tx => tx.receipt);
const newStateTxs = { ...stateTxs };
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -118,10 +122,7 @@ const reducer = handleActions(
...state,
token: {
...state.token,
transactions: mergeTransactions(
state.token.transactions,
payload.transactions
)
transactions: mergeTransactions(state.token.transactions, payload)
}
alex-sandrk marked this conversation as resolved.
Show resolved Hide resolved
}),

Expand Down
1 change: 1 addition & 0 deletions src/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const subscribeToMainProcessMessages = function(store) {
'transactions-scan-finished',
'transactions-scan-started',
'contracts-scan-finished',
'contracts-updated',
'contracts-scan-started',
'wallet-state-changed',
'coin-price-updated',
Expand Down
Loading