Fix info fetches overwritting active robot

This commit is contained in:
Reckless_Satoshi 2022-10-25 10:40:33 -07:00
parent f21a15b2bd
commit 7c901da04d
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
3 changed files with 20 additions and 27 deletions

View File

@ -508,7 +508,6 @@ class BottomBar extends Component {
<IconButton <IconButton
disabled={!this.showProfileButton()} disabled={!this.showProfileButton()}
color='primary' color='primary'
onClick={() => this.props.fetchInfo()}
to={`/`} to={`/`}
component={LinkRouter} component={LinkRouter}
> >
@ -552,6 +551,7 @@ class BottomBar extends Component {
<IconButton <IconButton
color='primary' color='primary'
aria-label='Stats for Nerds' aria-label='Stats for Nerds'
onClick={() => this.props.fetchInfo()}
onClick={this.handleClickOpenStatsForNerds} onClick={this.handleClickOpenStatsForNerds}
> >
<BarChartIcon /> <BarChartIcon />

View File

@ -112,7 +112,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
coordinatorVersion: versionInfo.coordinatorVersion, coordinatorVersion: versionInfo.coordinatorVersion,
clientVersion: versionInfo.clientVersion, clientVersion: versionInfo.clientVersion,
}); });
if (!robot.nickname) { if (!robot.nickname && data.nickname) {
setRobot({ setRobot({
...robot, ...robot,
nickname: data.nickname, nickname: data.nickname,

View File

@ -44,14 +44,9 @@ class UserGenPage extends Component {
componentDidMount() { componentDidMount() {
// Checks in parent HomePage if there is already a nick and token // Checks in parent HomePage if there is already a nick and token
// Displays the existing one // Displays the existing one
if (this.props.robot.nickname != null) { if (this.props.robot.token) {
this.setState({ this.setState({ inputToken: this.props.robot.token });
inputToken: this.props.robot.token ? this.props.robot.token : '', this.getGeneratedUser(this.props.robot.token);
});
} else if (window.NativeRobosats && systemClient.getCookie('robot_token')) {
const token = systemClient.getCookie('robot_token');
this.setState({ inputToken: token });
this.getGeneratedUser(token);
} else { } else {
const newToken = genBase62Token(36); const newToken = genBase62Token(36);
this.setState({ this.setState({
@ -79,21 +74,23 @@ class UserGenPage extends Component {
}); });
requestBody.then((body) => requestBody.then((body) =>
apiClient.post('/api/user/', body).then((data) => { apiClient.post('/api/user/', body).then((data) => {
this.setState({ found: data.found, bad_request: data.bad_request });
// Add nick and token to App state (token only if not a bad request) // Add nick and token to App state (token only if not a bad request)
data.bad_request data.bad_request
? this.props.setRobot({ ? this.props.setRobot({
...this.props.robot, ...this.props.robot,
nickname: data.nickname, avatarLoaded: true,
activeOrderId: data.active_order_id ? data.active_order_id : null, nickname: data.nickname ?? this.props.robot.nickname,
referralCode: data.referral_code, activeOrderId: data.active_order_id ?? null,
earnedRewards: data.earned_rewards ?? 0, referralCode: data.referral_code ?? this.props.referralCode,
lastOrderId: data.last_order_id ? data.last_order_id : null, earnedRewards: data.earned_rewards ?? this.props.eartnedRewards,
stealthInvoices: data.wants_stealth, lastOrderId: data.last_order_id ?? this.props.lastOrderId,
stealthInvoices: data.wants_stealth ?? this.props.stealthInvoices,
}) })
: this.props.setRobot({ : this.props.setRobot({
...this.props.robot, ...this.props.robot,
nickname: data.nickname, nickname: data.nickname,
token, token: token,
activeOrderId: data.active_order_id ? data.active_order_id : null, activeOrderId: data.active_order_id ? data.active_order_id : null,
lastOrderId: data.last_order_id ? data.last_order_id : null, lastOrderId: data.last_order_id ? data.last_order_id : null,
referralCode: data.referral_code, referralCode: data.referral_code,
@ -107,14 +104,10 @@ class UserGenPage extends Component {
pub_key: data.public_key, pub_key: data.public_key,
enc_priv_key: data.encrypted_private_key, enc_priv_key: data.encrypted_private_key,
copiedToken: data.found ? true : this.props.robot.copiedToken, copiedToken: data.found ? true : this.props.robot.copiedToken,
}) & });
systemClient.setCookie('robot_token', token) & systemClient.setCookie('robot_token', token);
systemClient.setCookie('pub_key', data.public_key.split('\n').join('\\')) & systemClient.setCookie('pub_key', data.public_key.split('\n').join('\\'));
systemClient.setCookie( systemClient.setCookie('enc_priv_key', data.encrypted_private_key.split('\n').join('\\'));
'enc_priv_key',
data.encrypted_private_key.split('\n').join('\\'),
);
data.found ? this.setState({ found: true }) : null;
}), }),
); );
}; };
@ -299,7 +292,7 @@ class UserGenPage extends Component {
color='primary' color='primary'
disabled={ disabled={
!this.props.robot.avatarLoaded || !this.props.robot.avatarLoaded ||
!(systemClient.getCookie('robot_token') === this.state.inputToken) !(systemClient.getCookie('robot_token') == this.state.inputToken)
} }
onClick={() => onClick={() =>
saveAsJson( saveAsJson(
@ -399,7 +392,7 @@ class UserGenPage extends Component {
disabled={ disabled={
this.props.robot.loading || this.props.robot.loading ||
!(this.props.robot.token !(this.props.robot.token
? systemClient.getCookie('robot_token') === this.props.robot.token ? systemClient.getCookie('robot_token') == this.props.robot.token
: true) : true)
} }
color='secondary' color='secondary'