Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MyLand refresh/navigation fix #333

Merged
merged 21 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from 14 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
7 changes: 7 additions & 0 deletions decentraland/constants/MyAssetStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const BUYING = "BUYING";
export const BOUGHT = "BOUGHT";

export default {
BUYING,
BOUGHT,
};
pcowgill marked this conversation as resolved.
Show resolved Hide resolved
21 changes: 19 additions & 2 deletions decentraland/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const showFatalError = msg => console.error(msg);
export const showError = msg => showToast(`ERROR: ${msg}`);
export const showWarn = msg => showToast(`WARN: ${msg}`);
export const showInfo = msg => showToast(`${msg}`);
export const logWarn = msg => console.warn(msg);

export const checkBlockchain = async () => {
loadConfig();
Expand Down Expand Up @@ -160,8 +161,14 @@ export const formatNumber = number => {
return formattedNumber;
};

export const removeFromList = (list, toRemove) =>
list.filter(e => e !== toRemove);
export const toListIfNot = itemOrList =>
Array.isArray(itemOrList) ? itemOrList : [itemOrList];

export const removeFromList = (list, toRemove) => {
const elementsToRemove = toListIfNot(toRemove);
const idsToRemove = elementsToRemove.map(e => e.id);
return list.filter(e => !idsToRemove.includes(e.id));
};

export const listsAreEqual = (first, second) => {
if (first.length !== second.length) return false;
Expand All @@ -171,6 +178,13 @@ export const listsAreEqual = (first, second) => {
);
};

// Update item from any list of objects having id as key field
export const updateListItem = (list, toUpdateId, entriesToUpdate) => {
return list.map(item => {
return item.id === toUpdateId ? { ...item, ...entriesToUpdate } : item;
});
};

const loadConfig = () => {
const tasitSdkConfig = require("../config/current.js");
ConfigLoader.setConfig(tasitSdkConfig);
Expand Down Expand Up @@ -244,6 +258,7 @@ export default {
showError,
showWarn,
showInfo,
logWarn,
fundAccountWithEthers,
fundAccountWithMana,
getContracts,
Expand All @@ -255,4 +270,6 @@ export default {
getNetworkName,
buildBlockchainUrlFromActionId,
restoreCreationStateOfAccountFromBlockchain,
updateListItem,
toListIfNot,
};
25 changes: 19 additions & 6 deletions decentraland/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ export const APPEND_LAND_FOR_SALE_TO_LIST = "APPEND_LAND_FOR_SALE_TO_LIST";
export const PREPEND_LAND_FOR_SALE_TO_LIST = "PREPEND_LAND_FOR_SALE_TO_LIST";
export const SET_LOADING_ASSETS_FOR_SALE_IN_PROGRESS =
"SET_LOADING_ASSETS_FOR_SALE_IN_PROGRESS";
export const ADD_TO_MY_ASSETS_LIST = "ADD_TO_MY_ASSETS_LIST";
export const REMOVE_MY_ASSET_FROM_LIST = "REMOVE_MY_ASSET_FROM_LIST";
export const PREPEND_TO_MY_ASSETS_LIST = "PREPEND_TO_MY_ASSETS_LIST";
export const APPEND_TO_MY_ASSETS_LIST = "APPEND_TO_MY_ASSETS_LIST";
export const REMOVE_FROM_MY_ASSETS_LIST = "REMOVE_FROM_MY_ASSETS_LIST";
export const SET_MY_ASSETS_LIST = "SET_MY_ASSETS_LIST";
export const SET_ACTION_ID_FOR_MY_ASSET = "SET_ACTION_ID_FOR_MY_ASSET";
export const UPDATE_MY_ASSET_STATUS = "UPDATE_MY_ASSET_STATUS";

export function setAccount(account) {
return { type: SET_ACCOUNT, account };
Expand Down Expand Up @@ -53,12 +55,16 @@ export function removeLandForSale(landForSale) {
return { type: REMOVE_LAND_FOR_SALE, landForSale };
}

export function addToMyAssetsList(myAsset) {
return { type: ADD_TO_MY_ASSETS_LIST, myAsset };
export function prependToMyAssetsList(myAsset) {
return { type: PREPEND_TO_MY_ASSETS_LIST, myAsset };
}

export function removeMyAssetFromList(myAsset) {
return { type: REMOVE_MY_ASSET_FROM_LIST, myAsset };
export function appendToMyAssetsList(itemOrList) {
return { type: APPEND_TO_MY_ASSETS_LIST, itemOrList };
}

export function removeFromMyAssetsList(itemOrList) {
return { type: REMOVE_FROM_MY_ASSETS_LIST, itemOrList };
}

export function setMyAssetsList(myAssets) {
Expand All @@ -71,3 +77,10 @@ export function setActionIdForMyAsset(myAssetId, actionId) {
myAssetAndActionIds: { myAssetId, actionId },
};
}

export function updateMyAssetStatus(myAssetId, status) {
return {
type: UPDATE_MY_ASSET_STATUS,
myAssetAndStatus: { myAssetId, status },
};
}
18 changes: 14 additions & 4 deletions decentraland/redux/middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import {
SET_ACCOUNT_CREATION_STATUS,
UPDATE_ACTION_FOR_ACCOUNT_CREATION_STATUS,
SET_ACCOUNT_CREATION_ACTIONS,
ADD_TO_MY_ASSETS_LIST,
REMOVE_MY_ASSET_FROM_LIST,
PREPEND_TO_MY_ASSETS_LIST,
APPEND_TO_MY_ASSETS_LIST,
REMOVE_FROM_MY_ASSETS_LIST,
SET_MY_ASSETS_LIST,
SET_ACTION_ID_FOR_MY_ASSET,
UPDATE_MY_ASSET_STATUS,
} from "./actions";
import {
storeAccount,
Expand Down Expand Up @@ -41,11 +43,15 @@ const storer = store => next => async action => {
await storeAccountCreationActions(creationActions);
break;
}
case ADD_TO_MY_ASSETS_LIST: {
case PREPEND_TO_MY_ASSETS_LIST: {
await storeMyAssets(myAssetsList);
break;
}
case REMOVE_MY_ASSET_FROM_LIST: {
case APPEND_TO_MY_ASSETS_LIST: {
await storeMyAssets(myAssetsList);
break;
}
case REMOVE_FROM_MY_ASSETS_LIST: {
await storeMyAssets(myAssetsList);
break;
}
Expand All @@ -57,6 +63,10 @@ const storer = store => next => async action => {
await storeMyAssets(myAssetsList);
break;
}
case UPDATE_MY_ASSET_STATUS: {
await storeMyAssets(myAssetsList);
break;
}
}

return result;
Expand Down
Loading