Skip to content
Permalink
Browse files

hotfix: gun hacks to get wallet recoery working

  • Loading branch information
sirpy committed Mar 25, 2020
1 parent 87b98c7 commit dda90ffcef54a41e1f9bc5d99f8446aedc07b300
Showing with 13 additions and 5 deletions.
  1. +13 −5 src/lib/gundb/UserStorageClass.js
@@ -23,6 +23,8 @@ import isMobilePhone from '../validators/isMobilePhone'
import resizeBase64Image from '../utils/resizeBase64Image'
import { GD_GUN_CREDENTIALS } from '../constants/localStorage'
import delUndefValNested from '../utils/delUndefValNested'
import { delay } from '../utils/async'

import defaultGun from './gundb'
import UserProperties from './UserPropertiesClass'
import { getUserModel, type UserModel } from './UserModel'
@@ -433,6 +435,10 @@ export class UserStorage {
let gunuser = gun.user()
let mnemonic = ''

//hack to get gun working. these seems to preload data gun needs to login
//otherwise it get stuck on a clean incognito
await Promise.race([gun.get('~@' + username).then(), delay(1000)])
await delay(1000)
const authUserInGun = (username, password) => {
return new Promise((res, rej) => {
gunuser.auth(username, password, user => {
@@ -530,19 +536,21 @@ export class UserStorage {
this.gunuser.leave()
}

// this causes gun create user only on non-incognito to hang if user doesnt exists i have no freaking idea why
//const existingUsername = await this.gun.get('~@' + username)
const existingUsername = false
let loggedInPromise

logger.debug('init existing username:', { existingUsername })

let existingCreds = JSON.parse(await AsyncStorage.getItem(GD_GUN_CREDENTIALS))

if (existingCreds == null) {
//sign with different address so its not connected to main user address and there's no 1-1 link
const username = await this.wallet.sign('GoodDollarUser', 'gundb').then(r => r.slice(0, 20))
const password = await this.wallet.sign('GoodDollarPass', 'gundb').then(r => r.slice(0, 20))

//hack to get gun working. these seems to preload data gun needs to login
//otherwise it get stuck on a clean incognito, either when checking existingusername (if doesnt exists)
//or in gun auth
const existingUsername = await Promise.race([this.gun.get('~@' + username), delay(1000)])
await delay(1000)
logger.debug('init existing username:', { existingUsername })
if (existingUsername) {
loggedInPromise = this.gunAuth(username, password).catch(e =>
this.gunCreate(username, password).then(r => this.gunAuth(username, password))

0 comments on commit dda90ff

Please sign in to comment.
You can’t perform that action at this time.