mirror of
https://github.com/ecency/ecency-mobile.git
synced 2025-01-05 04:28:03 +03:00
remove default beneficiary account while saving beneficiaries and draft and add it back when loading draft
This commit is contained in:
parent
0559e102bb
commit
8edb0a745d
@ -827,4 +827,4 @@ SPEC CHECKSUMS:
|
|||||||
|
|
||||||
PODFILE CHECKSUM: 0282022703ad578ab2d9afbf3147ba3b373b4311
|
PODFILE CHECKSUM: 0282022703ad578ab2d9afbf3147ba3b373b4311
|
||||||
|
|
||||||
COCOAPODS: 1.11.3
|
COCOAPODS: 1.11.2
|
||||||
|
@ -44,6 +44,7 @@ const BeneficiarySelectionContent = ({
|
|||||||
|
|
||||||
const beneficiariesMap = useAppSelector((state) => state.editor.beneficiariesMap);
|
const beneficiariesMap = useAppSelector((state) => state.editor.beneficiariesMap);
|
||||||
const username = useAppSelector((state) => state.account.currentAccount.name);
|
const username = useAppSelector((state) => state.account.currentAccount.name);
|
||||||
|
const DEFAULT_BENEFICIARY = { account: username, weight: 10000 };
|
||||||
|
|
||||||
const [beneficiaries, setBeneficiaries] = useState<Beneficiary[]>([
|
const [beneficiaries, setBeneficiaries] = useState<Beneficiary[]>([
|
||||||
{ account: username, weight: 10000, autoPowerUp: false },
|
{ account: username, weight: 10000, autoPowerUp: false },
|
||||||
@ -94,8 +95,9 @@ const BeneficiarySelectionContent = ({
|
|||||||
|
|
||||||
const readTempBeneficiaries = async () => {
|
const readTempBeneficiaries = async () => {
|
||||||
if (beneficiariesMap) {
|
if (beneficiariesMap) {
|
||||||
const tempBeneficiaries = beneficiariesMap[draftId || TEMP_BENEFICIARIES_ID];
|
const savedBeneficiareis = beneficiariesMap[draftId || TEMP_BENEFICIARIES_ID];
|
||||||
|
const tempBeneficiaries = savedBeneficiareis && savedBeneficiareis.length ? [DEFAULT_BENEFICIARY, ...beneficiariesMap[draftId || TEMP_BENEFICIARIES_ID]] : [DEFAULT_BENEFICIARY];
|
||||||
|
|
||||||
if (isArray(tempBeneficiaries) && tempBeneficiaries.length > 0) {
|
if (isArray(tempBeneficiaries) && tempBeneficiaries.length > 0) {
|
||||||
//weight correction algorithm.
|
//weight correction algorithm.
|
||||||
let othersWeight = 0;
|
let othersWeight = 0;
|
||||||
@ -105,17 +107,17 @@ const BeneficiarySelectionContent = ({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
tempBeneficiaries[0].weight = 10000 - othersWeight;
|
tempBeneficiaries[0].weight = 10000 - othersWeight;
|
||||||
|
|
||||||
setBeneficiaries(tempBeneficiaries);
|
setBeneficiaries(tempBeneficiaries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const _saveBeneficiaries = (value: Beneficiary[]) => {
|
const _saveBeneficiaries = (value: Beneficiary[]) => {
|
||||||
|
const filteredBeneficiaries = value.filter((item) => item.account !== username); //remove default beneficiary from array while saving
|
||||||
if (handleSaveBeneficiary) {
|
if (handleSaveBeneficiary) {
|
||||||
handleSaveBeneficiary(value);
|
handleSaveBeneficiary(filteredBeneficiaries);
|
||||||
} else {
|
} else {
|
||||||
dispatch(setBeneficiariesAction(draftId || TEMP_BENEFICIARIES_ID, value));
|
dispatch(setBeneficiariesAction(draftId || TEMP_BENEFICIARIES_ID, filteredBeneficiaries));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -359,6 +361,7 @@ const BeneficiarySelectionContent = ({
|
|||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
console.log('draftId : ',draftId );
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
|
@ -5,6 +5,7 @@ import { Alert } from 'react-native';
|
|||||||
import ImagePicker from 'react-native-image-crop-picker';
|
import ImagePicker from 'react-native-image-crop-picker';
|
||||||
import get from 'lodash/get';
|
import get from 'lodash/get';
|
||||||
import AsyncStorage from '@react-native-community/async-storage';
|
import AsyncStorage from '@react-native-community/async-storage';
|
||||||
|
import { isArray } from 'lodash';
|
||||||
|
|
||||||
// Services and Actions
|
// Services and Actions
|
||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer';
|
||||||
@ -254,7 +255,7 @@ class EditorContainer extends Component<any, any> {
|
|||||||
|
|
||||||
// load meta from local/param drfat into state
|
// load meta from local/param drfat into state
|
||||||
_loadMeta = (draft: any) => {
|
_loadMeta = (draft: any) => {
|
||||||
const { dispatch } = this.props;
|
const { dispatch, currentAccount } = this.props;
|
||||||
// if meta exist on draft, get the index of 1st image in meta from images urls in body
|
// if meta exist on draft, get the index of 1st image in meta from images urls in body
|
||||||
const body = draft.body;
|
const body = draft.body;
|
||||||
if (draft.meta && draft.meta.image) {
|
if (draft.meta && draft.meta.image) {
|
||||||
@ -279,7 +280,10 @@ class EditorContainer extends Component<any, any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (draft._id && draft.meta && draft.meta.beneficiaries) {
|
if (draft._id && draft.meta && draft.meta.beneficiaries) {
|
||||||
dispatch(setBeneficiaries(draft._id || TEMP_BENEFICIARIES_ID, draft.meta.beneficiaries));
|
if(isArray(draft.meta.beneficiaries)){
|
||||||
|
const filteredBeneficiaries = draft.meta.beneficiaries.filter((item) => item.account !== currentAccount.username); //remove default beneficiary from array while saving
|
||||||
|
dispatch(setBeneficiaries(draft._id || TEMP_BENEFICIARIES_ID, filteredBeneficiaries));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_requestKeyboardFocus = () => {
|
_requestKeyboardFocus = () => {
|
||||||
@ -625,8 +629,8 @@ class EditorContainer extends Component<any, any> {
|
|||||||
draftId: response._id,
|
draftId: response._id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
const filteredBeneficiaries = beneficiaries.filter((item) => item.account !== currentAccount.username); //remove default beneficiary from array while saving
|
||||||
dispatch(setBeneficiaries(response._id, beneficiaries));
|
dispatch(setBeneficiaries(response._id, filteredBeneficiaries));
|
||||||
dispatch(removeBeneficiaries(TEMP_BENEFICIARIES_ID));
|
dispatch(removeBeneficiaries(TEMP_BENEFICIARIES_ID));
|
||||||
|
|
||||||
//clear local copy if darft save is successful
|
//clear local copy if darft save is successful
|
||||||
|
Loading…
Reference in New Issue
Block a user