mirror of
https://github.com/ecency/ecency-mobile.git
synced 2025-01-03 03:25:24 +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
|
||||
|
||||
COCOAPODS: 1.11.3
|
||||
COCOAPODS: 1.11.2
|
||||
|
@ -44,6 +44,7 @@ const BeneficiarySelectionContent = ({
|
||||
|
||||
const beneficiariesMap = useAppSelector((state) => state.editor.beneficiariesMap);
|
||||
const username = useAppSelector((state) => state.account.currentAccount.name);
|
||||
const DEFAULT_BENEFICIARY = { account: username, weight: 10000 };
|
||||
|
||||
const [beneficiaries, setBeneficiaries] = useState<Beneficiary[]>([
|
||||
{ account: username, weight: 10000, autoPowerUp: false },
|
||||
@ -94,8 +95,9 @@ const BeneficiarySelectionContent = ({
|
||||
|
||||
const readTempBeneficiaries = async () => {
|
||||
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) {
|
||||
//weight correction algorithm.
|
||||
let othersWeight = 0;
|
||||
@ -105,17 +107,17 @@ const BeneficiarySelectionContent = ({
|
||||
}
|
||||
});
|
||||
tempBeneficiaries[0].weight = 10000 - othersWeight;
|
||||
|
||||
setBeneficiaries(tempBeneficiaries);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const _saveBeneficiaries = (value: Beneficiary[]) => {
|
||||
const filteredBeneficiaries = value.filter((item) => item.account !== username); //remove default beneficiary from array while saving
|
||||
if (handleSaveBeneficiary) {
|
||||
handleSaveBeneficiary(value);
|
||||
handleSaveBeneficiary(filteredBeneficiaries);
|
||||
} else {
|
||||
dispatch(setBeneficiariesAction(draftId || TEMP_BENEFICIARIES_ID, value));
|
||||
dispatch(setBeneficiariesAction(draftId || TEMP_BENEFICIARIES_ID, filteredBeneficiaries));
|
||||
}
|
||||
};
|
||||
|
||||
@ -359,6 +361,7 @@ const BeneficiarySelectionContent = ({
|
||||
</View>
|
||||
);
|
||||
};
|
||||
console.log('draftId : ',draftId );
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
|
@ -5,6 +5,7 @@ import { Alert } from 'react-native';
|
||||
import ImagePicker from 'react-native-image-crop-picker';
|
||||
import get from 'lodash/get';
|
||||
import AsyncStorage from '@react-native-community/async-storage';
|
||||
import { isArray } from 'lodash';
|
||||
|
||||
// Services and Actions
|
||||
import { Buffer } from 'buffer';
|
||||
@ -254,7 +255,7 @@ class EditorContainer extends Component<any, any> {
|
||||
|
||||
// load meta from local/param drfat into state
|
||||
_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
|
||||
const body = draft.body;
|
||||
if (draft.meta && draft.meta.image) {
|
||||
@ -279,7 +280,10 @@ class EditorContainer extends Component<any, any> {
|
||||
}
|
||||
|
||||
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 = () => {
|
||||
@ -625,8 +629,8 @@ class EditorContainer extends Component<any, any> {
|
||||
draftId: response._id,
|
||||
});
|
||||
}
|
||||
|
||||
dispatch(setBeneficiaries(response._id, beneficiaries));
|
||||
const filteredBeneficiaries = beneficiaries.filter((item) => item.account !== currentAccount.username); //remove default beneficiary from array while saving
|
||||
dispatch(setBeneficiaries(response._id, filteredBeneficiaries));
|
||||
dispatch(removeBeneficiaries(TEMP_BENEFICIARIES_ID));
|
||||
|
||||
//clear local copy if darft save is successful
|
||||
|
Loading…
Reference in New Issue
Block a user