Skip to content

Commit

Permalink
[DDW-269] init
Browse files Browse the repository at this point in the history
  • Loading branch information
thedanheller committed Jul 6, 2020
1 parent 50e318a commit dc821fa
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 12 deletions.
4 changes: 2 additions & 2 deletions source/common/types/downloadManager.types.js
Expand Up @@ -143,8 +143,8 @@ export type DownloadLocalDataRequest = {
};

export type DownloadLocalDataResponse = {
data: DownloadData,
progress: DownloadProgress,
data?: DownloadData,
progress?: DownloadProgress,
};

export type DownloadsLocalDataRequest = {
Expand Down
4 changes: 2 additions & 2 deletions source/main/ipc/downloadManagerChannel.js
Expand Up @@ -111,10 +111,10 @@ const requestResumeDownload = async (
const downloadLocalData = await getDownloadLocalData(
resumeDownloadRequestPayload
);
const { temporaryFilename, originalFilename } = downloadLocalData.data;
const { temporaryFilename, originalFilename } = downloadLocalData.data || {};
const { downloadId: id, fileUrl, destinationDirectoryName, options } =
downloadLocalData.data || {};
if (!id) throw new Error('Invalid download ID');
if (!id) throw new Error('Invalid download ID 2');
const requestDownloadPayload = {
id,
fileUrl,
Expand Down
2 changes: 1 addition & 1 deletion source/main/utils/mainLocalStorage.js
Expand Up @@ -24,7 +24,7 @@ export const downloadManagerLocalStorage = {
key: STORAGE_KEYS.DOWNLOAD_MANAGER,
id,
})) || {};
if (!data || !progress) throw new Error('Invalid download Id');
// if (!data || !progress) return {};
return { data, progress };
},
getAll: async () => {
Expand Down
5 changes: 5 additions & 0 deletions source/renderer/app/api/api.js
Expand Up @@ -189,6 +189,9 @@ import { deleteTransaction } from './transactions/requests/deleteTransaction';
import { WALLET_BYRON_KINDS } from '../config/walletRestoreConfig';
import ApiError from '../domains/ApiError';

// @UPDATE TODO
import dummyUpdate from './news/dummy-update.json';

const { isIncentivizedTestnet, isShelleyTestnet } = global;

export default class AdaApi {
Expand Down Expand Up @@ -1650,6 +1653,8 @@ export default class AdaApi {
throw new Error('Unable to fetch news');
}

news.items.push(dummyUpdate);

// Fetch news verification hash
let newsHash: string;
let expectedNewsHash: string;
Expand Down
32 changes: 32 additions & 0 deletions source/renderer/app/api/news/dummy-update.json
@@ -0,0 +1,32 @@
{
"title": {
"en-US": "Daedalus Shelley Testnet 1.1.0-STN1",
"ja-JP": "Daedalus Shelley Testnet 1.1.0-STN1"
},
"content": {
"en-US": "This second Daedalus release for the Shelley Testnet brings balance check functionality to those who participated in and earned rewards during the Incentivized Testnet program. It allows these users to check their rewards balance on the Shelley Testnet network, prior to claiming actual rewards on the Cardano mainnet following the Shelley hard fork later this summer. \n\nYou can find instructions on how to do this in the [release notes](https://iohk.zendesk.com/hc/en-us/articles/900001606746).",
"ja-JP": "このShelleyテストネット用Daedalusリリース第2弾は、インセンティブ付きテストネットプログラムに参加し、報酬を獲得したユーザー向けに残高チェック機能を搭載しています。対象ユーザーは、今夏実施されるShelleyハードフォーク後に可能となるCardanoメインネットにおける報酬申請に先立ち、報酬残高をShelleyテストネットネットワークで確認できます。\n\n確認方法の詳細は[リリースノート](https://iohk.zendesk.com/hc/ja/articles/900001606746)をご覧ください。"
},
"target": {
"daedalusVersion": "1.2.0-STN1",
"platforms": ["darwin", "win32", "linux"]
},
"action": {
"label": {
"en-US": "Download Daedalus at testnets.cardano.org",
"ja-JP": "testnets.cardano.orgからダウンロードする"
},
"url": {
"en-US": "https://testnets.cardano.org/en/shelley/get-started/wallet/",
"ja-JP": "https://testnets.cardano.org/en/shelley/get-started/wallet/"
}
},
"download": {
"darwin": "https://update-cardano-mainnet.iohk.io/daedalus-1.1.0-mainnet-12849.pkg",
"win32": "https://update-cardano-mainnet.iohk.io/daedalus-1.1.0-mainnet-12849.exe",
"linux": "https://update-cardano-mainnet.iohk.io/daedalus-1.1.0-mainnet-12849.bin"
},
"date": 1594043606135,
"type": "update",
"id": "dswkljhfksdhfksdhf"
}
7 changes: 6 additions & 1 deletion source/renderer/app/api/news/types.js
Expand Up @@ -17,7 +17,12 @@ export type NewsTarget = {
platform: string,
};

export type NewsType = 'incident' | 'alert' | 'announcement' | 'info';
export type NewsType =
| 'incident'
| 'alert'
| 'announcement'
| 'info'
| 'update';

export type NewsTimestamp = number;

Expand Down
7 changes: 7 additions & 0 deletions source/renderer/app/domains/News.js
Expand Up @@ -16,11 +16,13 @@ export const NewsTypes: {
ALERT: NewsType,
ANNOUNCEMENT: NewsType,
INFO: NewsType,
UPDATE: NewsType,
} = {
INCIDENT: 'incident',
ALERT: 'alert',
ANNOUNCEMENT: 'announcement',
INFO: 'info',
UPDATE: 'update',
};

export type NewsTypesStateType = {
Expand Down Expand Up @@ -67,6 +69,7 @@ class NewsCollection {
''
);
const targetPlatforms = get(newsItem, ['target', 'platforms']);

return (
(!availableTargetVersionRange ||
(availableTargetVersionRange &&
Expand Down Expand Up @@ -154,6 +157,10 @@ class NewsCollection {
// Order read from newest to oldest
return orderBy(read, 'date', 'asc');
}

@computed get updates(): Array<News> {
return this.unread.filter(item => item.type === NewsTypes.UPDATE);
}
}

export default {
Expand Down
31 changes: 25 additions & 6 deletions source/renderer/app/stores/AppUpdateStore.js
@@ -1,10 +1,11 @@
// @flow
import { action, computed, observable, runInAction } from 'mobx';
import { action, computed, observable, runInAction, autorun } from 'mobx';
import Store from './lib/Store';
import Request from './lib/LocalizedRequest';
import type { AppInfo, GetLatestAppVersionResponse } from '../api/nodes/types';
import { APP_UPDATE_POLL_INTERVAL } from '../config/timingConfig';
import { rebuildApplicationMenu } from '../ipc/rebuild-application-menu';
import NewsDomains from '../domains/News';
import {
requestDownloadChannel,
getDownloadLocalDataChannel,
Expand All @@ -13,6 +14,8 @@ import {
import type { DownloadMainResponse } from '../../../common/ipc/api';
import { DOWNLOAD_EVENT_TYPES } from '../../../common/config/downloadManagerConfig';

const { News } = NewsDomains;

const APP_UPDATE_DOWNLOAD_ID = 'appUpdate';

export default class AppUpdateStore extends Store {
Expand All @@ -26,6 +29,8 @@ export default class AppUpdateStore extends Store {
@observable nextUpdateVersion: ?string = null;
@observable applicationVersion: ?number = null;
@observable downloadProgress: ?number = null;
@observable availableUpdates: Array<any> = [];

// @observable updateFileUrl: ?string = null;
@observable updateFileUrl: ?string =
'https://update-cardano-mainnet.iohk.io/daedalus-1.1.0-mainnet-12849.pkg';
Expand Down Expand Up @@ -63,16 +68,30 @@ export default class AppUpdateStore extends Store {
APP_UPDATE_POLL_INTERVAL
);
}

// const availableUpdates = this.checkAvailableUpdates;
// console.log('availableUpdates ...', availableUpdates);

// this.watchAppUpdate();
// console.log('this._disposer', this._disposer);
}

_managePendingUpdate = async () => {
@computed get checkAvailableUpdates(): Array<News> {
const { updates } = this.stores.newsFeed.newsFeedData;
return updates.filter(
update =>
!this.availableUpdates.find(
availableUpdate => availableUpdate.id === update.id
)
);
}

checkUpdate = autorun(async () => {
const updates = this.checkAvailableUpdates;
const downloadLocalData = await getDownloadLocalDataChannel.request({
id: APP_UPDATE_DOWNLOAD_ID,
});
// eslint-disable-next-line
console.log('downloadLocalData', downloadLocalData);
return downloadLocalData;
};
});

_manageUpdateResponse = ({
eventType,
Expand Down
1 change: 1 addition & 0 deletions source/renderer/app/stores/NewsFeedStore.js
Expand Up @@ -234,6 +234,7 @@ export default class NewsFeedStore extends Store {
};
});
}

return new News.NewsCollection(news);
}

Expand Down
9 changes: 9 additions & 0 deletions source/renderer/app/utils/waitFor.js
@@ -0,0 +1,9 @@
// @flow

export const waitFor = (conditionFunction: Function): Promise<any> => {
const poll = resolve => {
if (conditionFunction()) resolve();
else setTimeout(() => poll(resolve), 400);
};
return new Promise(poll);
};

0 comments on commit dc821fa

Please sign in to comment.