diff --git a/embark-ui/src/api/index.js b/embark-ui/src/api/index.js
index 554f0c710..2175b86d5 100644
--- a/embark-ui/src/api/index.js
+++ b/embark-ui/src/api/index.js
@@ -22,7 +22,7 @@ export function fetchTransactions(blockFrom) {
}
export function fetchTransaction(hash) {
- return axios.get(`${constants.httpEndpoint}/blockchain/transactions${hash}`);
+ return axios.get(`${constants.httpEndpoint}/blockchain/transactions/${hash}`);
}
export function fetchProcesses() {
diff --git a/embark-ui/src/containers/AccountContainer.js b/embark-ui/src/containers/AccountContainer.js
index dab3ade9b..0bfa23e24 100644
--- a/embark-ui/src/containers/AccountContainer.js
+++ b/embark-ui/src/containers/AccountContainer.js
@@ -32,7 +32,7 @@ function mapStateToProps(state, props) {
if(state.accounts.data) {
return {account: state.accounts.data.find(account => account.address === props.match.params.address)};
}
- return null;
+ return {};
}
AccountContainer.propTypes = {
diff --git a/embark-ui/src/containers/BlockContainer.js b/embark-ui/src/containers/BlockContainer.js
index d95477f68..aef7e1d5c 100644
--- a/embark-ui/src/containers/BlockContainer.js
+++ b/embark-ui/src/containers/BlockContainer.js
@@ -21,7 +21,7 @@ class BlockContainer extends Component {
return (
-
+
);
@@ -30,9 +30,9 @@ class BlockContainer extends Component {
function mapStateToProps(state, props) {
if(state.blocks.data) {
- return {block: state.blocks.data.find(block => block.number === props.match.params.blockNumber)};
+ return {block: state.blocks.data.find(block => block.number.toString() === props.match.params.blockNumber)};
}
- return null;
+ return {};
}
BlockContainer.propTypes = {
diff --git a/embark-ui/src/containers/TransactionContainer.js b/embark-ui/src/containers/TransactionContainer.js
index 22707b142..2d98b3b15 100644
--- a/embark-ui/src/containers/TransactionContainer.js
+++ b/embark-ui/src/containers/TransactionContainer.js
@@ -20,7 +20,7 @@ class TransactionContainer extends Component {
return (
-
+
);
}
@@ -30,7 +30,7 @@ function mapStateToProps(state, props) {
if(state.transactions.data) {
return {transaction: state.transactions.data.find(transaction => transaction.hash === props.match.params.hash)};
}
- return null;
+ return {};
}
TransactionContainer.propTypes = {
diff --git a/embark-ui/src/reducers/accountsReducer.js b/embark-ui/src/reducers/accountsReducer.js
index 0fb9e6782..90e11b83e 100644
--- a/embark-ui/src/reducers/accountsReducer.js
+++ b/embark-ui/src/reducers/accountsReducer.js
@@ -1,13 +1,23 @@
import {RECEIVE_ACCOUNTS, RECEIVE_ACCOUNTS_ERROR, RECEIVE_ACCOUNT, RECEIVE_ACCOUNT_ERROR} from "../actions";
+function filterAccount(account, index, self) {
+ return index === self.findIndex((a) => a.address === account.address);
+}
+
export default function accounts(state = {}, action) {
switch (action.type) {
case RECEIVE_ACCOUNTS:
- return Object.assign({}, state, {data: action.accounts.data});
+ return {
+ ...state, data: [...action.accounts.data, ...state.data || []]
+ .filter(filterAccount)
+ };
case RECEIVE_ACCOUNTS_ERROR:
return Object.assign({}, state, {error: true});
case RECEIVE_ACCOUNT:
- return Object.assign({}, state, {data: action.account.data});
+ return {
+ ...state, data: [action.account.data, ...state.data || []]
+ .filter(filterAccount)
+ };
case RECEIVE_ACCOUNT_ERROR:
return Object.assign({}, state, {error: true});
default:
diff --git a/embark-ui/src/reducers/blocksReducer.js b/embark-ui/src/reducers/blocksReducer.js
index 9b4c8de2f..124f96a76 100644
--- a/embark-ui/src/reducers/blocksReducer.js
+++ b/embark-ui/src/reducers/blocksReducer.js
@@ -1,15 +1,31 @@
-import {RECEIVE_BLOCKS, RECEIVE_BLOCKS_ERROR} from "../actions";
+import {RECEIVE_BLOCK, RECEIVE_BLOCK_ERROR, RECEIVE_BLOCKS, RECEIVE_BLOCKS_ERROR} from "../actions";
+
+function sortBlock(a, b) {
+ return b.number - a.number;
+}
+
+function filterBlock(block, index, self) {
+ return index === self.findIndex((t) => t.number === block.number);
+}
export default function blocks(state = {}, action) {
switch (action.type) {
case RECEIVE_BLOCKS:
return {
- ...state, data: [...state.data || [], ...action.blocks.data]
- .filter((block, index, self) => index === self.findIndex((t) => t.number === block.number))
- .sort((a, b) => b.number - a.number)
+ ...state, data: [...action.blocks.data, ...state.data || []]
+ .filter(filterBlock)
+ .sort(sortBlock)
};
case RECEIVE_BLOCKS_ERROR:
return Object.assign({}, state, {error: true});
+ case RECEIVE_BLOCK:
+ return {
+ ...state, data: [action.block.data, ...state.data || []]
+ .filter(filterBlock)
+ .sort(sortBlock)
+ };
+ case RECEIVE_BLOCK_ERROR:
+ return Object.assign({}, state, {error: true});
default:
return state;
}
diff --git a/embark-ui/src/reducers/transactionsReducer.js b/embark-ui/src/reducers/transactionsReducer.js
index e2f3b290a..a2cc6b5ee 100644
--- a/embark-ui/src/reducers/transactionsReducer.js
+++ b/embark-ui/src/reducers/transactionsReducer.js
@@ -1,21 +1,35 @@
-import {RECEIVE_TRANSACTIONS, RECEIVE_TRANSACTIONS_ERROR} from "../actions";
+import {RECEIVE_TRANSACTION, RECEIVE_TRANSACTION_ERROR, RECEIVE_TRANSACTIONS, RECEIVE_TRANSACTIONS_ERROR} from "../actions";
const BN_FACTOR = 10000;
+function sortTransaction(a, b) {
+ return ((BN_FACTOR * b.blockNumber) + b.transactionIndex) - ((BN_FACTOR * a.blockNumber) + a.transactionIndex);
+}
+
+function filterTransaction(tx, index, self) {
+ return index === self.findIndex((t) => (
+ t.blockNumber === tx.blockNumber && t.transactionIndex === tx.transactionIndex
+ ));
+}
+
export default function transactions(state = {}, action) {
switch (action.type) {
case RECEIVE_TRANSACTIONS:
return {
- ...state, data: [...state.data || [], ...action.transactions.data]
- .filter((tx, index, self) => index === self.findIndex((t) => (
- t.blockNumber === tx.blockNumber && t.transactionIndex === tx.transactionIndex
- )))
- .sort((a, b) => (
- ((BN_FACTOR * b.blockNumber) + b.transactionIndex) - ((BN_FACTOR * a.blockNumber) + a.transactionIndex))
- )
+ ...state, data: [...action.transactions.data, ...state.data || []]
+ .filter(filterTransaction)
+ .sort(sortTransaction)
};
case RECEIVE_TRANSACTIONS_ERROR:
return Object.assign({}, state, {error: true});
+ case RECEIVE_TRANSACTION:
+ return {
+ ...state, data: [action.transaction.data, ...state.data || []]
+ .filter(filterTransaction)
+ .sort(sortTransaction)
+ };
+ case RECEIVE_TRANSACTION_ERROR:
+ return Object.assign({}, state, {error: true});
default:
return state;
}
diff --git a/embark-ui/src/sagas/index.js b/embark-ui/src/sagas/index.js
index a55ea6fd0..c4db69ce3 100644
--- a/embark-ui/src/sagas/index.js
+++ b/embark-ui/src/sagas/index.js
@@ -57,7 +57,7 @@ export function *watchFetchBlocks() {
export function *fetchAccount(payload) {
try {
- const account = yield call(api.fetchAccounts, payload.address);
+ const account = yield call(api.fetchAccount, payload.address);
yield put(actions.receiveAccount(account));
} catch (e) {
yield put(actions.receiveAccountError());