steem connect ignore created

This commit is contained in:
ue 2018-12-09 17:41:20 +03:00
parent 5ba8daa592
commit 167ac710e4
2 changed files with 85 additions and 75 deletions

View File

@ -194,36 +194,47 @@ export const getIsMuted = async (username, targetUsername) => {
return false;
};
export const ignoreUser = (data, postingKey) => {
let key;
try {
key = PrivateKey.fromString(postingKey);
} catch (error) {}
export const ignoreUser = async (currentAccount, data) => {
const digitPinCode = await getDigitPinCode();
const json = {
id: 'follow',
json: JSON.stringify([
'follow',
{
follower: `${data.follower}`,
following: `${data.following}`,
what: ['ignore'],
},
]),
required_auths: [],
required_posting_auths: [`${data.follower}`],
};
if (currentAccount.local.authType === AUTH_TYPE.MASTER_KEY) {
const key = decryptKey(currentAccount.local.postingKey, digitPinCode);
const privateKey = PrivateKey.fromString(key);
return new Promise((resolve, reject) => {
client.broadcast
.json(json, key)
.then((result) => {
resolve(result);
})
.catch((err) => {
reject(err);
});
});
const json = {
id: 'follow',
json: JSON.stringify([
'follow',
{
follower: `${data.follower}`,
following: `${data.following}`,
what: ['ignore'],
},
]),
required_auths: [],
required_posting_auths: [`${data.follower}`],
};
return new Promise((resolve, reject) => {
client.broadcast
.json(json, privateKey)
.then((result) => {
resolve(result);
})
.catch((err) => {
reject(err);
});
});
}
if (currentAccount.local.authType === AUTH_TYPE.STEEM_CONNECT) {
const token = decryptKey(currentAccount.local.accessToken, digitPinCode);
const api = steemConnect.Initialize({
accessToken: token,
});
return api.ignore(data.follower, data.following);
}
};
/**
@ -396,35 +407,44 @@ export const transferToken = (data, activeKey) => {
});
};
export const followUser = (data, postingKey) => {
let key;
try {
key = PrivateKey.fromString(postingKey);
} catch (error) {}
const json = {
id: 'follow',
json: JSON.stringify([
'follow',
{
follower: `${data.follower}`,
following: `${data.following}`,
what: ['blog'],
},
]),
required_auths: [],
required_posting_auths: [`${data.follower}`],
};
export const followUser = async (currentAccount, data) => {
const digitPinCode = await getDigitPinCode();
if (currentAccount.local.authType === AUTH_TYPE.MASTER_KEY) {
const key = decryptKey(currentAccount.local.postingKey, digitPinCode);
const privateKey = PrivateKey.fromString(key);
const json = {
id: 'follow',
json: JSON.stringify([
'follow',
{
follower: `${data.follower}`,
following: `${data.following}`,
what: ['blog'],
},
]),
required_auths: [],
required_posting_auths: [`${data.follower}`],
};
return new Promise((resolve, reject) => {
client.broadcast
.json(json, key)
.then((result) => {
resolve(result);
})
.catch((err) => {
reject(err);
});
});
return new Promise((resolve, reject) => {
client.broadcast
.json(json, privateKey)
.then((result) => {
resolve(result);
})
.catch((err) => {
reject(err);
});
});
}
if (currentAccount.local.authType === AUTH_TYPE.STEEM_CONNECT) {
const token = decryptKey(currentAccount.local.accessToken, digitPinCode);
const api = steemConnect.Initialize({
accessToken: token,
});
return api.follow(data.follower, data.following);
}
};
export const unfollowUser = async (currentAccount, data) => {
@ -462,12 +482,10 @@ export const unfollowUser = async (currentAccount, data) => {
if (currentAccount.local.authType === AUTH_TYPE.STEEM_CONNECT) {
const token = decryptKey(currentAccount.local.accessToken, digitPinCode);
const api = steemConnect.Initialize({
accessToken: token
accessToken: token,
});
const follower = currentAccount.username;
return api.unfollow(follower, data.following);
return api.unfollow(data.follower, data.following);
}
};

View File

@ -83,16 +83,13 @@ class ProfileContainer extends Component {
_handleFollowUnfollowUser = async (isFollowAction) => {
const { username, isFollowing } = this.state;
const { currentAccount } = this.props;
const digitPinCode = await getDigitPinCode();
const privateKey = decryptKey(currentAccount.local.postingKey, digitPinCode);
this.setState({
isProfileLoading: true,
});
if (isFollowAction && !isFollowing) {
this._followUser(currentAccount.name, username, privateKey);
this._followUser(currentAccount, currentAccount.name, username);
} else {
this._unfollowUser(currentAccount, currentAccount.name, username);
}
@ -101,18 +98,13 @@ class ProfileContainer extends Component {
_handleMuteUnmuteUser = async (isMuteAction) => {
const { username, isMuted } = this.state;
const { currentAccount } = this.props;
const digitPinCode = await getDigitPinCode();
const privateKey = decryptKey(currentAccount.local.postingKey, digitPinCode);
this.setState({
isProfileLoading: true,
});
if (isMuteAction && !isMuted) {
this._muteUser(currentAccount.name, username, privateKey);
} else {
this._muteUser(currentAccount.name, username, privateKey);
if (isMuteAction) {
this._muteUser(currentAccount, currentAccount.name, username);
}
};
@ -132,13 +124,13 @@ class ProfileContainer extends Component {
});
};
_followUser = (follower, following, privateKey) => {
_followUser = (currentAccount, follower, following) => {
followUser(
currentAccount,
{
follower,
following,
},
privateKey,
)
.then(() => {
this._profileActionDone();
@ -148,13 +140,13 @@ class ProfileContainer extends Component {
});
};
_muteUser = async (follower, following, privateKey) => {
_muteUser = async (currentAccount, follower, following) => {
ignoreUser(
currentAccount,
{
follower,
following,
},
privateKey,
)
.then(() => {
this._profileActionDone();