Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
use getBlockSize
Browse files Browse the repository at this point in the history
  • Loading branch information
gre committed Jan 15, 2021
1 parent a02f215 commit 7bd5015
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/apps/hw.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export const listApps = (
blocks ||
Math.ceil(
((installedAppVersion || availableAppVersion || { bytes: 0 })
.bytes || 0) / deviceModel.blockSize
.bytes || 0) / deviceModel.getBlockSize(deviceInfo.version)
);
const updated =
appsThatKeepChangingHashes.includes(name) ||
Expand Down
10 changes: 7 additions & 3 deletions src/apps/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const reducer = (state: State, action: Action): State => {
hash: app ? app.hash : "",
blocks:
app && app.bytes
? Math.ceil(app.bytes / state.deviceModel.blockSize)
? Math.ceil(app.bytes / getBlockSize(state))
: 0,
version: app ? app.version : "",
availableVersion: app ? app.version : "",
Expand Down Expand Up @@ -367,7 +367,7 @@ export const distribute = (
config?: $Shape<typeof defaultConfig>
): AppsDistribution => {
const { warnMemoryRatio, sortApps } = { ...defaultConfig, ...config };
const blockSize = state.deviceModel.blockSize;
const blockSize = getBlockSize(state);
const totalBytes = state.deviceModel.memorySize;
const totalBlocks = Math.floor(totalBytes / blockSize);
const osBytes = (state.firmware && state.firmware.bytes) || 0;
Expand Down Expand Up @@ -404,14 +404,18 @@ export const distribute = (
};
};

export function getBlockSize(state: State): number {
return state.deviceModel.getBlockSize(state.deviceInfo.version);
}

// tells if the state is "incomplete" to implement the Manager v2 feature
// this happens when some apps are unrecognized
export const isIncompleteState = (state: State): boolean =>
state.installed.some((a) => !a.name);

// calculate if a given state (typically a predicted one) is out of memory (meaning impossible to reach with a device)
export const isOutOfMemoryState = (state: State): boolean => {
const blockSize = state.deviceModel.blockSize;
const blockSize = getBlockSize(state);
const totalBytes = state.deviceModel.memorySize;
const totalBlocks = Math.floor(totalBytes / blockSize);
const osBytes = (state.firmware && state.firmware.bytes) || 0;
Expand Down

1 comment on commit 7bd5015

@vercel
Copy link

@vercel vercel bot commented on 7bd5015 Jan 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.