Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
fix: make sure profile link, when just opening space
Browse files Browse the repository at this point in the history
  • Loading branch information
zachferland authored and oed committed May 21, 2019
1 parent 0e957e2 commit a5cffca
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/3box.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const idUtils = require('./utils/id')
const config = require('./config.js')
const API = require('./api')

const ACCOUNT_TYPES = {
ethereum: 'ethereum'
}
const ADDRESS_SERVER_URL = config.address_server_url
const PINNING_NODE = config.pinning_node
const PINNING_ROOM = config.pinning_room
Expand Down Expand Up @@ -368,6 +371,7 @@ class Box {
try {
opts = Object.assign({ numEntriesMessages: this.spacesPubSubMessages }, opts)
await this.spaces[name].open(opts)
if (!this.isAccountLinked()) this.linkAccount()
} catch (e) {
delete this.spaces[name]
if (e.message.includes('User denied message signature.')) {
Expand Down Expand Up @@ -410,6 +414,28 @@ class Box {
return true
}

/**
* Creates a proof that links an external account to the 3Box account of the user.
*
* @param {String} type The type of link (default 'ethereum')
*/
async linkAccount (type = ACCOUNT_TYPES.ethereum) {
if (type === ACCOUNT_TYPES.ethereum) {
await this._linkProfile()
}
}

/**
* Checks if there is a proof that links an external account to the 3Box account of the user.
*
* @param {String} type The type of link (default ethereum)
*/
async isAccountLinked (type = ACCOUNT_TYPES.ethereum) {
if (type === ACCOUNT_TYPES.ethereum) {
return Boolean(await this.public.get('ethereum_proof'))
}
}

async _linkProfile () {
let linkData = await this.public.get('ethereum_proof')

Expand Down

0 comments on commit a5cffca

Please sign in to comment.