Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
Avatar on json restore
Browse files Browse the repository at this point in the history
  • Loading branch information
xardass committed Nov 27, 2018
1 parent e003221 commit b34f645
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/displays/display-backup.html
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
const filename = 'SwarmCity - UTC KeyStore';
storage.keyStore.avatar = storage.user.avatar;
storage.keyStore.username = storage.user.username;
storage.keyStore.avatarHash = storage.user.avatarHash;
const text = JSON.stringify(storage.keyStore);
const element = document.createElement('a');
element.setAttribute('href', 'data:application/json;charset=utf-8,'
Expand Down
47 changes: 30 additions & 17 deletions src/displays/display-restore-json-file.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@
<div>{{filename}}</div>
<div class="cancel" on-click="_cancel"></div>
</div>
<paper-input id="password" label="{{localize('password?')}}" type="password" value="{{password}}" on-keydown="_checkForEnter"></paper-input>
<paper-input id="password" label="{{localize('password?')}}" type="password" value="{{password}}"
on-keydown="_checkForEnter"></paper-input>
<div class="error">{{error}}</div>
<div class="btn">
<div class="confirm" on-click="_decrypt"></div>
Expand Down Expand Up @@ -346,7 +347,7 @@
*/
_decrypt() {
if (this.wallet.Crypto) {
// check password before dooing any of this
// check password before doing any of this
this.$.wallet.decryptUtcKeystore(this.wallet, this.password)
.then(() => {
let storage = JSON.parse(localStorage.getItem('SwarmCity'));
Expand All @@ -356,20 +357,32 @@
} else {
storage.user.avatar = this.wallet.avatar;
}
storage.user.username = this.wallet.username;
delete storage.keyStore.username;
delete storage.keyStore.avatar;
localStorage.setItem('SwarmCity', JSON.stringify(storage));
this.dispatch({ type: 'PUBLICKEY', publicKey: storage.keyStore.address });
this.dispatch({ type: 'USERNAME', username: storage.user.username });

if (sessionStorage.getItem('origin')) {
this.path = sessionStorage.getItem('origin');
sessionStorage.removeItem('origin');
}
else {
this.set('route.path', 'hashtag-list');
}
const ipfs = window.ipfs
ipfs.add(storage.user.avatar)
.then(hash => {
storage.user.avatarHash = hash.hash;
storage.user.username = this.wallet.username;
delete storage.keyStore.username;
delete storage.keyStore.avatar;
delete storage.keyStore.avatarHash;
localStorage.setItem('SwarmCity', JSON.stringify(storage));
this.dispatch({ type: 'UPDATE_AVATARHASH', avatarHash: storage.user.avatarHash });
this.dispatch({ type: 'PUBLICKEY', publicKey: storage.keyStore.address });
this.dispatch({ type: 'USERNAME', username: storage.user.username });

if (sessionStorage.getItem('origin')) {
this.path = sessionStorage.getItem('origin');
sessionStorage.removeItem('origin');
}
else {
this.set('route.path', 'hashtag-list');
}


})
.catch(err => {
console.error('error resolving ipfs hash for avatar', err)
})
})
.catch(() => {
this.error = 'wrong password';
Expand All @@ -387,7 +400,7 @@
storage.user.username = this.wallet.identity.username;
localStorage.setItem('SwarmCity', JSON.stringify(storage));
if (this.wallet.identity.avatarhash) {
this.dispatch({ type: 'REQIPFS', reqipfs: this.wallet.identity.avatarhash });
this.dispatch({ type: 'UPDATE_AVATARHASH', avatarHash: this.wallet.identity.avatarhash });
}
this.dispatch({ type: 'PUBLICKEY', publicKey: storage.keyStore.address });
this.dispatch({ type: 'USERNAME', username: storage.user.username });
Expand Down

0 comments on commit b34f645

Please sign in to comment.