Skip to content
Permalink
Browse files

fix(Auth): make sign async with callback for MetaMask

  • Loading branch information...
satello committed May 3, 2018
1 parent 5ad300b commit 9d0aa1424bc16cafdc75f351eb32fd6b0b65f8ce
Showing with 13 additions and 6 deletions.
  1. +3 −3 src/resources/Auth.js
  2. +1 −1 src/utils/StoreProviderWrapper.js
  3. +8 −1 src/utils/Web3Wrapper.js
  4. +1 −1 tests/integration/storeAuth.test.js
@@ -33,11 +33,11 @@ class Auth {
* @returns {string} Signed token for future use.
*/
validateNewAuthToken = async userAddress => {
const unsignedToken = await this._StoreProviderInstance.newAuthToken(
const unsignedToken = (await this._StoreProviderInstance.newAuthToken(
userAddress
)
)).unsignedToken

const signedToken = this.signMessage(userAddress, unsignedToken)
const signedToken = await this.signMessage(userAddress, unsignedToken)
this.setAuthToken(signedToken)
return signedToken
}
@@ -104,7 +104,7 @@ class StoreProviderWrapper {
newAuthToken = async userAddress => {
const newTokenResponse = await this._makeRequest(
'GET',
`${this._storeUri}/${userAddress}`
`${this._storeUri}/${userAddress}/authToken`
)

return newTokenResponse.body
@@ -32,7 +32,14 @@ class Web3Wrapper {

blockNumber = () => this._web3.eth.blockNumber

sign = (userAddress, data) => this._web3.eth.sign(userAddress, data)
sign = (userAddress, data) =>
new Promise((resolve, reject) => {
this._web3.eth.sign(userAddress, data, (error, result) => {
if (error) reject(error)

resolve(result)
})
})

getBlock = blockNumber =>
new Promise((resolve, reject) => {
@@ -34,7 +34,7 @@ describe('Auth', () => {
const mockToken =
'0x7b2276657273696f6e223a312c2265787069726174696f6e223a313532353830303831313932307d'
const mockStoreProvider = {
newAuthToken: () => mockToken,
newAuthToken: () => ({ unsignedToken: mockToken }),
setAuthToken: () => true
}
// set new store provider

0 comments on commit 9d0aa14

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