Skip to content

Commit

Permalink
Add some sample files so linting can be tested
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmire committed Mar 8, 2022
1 parent 0ccb400 commit d575ecf
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 39 deletions.
5 changes: 5 additions & 0 deletions dependencies.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module 'loglevel' {
function debug(message: string | Record<string, unknown>): void;
const log = { debug };
export default log;
}
23 changes: 0 additions & 23 deletions ui/helpers/utils/storage-helpers.js

This file was deleted.

30 changes: 30 additions & 0 deletions ui/helpers/utils/storage-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import localforage from 'localforage';

type SerializableValue = Record<string, unknown>;

export async function getStorageItem(
key: string,
): Promise<SerializableValue | undefined> {
try {
const serializedData = await localforage.getItem<string | null>(key);
if (serializedData === null) {
return undefined;
}

return JSON.parse(serializedData) as SerializableValue;
} catch (err) {
return undefined;
}
}

export async function setStorageItem(
key: string,
value: SerializableValue,
): Promise<void> {
try {
const serializedData = JSON.stringify(value);
await localforage.setItem(key, serializedData);
} catch (err) {
console.warn(err);
}
}
41 changes: 25 additions & 16 deletions ui/helpers/utils/tx-helper.js → ui/helpers/utils/tx-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@ import log from 'loglevel';
import { transactionMatchesNetwork } from '../../../shared/modules/transaction.utils';
import { valuesFor } from './util';

type Message = {
metamaskNetworkId: string;
time: number;
};

type MessagesByKey = Record<string, Message> | null | undefined;

export default function txHelper(
unapprovedTxs,
unapprovedMsgs,
personalMsgs,
decryptMsgs,
encryptionPublicKeyMsgs,
typedMessages,
network,
chainId,
) {
unapprovedTxs: MessagesByKey,
unapprovedMsgs: MessagesByKey,
personalMsgs: MessagesByKey,
decryptMsgs: MessagesByKey,
encryptionPublicKeyMsgs: MessagesByKey,
typedMessages: MessagesByKey,
network: string,
chainId: string,
): Message[] {
log.debug('tx-helper called with params:');
log.debug({
unapprovedTxs,
Expand All @@ -25,33 +32,35 @@ export default function txHelper(
});

const txValues = network
? valuesFor(unapprovedTxs).filter((txMeta) =>
? (valuesFor(unapprovedTxs) as Message[]).filter((txMeta) =>
transactionMatchesNetwork(txMeta, chainId, network),
)
: valuesFor(unapprovedTxs);
: (valuesFor(unapprovedTxs) as Message[]);
log.debug(`tx helper found ${txValues.length} unapproved txs`);

const msgValues = valuesFor(unapprovedMsgs);
const msgValues = valuesFor(unapprovedMsgs) as Message[];
log.debug(`tx helper found ${msgValues.length} unsigned messages`);
let allValues = txValues.concat(msgValues);

const personalValues = valuesFor(personalMsgs);
const personalValues = valuesFor(personalMsgs) as Message[];
log.debug(
`tx helper found ${personalValues.length} unsigned personal messages`,
);
allValues = allValues.concat(personalValues);

const decryptValues = valuesFor(decryptMsgs);
const decryptValues = valuesFor(decryptMsgs) as Message[];
log.debug(`tx helper found ${decryptValues.length} decrypt requests`);
allValues = allValues.concat(decryptValues);

const encryptionPublicKeyValues = valuesFor(encryptionPublicKeyMsgs);
const encryptionPublicKeyValues = valuesFor(
encryptionPublicKeyMsgs,
) as Message[];
log.debug(
`tx helper found ${encryptionPublicKeyValues.length} encryptionPublicKey requests`,
);
allValues = allValues.concat(encryptionPublicKeyValues);

const typedValues = valuesFor(typedMessages);
const typedValues = valuesFor(typedMessages) as Message[];
log.debug(`tx helper found ${typedValues.length} unsigned typed messages`);
allValues = allValues.concat(typedValues);

Expand Down

0 comments on commit d575ecf

Please sign in to comment.