mirror of
https://github.com/status-im/safe-react.git
synced 2025-01-11 10:34:06 +00:00
WA-238 Adding fetchTransactions action
This commit is contained in:
parent
89b1b5ffe0
commit
f4ca495ea0
@ -1,10 +1,11 @@
|
||||
// @flow
|
||||
import { List, Map } from 'immutable'
|
||||
import { createTransaction, loadSafeTransactions } from '~/routes/safe/component/Transactions/transactions'
|
||||
import { createTransaction } from '~/routes/safe/component/Transactions/transactions'
|
||||
import { type Transaction } from '~/routes/safe/store/model/transaction'
|
||||
import { SafeFactory } from '~/routes/safe/store/test/builder/safe.builder'
|
||||
import { type Safe } from '~/routes/safe/store/model/safe'
|
||||
import { type Owner } from '~/routes/safe/store/model/owner'
|
||||
import { loadSafeTransactions } from '~/routes/safe/store/actions/fetchTransactions'
|
||||
import { testSizeOfSafesWith, testSizeOfTransactions, testTransactionFrom } from './transactionsHelper'
|
||||
|
||||
describe('Transactions Suite', () => {
|
||||
|
@ -1,8 +1,8 @@
|
||||
// @flow
|
||||
import { List, Map } from 'immutable'
|
||||
import { type Owner, makeOwner } from '~/routes/safe/store/model/owner'
|
||||
import { List } from 'immutable'
|
||||
import { type Owner } from '~/routes/safe/store/model/owner'
|
||||
import { load, TX_KEY } from '~/utils/localStorage'
|
||||
import { type Confirmation, type ConfirmationProps, makeConfirmation } from '~/routes/safe/store/model/confirmation'
|
||||
import { type Confirmation, makeConfirmation } from '~/routes/safe/store/model/confirmation'
|
||||
import { makeTransaction, type Transaction, type TransactionProps } from '~/routes/safe/store/model/transaction'
|
||||
|
||||
const buildConfirmationsFrom = (owners: List<Owner>, creator: string): List<Confirmation> => {
|
||||
@ -52,24 +52,3 @@ export const createTransaction = (
|
||||
|
||||
localStorage.setItem(TX_KEY, JSON.stringify(safeTransactions))
|
||||
}
|
||||
|
||||
export const loadSafeTransactions = () => {
|
||||
const safes = load(TX_KEY) || {}
|
||||
|
||||
return Map().withMutations((map: Map<string, List<Confirmation>>) =>
|
||||
Object.keys(safes).map((safe: string) => {
|
||||
const safeTxs = safes[safe]
|
||||
const safeTxsRecord = safeTxs.map((tx: TransactionProps) => {
|
||||
const { confirmations } = tx
|
||||
const txRecord = makeTransaction({
|
||||
...tx,
|
||||
confirmations: List(confirmations.map((conf: ConfirmationProps) =>
|
||||
makeConfirmation({ ...conf, owner: makeOwner(conf.owner) }))),
|
||||
})
|
||||
|
||||
return txRecord
|
||||
})
|
||||
|
||||
return map.set(safe, List(safeTxsRecord))
|
||||
}))
|
||||
}
|
||||
|
36
src/routes/safe/store/actions/fetchTransactions.js
Normal file
36
src/routes/safe/store/actions/fetchTransactions.js
Normal file
@ -0,0 +1,36 @@
|
||||
// @flow
|
||||
import { List, Map } from 'immutable'
|
||||
import type { Dispatch as ReduxDispatch } from 'redux'
|
||||
import { type GlobalState } from '~/store/index'
|
||||
import { makeOwner } from '~/routes/safe/store/model/owner'
|
||||
import { makeTransaction, type Transaction, type TransactionProps } from '~/routes/safe/store/model/transaction'
|
||||
import { load, TX_KEY } from '~/utils/localStorage'
|
||||
import { type Confirmation, type ConfirmationProps, makeConfirmation } from '~/routes/safe/store/model/confirmation'
|
||||
import addTransactions from './addTransactions'
|
||||
|
||||
export const loadSafeTransactions = () => {
|
||||
const safes = load(TX_KEY) || {}
|
||||
|
||||
return Map().withMutations((map: Map<string, List<Confirmation>>) =>
|
||||
Object.keys(safes).map((safe: string) => {
|
||||
const safeTxs = safes[safe]
|
||||
const safeTxsRecord = safeTxs.map((tx: TransactionProps) => {
|
||||
const { confirmations } = tx
|
||||
const txRecord = makeTransaction({
|
||||
...tx,
|
||||
confirmations: List(confirmations.map((conf: ConfirmationProps) =>
|
||||
makeConfirmation({ ...conf, owner: makeOwner(conf.owner) }))),
|
||||
})
|
||||
|
||||
return txRecord
|
||||
})
|
||||
|
||||
return map.set(safe, List(safeTxsRecord))
|
||||
}))
|
||||
}
|
||||
|
||||
export default () => async (dispatch: ReduxDispatch<GlobalState>) => {
|
||||
const transactions: Map<string, List<Transaction>> = await loadSafeTransactions()
|
||||
|
||||
return dispatch(addTransactions(transactions))
|
||||
}
|
@ -3,7 +3,7 @@ import { List, Map } from 'immutable'
|
||||
import { handleActions, type ActionType } from 'redux-actions'
|
||||
import addTransactions, { ADD_TRANSACTIONS } from '~/routes/safe/store/actions/addTransactions'
|
||||
import { type Transaction } from '~/routes/safe/store/model/transaction'
|
||||
import { loadSafeTransactions } from '~/routes/safe/component/Transactions/transactions'
|
||||
import { loadSafeTransactions } from '~/routes/safe/store/actions/fetchTransactions'
|
||||
|
||||
export const TRANSACTIONS_REDUCER_ID = 'transactions'
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user