Daniel Kmak 985ea0fb89 Ethereum Alarm Clock Integration (#1343)
* [FEATURE] Initial EAC integration.

* Title and explanation

* [FEATURE] Move the Schedule Payment to the main tab.

* [FEATURE] TimeBounty slider.

* [FEATURE] Move to main menu.

* [FEATURE] Redirection to the DApp for details.

* [FEATURE] Timestamp scheduling

* Scheduling: Basic date and time widget

* Linting fixes

* Moved the datetime field to new tab

* Fixed push errors

* Added missing specs

* Undid unintentional UI change

* Fixed some failing tests

* Ignore datetime parameter when checking if a transaction is full

* Added a date selector widget and renamed ScheduleTimestamp to ScheduleDate

* Marked componentDidMount

* Initialized Pikaday

* Revert "Initialized Pikaday"

This reverts commit 4e5bf5b2b882f236f5977400abf9b7092cbd1592.

* Revert "Marked componentDidMount"

This reverts commit 85d52192ac58f4b6ca9219e702f7390cd27e582f.

* Revert "Added a date selector widget and renamed ScheduleTimestamp to ScheduleDate"

This reverts commit aaad0ac9b565a78d1bfc631754160919fd38a59b.

* Converted the date picker into a datetime picker

* Added decent styling to the datetimepicker

* Added validation to the datetime picker

* Fixed prepush errors for scheduling timestamp

* Adjusted validation logic scheduling timestamp

* [FEATURE] Move scheduling to main tab.

* [FEATURE] Timezone selector

* [FEATURE] Scheduling: Timezone selector

* Removed zombie files

* [FEATURE] Reimplement Time Bounty.

* [FEATURE] Time/block selector

* [FEATURE] Add Window Size field.

* [FEATURE] Time/block switch functionality

* Implemented time/block switcher fuctionality

* [FEATURE] Add Schedule Gas Price field.

* [FEATURE] Scheduling toggle

* [FEATURE] Add basic styling and network check.

* [FEATURE] Add Schedule Gas Limit field

* [FEATURE] "Scheduled" button styling

* Reordered, renamed and centered scheduling elements

* Added the toggle button styling

* Class -> ClassName

* [FEATURE] Add Deposit field

*  [FEATURE] Move scheduling code into one directory

* [FIX] Scheduling responsiveness

* [FIX] Datetime picker not working on md screens

* [FEATURE] Timestamp Scheduling basic functionality

* [FIX] Fix data serialization.

* [FEATURE] Timezone inclusion

* [FEATURE] Add ChronoLogic logo.

* [FEATURE] Add link to image.

* [FIX] Update CSS of logo.

* [FEATURE] Default Window Size

* [FEATURE] Modified Help component to enable acting as a tooltip

* [FEATURE] Call contract to validate scheduling params

* [FIX] Change moment import to fix tests

* [FEATURE] Gas estimation for scheduling

* [FEATURE] Additional validation

* [FEATURE] UI changes and descriptions

* [FEATURE] Add tooltip to window and fix fee display.

* [FIX] Fix ethereumjs-abi dependency.

* [FEATURE] Hide scheduling when sending tokens.

* [FIX] Improved styling datetime picker

* [FEATURE] Add Redux state for scheduling

* [FEATURE] Create Toggle component, Share code between components

* [FEATURE] Use Tooltip component for help.

* [FEATURE] Better datetime picker

* [FEATURE] Remove fee

* Trigger mycryptobuild

* [FIX] Timestamp scheduling - Validation match

* [FIX] EAC integration touchups

* [FIX] Code review fixes

* [FIX] Window Size type

* [FIX] Type fixes.

* [FIX] Make tooltips only show on icons + resposiveness fixes

* [FIX] Break tooltips into more lines

* [FIX] Remove unnecessary code.

* [FIX] Remove unnecessary code.

* [FIX] Remove unnecessary types declaration.

* [FIX] Fee class names
2018-04-14 17:21:33 -05:00

145 lines
4.2 KiB
TypeScript

import { app, dialog, BrowserWindow } from 'electron';
import { autoUpdater, UpdateInfo } from 'electron-updater';
import { APP_TITLE, REPOSITORY } from '../constants';
import TEST_RELEASE from './testrelease.json';
autoUpdater.autoDownload = false;
// Set to 'true' if you want to test update behavior. Requires a recompile.
const shouldMockUpdate = false && process.env.NODE_ENV !== 'production';
const shouldMockUpdateError = false && process.env.NODE_ENV !== 'production';
let hasRunUpdater = false;
let hasStartedUpdating = false;
enum AutoUpdaterEvents {
CHECKING_FOR_UPDATE = 'checking-for-update',
UPDATE_AVAILABLE = 'update-available',
DOWNLOAD_PROGRESS = 'download-progress',
UPDATE_DOWNLOADED = 'update-downloaded',
ERROR = 'error'
}
export default function(mainWindow: BrowserWindow) {
if (hasRunUpdater) {
return;
}
hasRunUpdater = true;
autoUpdater.on(AutoUpdaterEvents.UPDATE_AVAILABLE, (info: UpdateInfo) => {
dialog.showMessageBox(
{
type: 'question',
buttons: ['Yes, start downloading', 'Maybe later'],
title: `An Update is Available (v${info.version})`,
message: `An Update is Available (v${info.version})`,
detail:
'A new version has been released. Would you like to start downloading the update? You will be notified when the download is finished.'
},
response => {
if (response === 0) {
if (shouldMockUpdate) {
mockDownload();
} else {
autoUpdater.downloadUpdate();
}
}
}
);
hasStartedUpdating = true;
});
autoUpdater.on(AutoUpdaterEvents.DOWNLOAD_PROGRESS, (progress: any) => {
mainWindow.setTitle(`${APP_TITLE} (Downloading update... ${Math.round(progress.percent)}%)`);
mainWindow.setProgressBar(progress.percent / 100);
});
autoUpdater.on(AutoUpdaterEvents.UPDATE_DOWNLOADED, () => {
resetWindowFromUpdates(mainWindow);
dialog.showMessageBox(
{
type: 'question',
buttons: ['Yes, restart now', 'Maybe later'],
title: 'Update Has Been Downloaded',
message: 'Download complete!',
detail: `The new version of ${APP_TITLE} has finished downloading. Would you like to restart to complete the installation?`
},
response => {
if (response === 0) {
if (shouldMockUpdate) {
app.quit();
} else {
autoUpdater.quitAndInstall();
}
}
}
);
});
autoUpdater.on(AutoUpdaterEvents.ERROR, (err: Error) => {
console.error('Update failed with an error');
console.error(err);
// If they haven't started updating yet, just fail silently
if (!hasStartedUpdating) {
return;
}
resetWindowFromUpdates(mainWindow);
dialog.showErrorBox(
'Downloading Update has Failed',
`The update could not be downloaded. Restart the app and try again later, or manually install the new update at ${REPOSITORY}/releases\n\n(${
err.name
}: ${err.message})`
);
});
// Kick off the check
autoUpdater.checkForUpdatesAndNotify();
// Simulate a test release
if (shouldMockUpdate) {
mockUpdateCheck();
}
}
function resetWindowFromUpdates(window: BrowserWindow) {
window.setTitle('MyCrypto');
window.setProgressBar(-1); // Clears progress bar
}
// Mock functions for dev testing
function mockUpdateCheck() {
autoUpdater.emit(AutoUpdaterEvents.CHECKING_FOR_UPDATE);
setTimeout(() => {
autoUpdater.emit(AutoUpdaterEvents.UPDATE_AVAILABLE, TEST_RELEASE);
}, 3000);
}
function mockDownload() {
for (let i = 0; i < 11; i++) {
setTimeout(() => {
if (i >= 5 && shouldMockUpdateError) {
if (i === 5) {
autoUpdater.emit(
AutoUpdaterEvents.ERROR,
new Error('Test error, nothing actually failed')
);
}
return;
}
const total = 150000000;
autoUpdater.emit(AutoUpdaterEvents.DOWNLOAD_PROGRESS, {
bytesPerSecond: Math.round(Math.random() * 100000000),
percent: i * 10,
transferred: total / i,
total
});
if (i === 10) {
autoUpdater.emit(AutoUpdaterEvents.UPDATE_DOWNLOADED);
}
}, 500 * i);
}
}