Skip to content

Commit

Permalink
Merge pull request #3749 from Emurgo/release/5.4.500
Browse files Browse the repository at this point in the history
Release / 5.4.500
  • Loading branch information
vsubhuman authored Nov 27, 2024
2 parents db37ee7 + 96411b2 commit 413a23f
Show file tree
Hide file tree
Showing 32 changed files with 325 additions and 141 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const sendTx: ({|
res: error.response?.data || null,
}
Logger.error(`${nameof(RemoteFetcher)}::${nameof(sendTx)} error: ${stringifyError(err)}`);
if (error.request.response.includes('Invalid witness')) {
if (JSON.stringify(error.response?.data ?? '').includes('InvalidWitnessesUTXOW')) {
throw new InvalidWitnessError();
}
throw new SendTransactionApiError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const networks = Object.freeze({
]: CardanoHaskellBaseConfig),
CoinType: CoinTypes.CARDANO,
Fork: CardanoForks.Haskell,
isInProduction: true,
}: NetworkRow),
CardanoPreprodTestnet: ({
NetworkId: 2_50,
Expand Down Expand Up @@ -179,6 +180,14 @@ export const networks = Object.freeze({
}: NetworkRow),
});

export function listRelevantNetworkNamesForEnvironment(): Array<string> {
const keys = Object.keys(networks);
if (environment.isProduction() && !environment.isNightly()) {
return keys.filter(k => networks[k].isInProduction);
}
return keys;
}

export function isTestnet(
network: $ReadOnly<NetworkRow>,
): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export type NetworkRow = {|
* To differentiate these, we need some identifier of the fork
*/
Fork: number,
isInProduction?: boolean,
|};
export const NetworkSchema: {|
+name: 'Network',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,7 @@ Object {
"NetworkFeatureName": "mainnet",
"NetworkId": 0,
"NetworkName": "Cardano Mainnet",
"isInProduction": true,
},
Object {
"Backend": Object {
Expand Down
73 changes: 46 additions & 27 deletions packages/yoroi-extension/app/api/localStorage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import { deserializeTransactionCtorData } from '../../domain/CardanoShelleyTrans
import { maybe } from '../../coreUtils';
import type { StorageAPI } from '@emurgo/yoroi-lib/dist/flags';

declare var chrome;
declare var browser;

const networkForLocalStorage = String(environment.getNetworkName());
const storageKeys = {
USER_LOCALE: networkForLocalStorage + '-USER-LOCALE',
Expand Down Expand Up @@ -117,15 +114,24 @@ export default class LocalStorageApi {

// ========== Select Wallet ========== //

getSelectedWalletId: void => number | null = () => {
const id = localStorage.getItem(storageKeys.SELECTED_WALLET);
if (!id) return null;
getSelectedWalletId: void => Promise<number | null> = async () => {
let id = await getLocalItem(storageKeys.SELECTED_WALLET);
// previously it was stored in window.localStorage, which is not accessible in the mv3 service worker
if (!id) {
id = window?.localStorage.getItem(storageKeys.SELECTED_WALLET);
if (/^\d+$/.test(id)) {
await this.setSelectedWalletId(Number(id));
}
}
if (!id) {
return null;
}
if (isNaN(Number(id))) throw new Error(`Invalid wallet Id: ${id}`);
return Number(id);
};

setSelectedWalletId: number => void = id => {
localStorage.setItem(storageKeys.SELECTED_WALLET, id.toString());
setSelectedWalletId: number => Promise<void> = async (id) => {
await setLocalItem(storageKeys.SELECTED_WALLET, id.toString());
};

// ========== Legacy Theme ========== //
Expand Down Expand Up @@ -161,13 +167,15 @@ export default class LocalStorageApi {

clear: void => Promise<void> = async () => {
const storage = JSON.parse(await this.getStorage());
await Object.keys(storage).forEach(async key => {
// changing this key would cause the tab to close
const isTabCloseKey = new Set(Object.values(TabIdKeys)).has(key);
if (!isTabCloseKey) {
await removeLocalItem(key);
}
});
const tabKeys = new Set(Object.values(TabIdKeys));
await Promise.all(
Object.keys(storage).map(async key => {
// changing this key would cause the tab to close
if (!tabKeys.has(key)) {
await removeLocalItem(key);
}
})
);
};

// ========== Show/hide Balance ========== //
Expand Down Expand Up @@ -213,7 +221,7 @@ export default class LocalStorageApi {
const result = await getLocalItem(storageKeys.DAPP_CONNECTOR_WHITELIST);
if (result === undefined || result === null) return undefined;
const filteredWhitelist = JSON.parse(result);
this.setWhitelist(filteredWhitelist);
await this.setWhitelist(filteredWhitelist);
return filteredWhitelist;
};

Expand Down Expand Up @@ -303,17 +311,26 @@ export default class LocalStorageApi {

unsetAcceptedTosVersion: void => Promise<void> = () => removeLocalItem(storageKeys.ACCEPTED_TOS_VERSION);

// Firefox demands us to re-show the data collection consent screen, so change the key for Firefox
_getIsAnalyticsAllowedKey: () => string = () => {
let key = storageKeys.IS_ANALYTICS_ALLOWED;
if (environment.isFirefox()) {
key += '-firefox';
}
return key;
}

loadIsAnalyticsAllowed: () => Promise<?boolean> = async () => {
const json = await getLocalItem(storageKeys.IS_ANALYTICS_ALLOWED);
const json = await getLocalItem(this._getIsAnalyticsAllowedKey());
if (!json) {
return undefined;
}
return JSON.parse(json);
};

saveIsAnalysticsAllowed: (flag: boolean) => Promise<void> = async flag => {
await setLocalItem(storageKeys.IS_ANALYTICS_ALLOWED, JSON.stringify(flag));
};
saveIsAnalysticsAllowed: (flag: boolean) => Promise<void> = async (flag) => {
await setLocalItem(this._getIsAnalyticsAllowedKey(), JSON.stringify(flag));
}

unsetIsAnalyticsAllowed: void => Promise<void> = () => removeLocalItem(storageKeys.IS_ANALYTICS_ALLOWED);

Expand All @@ -340,13 +357,15 @@ export default class LocalStorageApi {
});

setStorage: ({ [key: string]: string, ... }) => Promise<void> = async localStorageData => {
await Object.keys(localStorageData).forEach(async key => {
// changing this key would cause the tab to close
const isTabCloseKey = new Set(Object.values(TabIdKeys)).has(key);
if (!isTabCloseKey) {
await setLocalItem(key, localStorageData[key]);
}
});
const tabKeys = new Set(Object.values(TabIdKeys));
await Promise.all(
Object.keys(localStorageData).map(async key => {
// changing this key would cause the tab to close
if (!tabKeys.has(key)) {
await setLocalItem(key, localStorageData[key]);
}
})
);
};

getStorage: void => Promise<string> = () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/yoroi-extension/app/api/localStorage/primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const getStorageItemInWeb = async (

/** passing undefined gives you the whole storage as a JSON string */
export async function getLocalItem(key: string | void): Promise<?string> {
const isExtension = environment.userAgentInfo.isExtension();
const isExtension = environment.isExtension();
if (isExtension) {
return await getStorageItemInExtension(key);
}
Expand All @@ -59,7 +59,7 @@ export async function getLocalItem(key: string | void): Promise<?string> {
// =====

export async function setLocalItem(key: string, value: string): Promise<void> {
const isExtension = environment.userAgentInfo.isExtension();
const isExtension = environment.isExtension();
if (isExtension) {
await new Promise((resolve, reject) => {
chrome.storage.local.set(
Expand All @@ -80,7 +80,7 @@ export async function setLocalItem(key: string, value: string): Promise<void> {
// ========

export async function removeLocalItem(key: string): Promise<void> {
const isExtension = environment.userAgentInfo.isExtension();
const isExtension = environment.isExtension();

if (isExtension) {
await new Promise((resolve, reject) => {
Expand All @@ -98,7 +98,7 @@ export async function removeLocalItem(key: string): Promise<void> {
}

export async function clear(): Promise<void> {
const isExtension = environment.userAgentInfo.isExtension();
const isExtension = environment.isExtension();
if (isExtension) {
await new Promise((resolve, reject) => {
chrome.storage.local.clear(
Expand Down Expand Up @@ -136,7 +136,7 @@ type StorageChange = { [key: string]: {|
export function addListener(
listener: StorageChange => void,
): void {
const isExtension = environment.userAgentInfo.isExtension();
const isExtension = environment.isExtension();
if (isExtension) {
chrome.storage.onChanged.addListener((changes, _area) => {
listener(changes);
Expand Down Expand Up @@ -168,7 +168,7 @@ export function addListener(
// =======

export async function isEmptyStorage(): Promise<boolean> {
const isExtension = environment.userAgentInfo.isExtension();
const isExtension = environment.isExtension();
if (isExtension) {
const isEmpty = await getStorageItemInExtension().then(
(data: Object) => Object.keys(data).length === 0
Expand Down
13 changes: 13 additions & 0 deletions packages/yoroi-extension/app/api/thunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
SendTransactionApiError,
GenericApiError,
IncorrectWalletPasswordError,
InvalidWitnessError,
} from './common/errors';
import type { ResponseTicker } from './common/lib/state-fetch/types';
//import type { HandlerType } from '../../chrome/extension/background/handlers/yoroi/type';
Expand Down Expand Up @@ -236,11 +237,13 @@ export async function signAndBroadcastTransaction(
type: SignAndBroadcastTransaction.typeTag,
request: serializableRequest,
});
handleKnownSubmissionErrors(result);
return handleWrongPassword(result, IncorrectWalletPasswordError);
}

export async function broadcastTransaction(request: BroadcastTransactionRequestType): Promise<void> {
const result = await callBackground({ type: BroadcastTransaction.typeTag, request });
handleKnownSubmissionErrors(result);
if (result?.error) {
throw new Error(result.error);
}
Expand Down Expand Up @@ -518,3 +521,13 @@ function handleWrongPassword<
}
return result;
}

function handleKnownSubmissionErrors<
T: { error?: string, ... }
>(
result: T,
): void {
if (result?.error?.includes('api.errors.invalidWitnessError')) {
throw new InvalidWitnessError()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Props = {|
+error?: ?LocalizableError,
+localizedTermsOfUse: string,
+localizedPrivacyNotice: string,
+externalPrivacyPolicyURL: ?string,
|};

type State = {|
Expand Down Expand Up @@ -82,7 +83,13 @@ class LanguageSelectionForm extends Component<Props & InjectedLayoutProps, State
if (target.id === 'tosLink') {
this.setState({ showing: 'tos' });
} else if (target.id === 'privacyLink') {
this.setState({ showing: 'privacy' });
const externalURL = this.props.externalPrivacyPolicyURL;
if (externalURL != null) {
window.open(externalURL, '_blank');
event.preventDefault();
} else {
this.setState({ showing: 'privacy' });
}
}
};

Expand Down
Loading

0 comments on commit 413a23f

Please sign in to comment.