@@ -14,7 +14,7 @@ import _platform from '../../../native-base-theme/variables/platform';
1414import styles from './styles'
1515import { login as _login , registerAccount as _registerAccount } from '../../reducers/account'
1616import { setLoading as _setLoading , showToast as _showToast } from '../../reducers/ui'
17- import { getErrorMsg } from '../../helpers/functions'
17+ import { getErrorMsg , exchangeCoinbaseCodeForCredentials } from '../../helpers/functions'
1818
1919const customStyles = {
2020 header : {
@@ -155,9 +155,33 @@ class SignUp extends Component {
155155 } )
156156 }
157157
158+ async useCoinbaseAuth ( indicateLoading , loginFn , oauth , oauthProvider , code ) {
159+ const {
160+ access_token : accessToken ,
161+ refresh_token : refreshToken ,
162+ email
163+ } = await exchangeCoinbaseCodeForCredentials ( code )
164+ indicateLoading ( true , 'Connecting To Coinbase' )
165+ const success = await loginFn (
166+ { email, oauth, oauthProvider } ,
167+ { failureRedirect : false , suppressToast : true }
168+ )
169+ indicateLoading ( false )
170+ if ( success ) {
171+ console . log ( 'logged in with Coinbase' )
172+ return
173+ }
174+ this . setState ( {
175+ showForm : true ,
176+ email,
177+ accessToken,
178+ refreshToken
179+ } )
180+ }
181+
158182 submit = async ( ) => {
159183 const { registerAccount, navigate, navigation, login, showToast } = this . props
160- const { withGoogle } = navigation . state . params
184+ const { oauth , oauthProvider } = navigation . state . params
161185 const {
162186 username,
163187 email,
@@ -173,10 +197,10 @@ class SignUp extends Component {
173197 } else if ( ! email ) {
174198 Alert . alert ( 'Email is required' )
175199 return
176- } else if ( ! withGoogle && ! password ) {
200+ } else if ( ! oauth && ! password ) {
177201 Alert . alert ( 'Password is required' )
178202 return
179- } else if ( ! withGoogle && password . length < 6 ) {
203+ } else if ( ! oauth && password . length < 6 ) {
180204 Alert . alert ( 'Password must be 6 char min' )
181205 return
182206 }
@@ -188,19 +212,20 @@ class SignUp extends Component {
188212 accessToken,
189213 refreshToken,
190214 serverAuthCode,
191- withGoogle,
215+ oauth,
216+ oauth_provider : oauthProvider ,
192217 invite_code : inviteCode
193218 } )
194219 showToast ( 'Account Created' )
195220 } catch ( err ) {
196221 logger . error ( 'submit, registerAccount' , err )
197222 showToast ( getErrorMsg ( err ) )
198223 }
199- if ( withGoogle ) {
224+ if ( oauth ) {
200225 try {
201- await login ( { username, accessToken, withGoogle } )
226+ await login ( { email , username, accessToken, oauth , oauthProvider } )
202227 } catch ( err ) {
203- logger . error ( ' SignUp withGoogle' , err )
228+ logger . error ( ` SignUp with oauth provider: ${ oauthProvider } ` , err )
204229 showToast ( getErrorMsg ( err ) )
205230 }
206231 } else {
0 commit comments