mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-22 12:51:42 +03:00
fix permission and scheduling
This commit is contained in:
parent
2985e3aed1
commit
5cbe942c51
@ -1178,6 +1178,73 @@ export const boost = (currentAccount, pinCode, point, permlink, author) => {
|
|||||||
return Promise.reject(new Error('Private key permission issue!'));
|
return Promise.reject(new Error('Private key permission issue!'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const grantPostingPermission = async (params, pin, currentAccount) => {
|
||||||
|
const digitPinCode = getDigitPinCode(pin);
|
||||||
|
const key = getActiveKey(get(currentAccount, 'local'), digitPinCode);
|
||||||
|
|
||||||
|
const newPosting = Object.assign(
|
||||||
|
{},
|
||||||
|
{ ...get(currentAccount, 'posting') },
|
||||||
|
{
|
||||||
|
account_auths: [
|
||||||
|
...get(currentAccount, 'posting.account_auths'),
|
||||||
|
['esteemapp', get(currentAccount, 'posting.weight_threshold')],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (get(currentAccount, 'local.authType') === AUTH_TYPE.STEEM_CONNECT) {
|
||||||
|
const token = decryptKey(get(currentAccount, 'local.accessToken'), digitPinCode);
|
||||||
|
const api = new steemconnect.Client({
|
||||||
|
accessToken: token,
|
||||||
|
});
|
||||||
|
const _params = {
|
||||||
|
account: get(currentAccount, 'name'),
|
||||||
|
posting: newPosting,
|
||||||
|
memo_key: get(currentAccount, 'memo_key'),
|
||||||
|
json_metadata: jsonStringify(params),
|
||||||
|
};
|
||||||
|
|
||||||
|
const opArray = [['account_update', _params]];
|
||||||
|
|
||||||
|
return api
|
||||||
|
.broadcast(opArray)
|
||||||
|
.then(resp => resp.result)
|
||||||
|
.catch(error => console.log(error));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key) {
|
||||||
|
newPosting.account_auths.sort();
|
||||||
|
const opArray = [
|
||||||
|
[
|
||||||
|
'account_update',
|
||||||
|
{
|
||||||
|
account: get(currentAccount, 'name'),
|
||||||
|
memo_key: get(currentAccount, 'memo_key'),
|
||||||
|
json_metadata: jsonStringify(params),
|
||||||
|
posting: newPosting,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
];
|
||||||
|
const privateKey = PrivateKey.fromString(key);
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
client.broadcast
|
||||||
|
.sendOperations(opArray, privateKey)
|
||||||
|
.then(result => {
|
||||||
|
resolve(result);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
if (get(error, 'jse_info.code') === 4030100) {
|
||||||
|
error.message = getDsteemDateErrorMessage(error);
|
||||||
|
}
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.reject(new Error('Private key permission issue!'));
|
||||||
|
};
|
||||||
|
|
||||||
export const profileUpdate = async (params, pin, currentAccount) => {
|
export const profileUpdate = async (params, pin, currentAccount) => {
|
||||||
const digitPinCode = getDigitPinCode(pin);
|
const digitPinCode = getDigitPinCode(pin);
|
||||||
const key = getActiveKey(get(currentAccount, 'local'), digitPinCode);
|
const key = getActiveKey(get(currentAccount, 'local'), digitPinCode);
|
||||||
|
@ -10,7 +10,7 @@ import AsyncStorage from '@react-native-community/async-storage';
|
|||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer';
|
||||||
import { uploadImage, addDraft, updateDraft, schedule } from '../../../providers/esteem/esteem';
|
import { uploadImage, addDraft, updateDraft, schedule } from '../../../providers/esteem/esteem';
|
||||||
import { toastNotification } from '../../../redux/actions/uiAction';
|
import { toastNotification } from '../../../redux/actions/uiAction';
|
||||||
import { postContent, getPurePost } from '../../../providers/steem/dsteem';
|
import { postContent, getPurePost, grantPostingPermission } from '../../../providers/steem/dsteem';
|
||||||
import { setDraftPost, getDraftPost } from '../../../realm/realm';
|
import { setDraftPost, getDraftPost } from '../../../realm/realm';
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
@ -449,12 +449,38 @@ class EditorContainer extends Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_handleDatePickerChange = (datePickerValue, fields) => {
|
_handleDatePickerChange = async (datePickerValue, fields) => {
|
||||||
this._submitPost(fields, datePickerValue);
|
const { currentAccount, pinCode, intl } = this.props;
|
||||||
|
|
||||||
|
const params = get(currentAccount, 'json_metadata', '');
|
||||||
|
|
||||||
|
let hasPostingPerm = false;
|
||||||
|
|
||||||
|
if (currentAccount && currentAccount.posting) {
|
||||||
|
hasPostingPerm =
|
||||||
|
currentAccount.posting.account_auths.filter(x => x[0] === 'esteemapp').length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasPostingPerm) {
|
||||||
|
this._submitPost(fields, datePickerValue);
|
||||||
|
} else {
|
||||||
|
await grantPostingPermission(params, pinCode, currentAccount)
|
||||||
|
.then(() => {
|
||||||
|
this._submitPost(fields, datePickerValue);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
Alert.alert(
|
||||||
|
intl.formatMessage({
|
||||||
|
id: 'alert.fail',
|
||||||
|
}),
|
||||||
|
get(error, 'message', error.toString()),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_setScheduledPost = data => {
|
_setScheduledPost = data => {
|
||||||
const { dispatch, intl } = this.props;
|
const { dispatch, intl, currentAccount, navigation } = this.props;
|
||||||
|
|
||||||
schedule(
|
schedule(
|
||||||
data.author,
|
data.author,
|
||||||
@ -476,6 +502,13 @@ class EditorContainer extends Component {
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
setDraftPost({ title: '', body: '', tags: '' }, currentAccount.name);
|
||||||
|
setTimeout(() => {
|
||||||
|
navigation.navigate({
|
||||||
|
routeName: ROUTES.SCREENS.DRAFTS,
|
||||||
|
key: currentAccount.name,
|
||||||
|
});
|
||||||
|
}, 3000);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
this.setState({ isPostSending: false });
|
this.setState({ isPostSending: false });
|
||||||
|
Loading…
Reference in New Issue
Block a user