/* * Copyright 2019 balena.io * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import * as React from 'react'; import { Flex } from 'rendition'; import { v4 as uuidV4 } from 'uuid'; import * as flashState from '../../models/flash-state'; import * as selectionState from '../../models/selection-state'; import * as settings from '../../models/settings'; import { Actions, store } from '../../models/store'; import * as analytics from '../../modules/analytics'; import { FlashAnother } from '../flash-another/flash-another'; import { FlashResults, FlashError } from '../flash-results/flash-results'; import { SafeWebview } from '../safe-webview/safe-webview'; function restart(goToMain: () => void) { selectionState.deselectAllDrives(); analytics.logEvent('Restart'); // Reset the flashing workflow uuid store.dispatch({ type: Actions.SET_FLASHING_WORKFLOW_UUID, data: uuidV4(), }); goToMain(); } async function getSuccessBannerURL() { return ( (await settings.get('successBannerURL')) ?? 'https://www.balena.io/etcher/success-banner?borderTop=false&darkBackground=true' ); } function FinishPage({ goToMain }: { goToMain: () => void }) { const [webviewShowing, setWebviewShowing] = React.useState(false); const [successBannerURL, setSuccessBannerURL] = React.useState(''); (async () => { setSuccessBannerURL(await getSuccessBannerURL()); })(); const flashResults = flashState.getFlashResults(); const errors: FlashError[] = ( store.getState().toJS().failedDeviceErrors || [] ).map(([, error]: [string, FlashError]) => ({ ...error, })); const { averageSpeed, blockmappedSize, bytesWritten, failed, size } = flashState.getFlashState(); const { skip, results = { bytesWritten, sourceMetadata: { size, blockmappedSize, }, averageFlashingSpeed: averageSpeed, devices: { failed, successful: 0 }, }, } = flashResults; return ( { restart(goToMain); }} /> {successBannerURL.length && ( )} ); } export default FinishPage;