Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { getCurrentSessionFromStorage } from 'src/logic/currentSession/utils'

const loadCurrentSessionFromStorage =
() =>
async (dispatch: Dispatch): Promise<void> => {
const currentSession = await getCurrentSessionFromStorage()
(dispatch: Dispatch): void => {
const currentSession = getCurrentSessionFromStorage()

dispatch(loadCurrentSession(currentSession))
}
Expand Down
10 changes: 3 additions & 7 deletions src/logic/currentSession/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ import { CurrentSessionState } from 'src/logic/currentSession/store/reducer/curr

const CURRENT_SESSION_STORAGE_KEY = 'CURRENT_SESSION'

export const getCurrentSessionFromStorage = async (): Promise<CurrentSessionState | undefined> =>
export const getCurrentSessionFromStorage = (): CurrentSessionState | undefined =>
loadFromStorage(CURRENT_SESSION_STORAGE_KEY)

export const saveCurrentSessionToStorage = async (currentSession: CurrentSessionState): Promise<void> => {
try {
await saveToStorage(CURRENT_SESSION_STORAGE_KEY, currentSession)
} catch (err) {
console.error('Error storing currentSession in localStorage', err)
}
export const saveCurrentSessionToStorage = (currentSession: CurrentSessionState): void => {
saveToStorage(CURRENT_SESSION_STORAGE_KEY, currentSession)
}
4 changes: 2 additions & 2 deletions src/logic/safe/hooks/useLocalSafes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const useLocalSafes = (): LocalSafes => {
// Reload added Safes from the localStorage when addedAddresses changes
useEffect(() => {
const getLocalSafes = () => {
getChains().forEach(async ({ chainId }) => {
const localSafe = await getLocalNetworkSafesById(chainId)
getChains().forEach(({ chainId }) => {
const localSafe = getLocalNetworkSafesById(chainId)
setLocalSafes((prevSafes) => ({
...prevSafes,
...(localSafe && { [chainId]: localSafe }),
Expand Down
12 changes: 5 additions & 7 deletions src/logic/safe/store/actions/fetchSafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ export const buildSafe = async (safeAddress: string): Promise<SafeRecordProps> =
// setting `loadedViaUrl` to false, as `buildSafe` is called on safe Load or Open flows
const safeInfo: Partial<SafeRecordProps> = { address, loadedViaUrl: false }

const [remote, local] = await Promise.all([
getSafeInfo(safeAddress).catch((err) => {
err.log()
return null
}),
getLocalSafe(safeAddress),
])
const local = getLocalSafe(safeAddress)
const remote = await getSafeInfo(safeAddress).catch((err) => {
err.log()
return null
})

// remote (client-gateway)
const remoteSafeInfo = remote ? await extractRemoteSafeInfo(remote) : {}
Expand Down
6 changes: 2 additions & 4 deletions src/logic/safe/store/actions/loadSafesFromStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import { addOrUpdateSafe } from './addOrUpdateSafe'

const loadSafesFromStorage =
() =>
async (dispatch: Dispatch): Promise<void> => {
const safes = await getLocalSafes()
(dispatch: Dispatch): void => {
const safes = getLocalSafes()

if (safes) {
safes.forEach((safeProps) => {
dispatch(addOrUpdateSafe(buildSafe(safeProps)))
})
}

return Promise.resolve()
}

export default loadSafesFromStorage
10 changes: 5 additions & 5 deletions src/logic/safe/store/middleware/notificationsMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ const watchedActions = [ADD_OR_UPDATE_SAFE, ADD_QUEUED_TRANSACTIONS, ADD_HISTORY

const LAST_TIME_USED_LOGGED_IN_ID = 'LAST_TIME_USED_LOGGED_IN_ID'

const sendAwaitingTransactionNotification = async (
const sendAwaitingTransactionNotification = (
dispatch,
safeAddress,
awaitingTxsSubmissionDateList,
notificationKey,
notificationClickedCb,
) => {
): void => {
if (!dispatch || !safeAddress || !awaitingTxsSubmissionDateList || !notificationKey) {
return
}
if (awaitingTxsSubmissionDateList.length === 0) {
return
}

let lastTimeUserLoggedInForSafes = (await loadFromStorage<Record<string, string>>(LAST_TIME_USED_LOGGED_IN_ID)) || {}
let lastTimeUserLoggedInForSafes = loadFromStorage<Record<string, string>>(LAST_TIME_USED_LOGGED_IN_ID) || {}
const lastTimeUserLoggedIn = lastTimeUserLoggedInForSafes[safeAddress]
? lastTimeUserLoggedInForSafes[safeAddress]
: null
Expand All @@ -63,7 +63,7 @@ const sendAwaitingTransactionNotification = async (
...lastTimeUserLoggedInForSafes,
[safeAddress]: new Date(),
}
await saveToStorage(LAST_TIME_USED_LOGGED_IN_ID, lastTimeUserLoggedInForSafes)
saveToStorage(LAST_TIME_USED_LOGGED_IN_ID, lastTimeUserLoggedInForSafes)
}

// any/AnyAction used as our Redux state is not typed
Expand Down Expand Up @@ -121,7 +121,7 @@ const notificationsMiddleware =
)
}

await sendAwaitingTransactionNotification(
sendAwaitingTransactionNotification(
dispatch,
safeAddress,
awaitingTxsSubmissionDateList,
Expand Down
57 changes: 0 additions & 57 deletions src/logic/safe/utils/mocks/remoteConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,62 +64,6 @@
"SPENDING_LIMIT"
]
},
{
"transactionService": "https://safe-transaction.avalanche.gnosis.io",
"chainId": "43114",
"chainName": "Avalanche",
"shortName": "Avalanche",
"l2": true,
"description": "",
"rpcUri": {
"authentication": "NO_AUTHENTICATION",
"value": "https://api.avax.network/ext/bc/C/rpc"
},
"safeAppsRpcUri": {
"authentication": "NO_AUTHENTICATION",
"value": "https://api.avax.network/ext/bc/C/rpc"
},
"publicRpcUri": {
"authentication": "NO_AUTHENTICATION",
"value": "https://api.avax.network/ext/bc/C/rpc"
},
"blockExplorerUriTemplate": {
"address": "https://snowtrace.io/address/{{address}}",
"txHash": "https://snowtrace.io/tx/{{txHash}}",
"api": "https://api.snowtrace.io/api?module={{module}}&action={{action}}&address={{address}}&apiKey={{apiKey}}"
},
"nativeCurrency": {
"name": "Avalanche",
"symbol": "AVAX",
"decimals": 18,
"logoUri": "https://safe-transaction-assets.staging.gnosisdev.com/chains/43114/currency_logo.png"
},
"theme": {
"textColor": "#ffffff",
"backgroundColor": "#e84142"
},
"gasPrice": [],
"disabledWallets": [
"authereum",
"fortmatic",
"keystone",
"lattice",
"opera",
"operaTouch",
"portis",
"torus",
"trezor",
"trust"
],
"features": [
"CONTRACT_INTERACTION",
"DOMAIN_LOOKUP",
"EIP1559",
"ERC721",
"SAFE_APPS",
"SAFE_TX_GAS_OPTIONAL"
]
},
{
"transactionService": "https://safe-transaction-polygon.staging.gnosisdev.com",
"chainId": "137",
Expand Down Expand Up @@ -168,7 +112,6 @@
"fortmatic",
"keystone",
"lattice",
"ledger",
"opera",
"operaTouch",
"portis",
Expand Down
24 changes: 10 additions & 14 deletions src/logic/safe/utils/safeStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,29 @@ export const SAFES_KEY = 'SAFES'

export type StoredSafes = Record<string, SafeRecordProps>

export const loadStoredSafes = (): Promise<StoredSafes | undefined> => {
export const loadStoredSafes = (): StoredSafes | undefined => {
return loadFromStorage<StoredSafes>(SAFES_KEY)
}

export const loadStoredNetworkSafeById = (id: ChainId): Promise<StoredSafes | undefined> => {
export const loadStoredNetworkSafeById = (id: ChainId): StoredSafes | undefined => {
return loadFromStorage<StoredSafes>(SAFES_KEY, getStoragePrefix(id))
}

export const saveSafes = async (safes: StoredSafes): Promise<void> => {
try {
await saveToStorage(SAFES_KEY, safes)
} catch (err) {
console.error('Error storing Safe info in localstorage', err)
}
export const saveSafes = (safes: StoredSafes): void => {
saveToStorage(SAFES_KEY, safes)
}

export const getLocalSafes = async (): Promise<SafeRecordProps[] | undefined> => {
const storedSafes = await loadStoredSafes()
export const getLocalSafes = (): SafeRecordProps[] | undefined => {
const storedSafes = loadStoredSafes()
return storedSafes ? Object.values(storedSafes) : undefined
}

export const getLocalNetworkSafesById = async (id: ChainId): Promise<SafeRecordProps[] | undefined> => {
const storedSafes = await loadStoredNetworkSafeById(id)
export const getLocalNetworkSafesById = (id: ChainId): SafeRecordProps[] | undefined => {
const storedSafes = loadStoredNetworkSafeById(id)
return storedSafes ? Object.values(storedSafes) : undefined
}

export const getLocalSafe = async (safeAddress: string): Promise<SafeRecordProps | undefined> => {
const storedSafes = await loadStoredSafes()
export const getLocalSafe = (safeAddress: string): SafeRecordProps | undefined => {
const storedSafes = loadStoredSafes()
return storedSafes?.[safeAddress]
}
6 changes: 3 additions & 3 deletions src/logic/wallets/transactionDataCheck/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import contractDataImage from './images/contractData.png'

const USER_ENABLED_LEDGER_TX_DATA = 'USER_ENABLED_LEDGER_TX_DATA'
function transactionDataCheck(): any {
return async (stateAndHelpers) => {
return (stateAndHelpers) => {
const { wallet } = stateAndHelpers
const isTransactionDataEnabled = await loadFromStorage<boolean>(USER_ENABLED_LEDGER_TX_DATA)
const isTransactionDataEnabled = loadFromStorage<boolean>(USER_ENABLED_LEDGER_TX_DATA)
if (wallet && wallet.name.toUpperCase() === WALLET_PROVIDER.LEDGER && !isTransactionDataEnabled) {
return {
heading: 'Allow Transaction Data', // edit modal heading here
description: `<div><p><strong>Important</strong>: In order to sign transactions with your Ledger device, you will have to activate the "Contract Data" setting in the Ethereum app on your Ledger.</p><img style="width:100%" src=${contractDataImage} /></div>`, // edit modal description that is displayed here. You can include html strings here and they will be rendered as html elements.
eventCode: 'allowTransactionData',
button: {
text: 'Done',
onclick: async () => await saveToStorage(USER_ENABLED_LEDGER_TX_DATA, true),
onclick: () => saveToStorage(USER_ENABLED_LEDGER_TX_DATA, true),
},
icon: `
<svg height="14" viewBox="0 0 18 14" width="18" xmlns="http://www.w3.org/2000/svg"><g fill="currentColor"><path d="m10.29375 4.05351563c0-.04921875 0-.09140625 0-.13007813 0-1.0546875 0-2.109375 0-3.1640625 0-.43945312.3480469-.76992188.7804688-.7453125.2003906.01054688.3585937.10546875.4992187.24609375.5800781.58359375 1.1566406 1.16367188 1.7367187 1.74023438 1.4695313 1.46953125 2.9390625 2.93906249 4.4050782 4.40859375.1335937.13359375.2425781.27421875.2707031.46757812.0351562.20742188-.0246094.421875-.1652344.58007813-.0246094.028125-.0492187.05273437-.0738281.08085937-2.0601563 2.06367188-4.1203125 4.1238281-6.1804688 6.1875-.2109375.2109375-.4570312.3023438-.7453125.2179688-.2707031-.0808594-.4464843-.2707032-.5132812-.5484375-.0140625-.0738282-.0175781-.1441407-.0140625-.2179688 0-1.0335937 0-2.0707031 0-3.1042969 0-.0386719 0-.08085935 0-.13359372h-5.06953125c-.49570313 0-.80507813-.309375-.80507813-.80859375 0-1.42382813 0-2.84414063 0-4.26796875 0-.49570313.30585938-.8015625.8015625-.8015625h4.93593748z"/><path d="m5.69882812 13.978125h-4.01132812c-.928125 0-1.6875-.8753906-1.6875-1.9511719v-10.06171872c0-1.07578125.75585938-1.95117188 1.6875-1.95117188h4.01132812c.34101563 0 .61523438.31992188.61523438.71015625 0 .39023438-.27421875.71015625-.61523438.71015625h-4.01132812c-.253125 0-.45703125.23554688-.45703125.52734375v10.06171875c0 .2917969.20390625.5273437.45703125.5273437h4.01132812c.34101563 0 .61523438.3199219.61523438.7101563s-.27773438.7171875-.61523438.7171875z"/></g></svg>
Expand Down
14 changes: 10 additions & 4 deletions src/routes/CreateSafePage/CreateSafePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ function CreateSafePage(): ReactElement {
const provider = !!providerName && !isWrongNetwork

useEffect(() => {
async function checkIfSafeIsPendingToBeCreated() {
const checkIfSafeIsPendingToBeCreated = async (): Promise<void> => {
setIsLoading(true)
const safePendingToBeCreated = (await loadFromStorage(SAFE_PENDING_CREATION_STORAGE_KEY)) as CreateSafeFormValues

// Removing the await completely is breaking the tests for a mysterious reason
// @TODO: remove the promise
const safePendingToBeCreated = await Promise.resolve(
Copy link
Member Author

Choose a reason for hiding this comment

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

Removing the promise completely here was breaking the CreateSafePage tests for a mysterious reason, so I kept this for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a @TODO: comment?

loadFromStorage<CreateSafeFormValues>(SAFE_PENDING_CREATION_STORAGE_KEY),
)

if (provider) {
await instantiateSafeContracts()
setSafePendingToBeCreated(safePendingToBeCreated)
Expand All @@ -63,8 +69,8 @@ function CreateSafePage(): ReactElement {
const location = useLocation()
const safeRandomName = useMnemonicSafeName()

async function showSafeCreationProcess(newSafeFormValues: CreateSafeFormValues) {
await saveToStorage(SAFE_PENDING_CREATION_STORAGE_KEY, { ...newSafeFormValues })
const showSafeCreationProcess = (newSafeFormValues: CreateSafeFormValues): void => {
saveToStorage(SAFE_PENDING_CREATION_STORAGE_KEY, { ...newSafeFormValues })
setSafePendingToBeCreated(newSafeFormValues)
}

Expand Down
42 changes: 19 additions & 23 deletions src/routes/CreateSafePage/components/SafeCreationProcess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ function SafeCreationProcess(): ReactElement {
const [showModal, setShowModal] = useState(false)
const [modalData, setModalData] = useState<ModalDataType>({ safeAddress: '' })

const createNewSafe = useCallback(async () => {
const safeCreationFormValues = (await loadFromStorage(SAFE_PENDING_CREATION_STORAGE_KEY)) as CreateSafeFormValues
const createNewSafe = useCallback(() => {
const safeCreationFormValues = loadFromStorage<CreateSafeFormValues>(SAFE_PENDING_CREATION_STORAGE_KEY)

if (!safeCreationFormValues) {
goToWelcomePage()
Expand Down Expand Up @@ -115,27 +115,22 @@ function SafeCreationProcess(): ReactElement {
}, [userAddressAccount])

useEffect(() => {
const load = async () => {
const safeCreationFormValues = (await loadFromStorage(SAFE_PENDING_CREATION_STORAGE_KEY)) as CreateSafeFormValues

if (!safeCreationFormValues) {
goToWelcomePage()
return
}

const safeCreationTxHash = safeCreationFormValues[FIELD_NEW_SAFE_CREATION_TX_HASH]
if (safeCreationTxHash) {
setSafeCreationTxHash(safeCreationTxHash)
} else {
createNewSafe()
}
const safeCreationFormValues = loadFromStorage<CreateSafeFormValues>(SAFE_PENDING_CREATION_STORAGE_KEY)
if (!safeCreationFormValues) {
goToWelcomePage()
return
}

load()
const safeCreationTxHash = safeCreationFormValues[FIELD_NEW_SAFE_CREATION_TX_HASH]
if (safeCreationTxHash) {
setSafeCreationTxHash(safeCreationTxHash)
} else {
createNewSafe()
}
}, [createNewSafe])

const onSafeCreated = async (newSafeAddress: string): Promise<void> => {
const createSafeFormValues = (await loadFromStorage(SAFE_PENDING_CREATION_STORAGE_KEY)) as CreateSafeFormValues
const createSafeFormValues = loadFromStorage<CreateSafeFormValues>(SAFE_PENDING_CREATION_STORAGE_KEY)

if (!createSafeFormValues) {
goToWelcomePage()
Expand Down Expand Up @@ -182,8 +177,8 @@ function SafeCreationProcess(): ReactElement {
})
}

const onRetry = async () => {
const safeCreationFormValues = (await loadFromStorage(SAFE_PENDING_CREATION_STORAGE_KEY)) as CreateSafeFormValues
const onRetry = (): void => {
const safeCreationFormValues = loadFromStorage<CreateSafeFormValues>(SAFE_PENDING_CREATION_STORAGE_KEY)

if (!safeCreationFormValues) {
goToWelcomePage()
Expand All @@ -192,7 +187,7 @@ function SafeCreationProcess(): ReactElement {

setSafeCreationTxHash(undefined)
delete safeCreationFormValues.safeCreationTxHash
await saveToStorage(SAFE_PENDING_CREATION_STORAGE_KEY, safeCreationFormValues)
saveToStorage(SAFE_PENDING_CREATION_STORAGE_KEY, safeCreationFormValues)
createNewSafe()
}

Expand All @@ -201,8 +196,9 @@ function SafeCreationProcess(): ReactElement {
goToWelcomePage()
}

async function onClickModalButton() {
await removeFromStorage(SAFE_PENDING_CREATION_STORAGE_KEY)
function onClickModalButton() {
removeFromStorage(SAFE_PENDING_CREATION_STORAGE_KEY)

const { safeName, safeCreationTxHash, safeAddress } = modalData
history.push({
pathname: generateSafeRoute(SAFE_ROUTES.ASSETS_BALANCES, {
Expand Down
6 changes: 3 additions & 3 deletions src/routes/LoadSafePage/LoadSafePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function Load(): ReactElement {
dispatch(addressBookSafeLoad([...ownerEntries, safeEntry]))
}

const onSubmitLoadSafe = async (values: LoadSafeFormValues) => {
const onSubmitLoadSafe = async (values: LoadSafeFormValues): Promise<void> => {
const address = values[FIELD_LOAD_SAFE_ADDRESS]
if (!isValidAddress(address)) {
return
Expand All @@ -91,10 +91,10 @@ function Load(): ReactElement {

const checksummedAddress = checksumAddress(address || '')
const safeProps = await buildSafe(checksummedAddress)
const storedSafes = (await loadStoredSafes()) || {}
const storedSafes = loadStoredSafes() || {}
storedSafes[checksummedAddress] = safeProps

await saveSafes(storedSafes)
saveSafes(storedSafes)
dispatch(addOrUpdateSafe(safeProps))

// Go to the newly added Safe
Expand Down
Loading