1
1
import { U2fSigner } from 'components/U2F' ;
2
- import { DangerAlert } from 'f61ui/component/alerts' ;
3
- import { Button , PrimaryLabel } from 'f61ui/component/bootstrap' ;
2
+ import { PrimaryLabel } from 'f61ui/component/bootstrap' ;
4
3
import { Breadcrumb } from 'f61ui/component/breadcrumbtrail' ;
5
4
import { ClipboardButton } from 'f61ui/component/clipboardbutton' ;
6
5
import { CommandIcon , CommandLink } from 'f61ui/component/CommandButton' ;
@@ -10,7 +9,6 @@ import { MonospaceContent } from 'f61ui/component/monospacecontent';
10
9
import { OptionalContent } from 'f61ui/component/optionalcontent' ;
11
10
import { Result } from 'f61ui/component/result' ;
12
11
import { SecretReveal } from 'f61ui/component/secretreveal' ;
13
- import { defaultErrorHandler } from 'f61ui/errors' ;
14
12
import { relativeDateFormat , shouldAlwaysSucceed , unrecognizedValue } from 'f61ui/utils' ;
15
13
import {
16
14
AccountAddExternalU2FToken ,
@@ -48,78 +46,51 @@ import { ExternalTokenKind, SecretKind } from 'generated/domain_types';
48
46
import { AppDefaultLayout } from 'layout/appdefaultlayout' ;
49
47
import * as React from 'react' ;
50
48
import { folderRoute , importotptokenRoute } from 'routes' ;
51
- import { isU2FError , nativeSignResultToApiType , u2fErrorMsg , u2fSign } from 'u2ftypes' ;
52
49
53
50
interface SecretsFetcherProps {
54
51
wrappedAccount : WrappedAccount ;
55
52
fetched : ( secrets : ExposedSecret [ ] ) => void ;
56
53
}
57
54
58
55
interface SecretsFetcherState {
59
- authing : boolean ;
60
- authError ?: string ;
56
+ secrets ?: Result < ExposedSecret [ ] > ;
61
57
}
62
58
63
59
class SecretsFetcher extends React . Component < SecretsFetcherProps , SecretsFetcherState > {
64
- state : SecretsFetcherState = { authing : false } ;
65
-
66
- componentDidMount ( ) {
67
- // start fetching process automatically. in some rare cases the user might not
68
- // want this, but failed auth attempt timeouts are not dangerous and this reduces
69
- // extra clicks in the majority case
70
- shouldAlwaysSucceed ( this . startSigning ( ) ) ;
71
- }
60
+ state : SecretsFetcherState = { } ;
72
61
73
62
render ( ) {
74
- if ( this . state . authing ) {
75
- return (
76
- < div >
77
- < p > Please swipe your U2F token now ...</ p >
78
-
79
- < Loading />
80
- </ div >
81
- ) ;
63
+ if ( this . state . secrets ) {
64
+ const [ , loadingOrError ] = this . state . secrets . unwrap ( ) ;
65
+ return loadingOrError ;
82
66
}
83
67
84
- const authErrorNode = this . state . authError && (
85
- < DangerAlert > { this . state . authError } </ DangerAlert >
86
- ) ;
87
-
88
68
return (
89
- < div >
90
- < Button
91
- label = "Authenticate"
92
- click = { ( ) => {
93
- shouldAlwaysSucceed ( this . startSigning ( ) ) ;
94
- } }
95
- />
96
-
97
- { authErrorNode }
98
- </ div >
69
+ < U2fSigner
70
+ challenge = { this . props . wrappedAccount . ChallengeBundle }
71
+ signed = { ( signature ) => {
72
+ const secrets = new Result < ExposedSecret [ ] > ( ( x ) => {
73
+ this . setState ( { secrets : x } ) ;
74
+ } ) ;
75
+
76
+ this . setState ( { secrets } ) ;
77
+
78
+ const secretsProm = getSecrets ( this . props . wrappedAccount . Account . Id , signature ) ;
79
+
80
+ secrets . load ( ( ) => secretsProm ) ;
81
+
82
+ secretsProm . then (
83
+ ( secretsRaw ) => {
84
+ this . props . fetched ( secretsRaw ) ;
85
+ } ,
86
+ ( ) => {
87
+ // errors already handled in another handler
88
+ } ,
89
+ ) ;
90
+ } }
91
+ />
99
92
) ;
100
93
}
101
-
102
- private async startSigning ( ) {
103
- this . setState ( { authing : true , authError : undefined } ) ;
104
-
105
- try {
106
- const result = await u2fSign ( this . props . wrappedAccount . ChallengeBundle . SignRequest ) ;
107
-
108
- if ( isU2FError ( result ) ) {
109
- this . setState ( { authing : false , authError : u2fErrorMsg ( result ) } ) ;
110
- return ;
111
- }
112
-
113
- const secrets = await getSecrets ( this . props . wrappedAccount . Account . Id , {
114
- Challenge : this . props . wrappedAccount . ChallengeBundle . Challenge ,
115
- SignResult : nativeSignResultToApiType ( result ) ,
116
- } ) ;
117
-
118
- this . props . fetched ( secrets ) ;
119
- } catch ( e ) {
120
- defaultErrorHandler ( e ) ;
121
- }
122
- }
123
94
}
124
95
125
96
interface KeylistAccessorProps {
0 commit comments