-
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mobile): firmware upgrade (#15184)
* fix(connect): make fetch work in react native * refactor(suite): move FW upgrade logic to common package * feat(mobile): make some atoms easily animatable * feat(mobile): firmware upgrade * fix: formatting and deps * refactor(suite): map operation to translation ID * refactor(suite): add transport selectors * refactor(suite): remove useFirmware hook * chore: bug fixes --------- Co-authored-by: Jan Komarek <jan.komarek@satoshilabs.com>
- Loading branch information
Showing
98 changed files
with
1,630 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,32 @@ | ||
import { HttpRequestType, HttpRequestReturnType, HttpRequestOptions } from './assetsTypes'; | ||
import { tryLocalAssetRequire } from './assetUtils'; | ||
|
||
export const httpRequest = (url: string, _type: string): any => tryLocalAssetRequire(url); | ||
export function httpRequest<T extends HttpRequestType>( | ||
url: string, | ||
type: T, | ||
options?: HttpRequestOptions, | ||
): Promise<HttpRequestReturnType<T>> { | ||
const asset = options?.skipLocalForceDownload ? null : tryLocalAssetRequire(url); | ||
|
||
if (!asset) { | ||
return fetch(url, { | ||
...options, | ||
}) | ||
.then(response => { | ||
if (type === 'binary') { | ||
return response.arrayBuffer() as unknown as HttpRequestReturnType<T>; | ||
} | ||
if (type === 'json') { | ||
return response.json() as unknown as HttpRequestReturnType<T>; | ||
} | ||
|
||
return response.text() as unknown as HttpRequestReturnType<T>; | ||
}) | ||
.catch(error => { | ||
console.error('httpRequest native error', error); | ||
throw error; | ||
}); | ||
} | ||
|
||
return asset as Promise<HttpRequestReturnType<T>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,26 @@ | ||
// https://github.com/trezor/connect/blob/develop/src/js/env/node/networkUtils.js | ||
|
||
import fetch from 'cross-fetch'; | ||
import { promises as fs } from 'fs'; | ||
|
||
import { httpRequest as browserHttpRequest } from './assets-browser'; | ||
import { HttpRequestOptions, HttpRequestReturnType, HttpRequestType } from './assetsTypes'; | ||
import { tryLocalAssetRequire } from './assetUtils'; | ||
|
||
if (global && typeof global.fetch !== 'function') { | ||
global.fetch = fetch; | ||
} | ||
|
||
export function httpRequest( | ||
url: string, | ||
type: 'text', | ||
options?: RequestInit, | ||
skipLocalForceDownload?: boolean, | ||
): Promise<string>; | ||
|
||
export function httpRequest( | ||
export function httpRequest<T extends HttpRequestType>( | ||
url: string, | ||
type: 'binary', | ||
options?: RequestInit, | ||
skipLocalForceDownload?: boolean, | ||
): Promise<ArrayBuffer>; | ||
|
||
export function httpRequest( | ||
url: string, | ||
type: 'json', | ||
options?: RequestInit, | ||
skipLocalForceDownload?: boolean, | ||
): Promise<Record<string, any>>; | ||
|
||
export function httpRequest( | ||
url: any, | ||
type: any, | ||
options?: RequestInit, | ||
skipLocalForceDownload?: boolean, | ||
) { | ||
const asset = skipLocalForceDownload ? null : tryLocalAssetRequire(url); | ||
type: T, | ||
options?: HttpRequestOptions, | ||
): Promise<HttpRequestReturnType<T>> { | ||
const asset = options?.skipLocalForceDownload ? null : tryLocalAssetRequire(url); | ||
|
||
if (!asset) { | ||
return /^https?/.test(url) ? browserHttpRequest(url, type, options) : fs.readFile(url); | ||
return /^https?/.test(url) | ||
? browserHttpRequest(url, type, options) | ||
: (fs.readFile(url) as Promise<HttpRequestReturnType<T>>); | ||
} | ||
|
||
return asset; | ||
return asset as Promise<HttpRequestReturnType<T>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export type HttpRequestType = 'text' | 'binary' | 'json'; | ||
|
||
export type HttpRequestReturnType<T extends HttpRequestType> = T extends 'text' | ||
? string | ||
: T extends 'binary' | ||
? ArrayBuffer | Buffer | ||
: T extends 'json' | ||
? Record<string, any> | ||
: never; | ||
|
||
export interface HttpRequestOptions extends RequestInit { | ||
skipLocalForceDownload?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/suite/src/actions/firmware/__fixtures__/firmwareActions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/suite/src/actions/firmware/__tests__/firmwareActions.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/suite/src/components/firmware/FirmwareUpdateHashCheckError.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.