@@ -3,7 +3,12 @@ import { symbolApi } from '../../shared';
3
3
import config from '../../../common/const' ;
4
4
import { generateLiveApiInstance } from '../../../../common/appId' ;
5
5
import { translate } from '../../../../common/i18n' ;
6
- import { get as getStorage , set as setStorage , getTokenList } from '../../../../common/utils/storageManager' ;
6
+ import {
7
+ get as getStorage ,
8
+ set as setStorage ,
9
+ getTokenList ,
10
+ removeAllTokens ,
11
+ } from '../../../../common/utils/storageManager' ;
7
12
8
13
let purchaseChoices = [ [ translate ( 'Click to select' ) , '' ] ] ;
9
14
@@ -136,21 +141,27 @@ export const dependentFieldMapping = {
136
141
137
142
export const getAvailableDurations = ( symbol , selectedContractType ) => {
138
143
const contractsForStore = JSON . parse ( getStorage ( 'contractsForStore' ) || '[]' ) ;
139
- const tokenList = getTokenList ( ) ;
144
+ let tokenList = getTokenList ( ) ;
140
145
const defaultDurations = [
141
146
[ translate ( 'Ticks' ) , 't' ] ,
142
147
[ translate ( 'Seconds' ) , 's' ] ,
143
148
[ translate ( 'Minutes' ) , 'm' ] ,
144
149
[ translate ( 'Hours' ) , 'h' ] ,
145
150
[ translate ( 'Days' ) , 'd' ] ,
146
151
] ;
152
+
147
153
const getContractsForSymbolFromApi = async underlyingSymbol => {
148
154
// Refactor this when reducing WS connections
149
- let api = generateLiveApiInstance ( ) ;
155
+ const api = generateLiveApiInstance ( ) ;
150
156
151
157
// Try to authorize for accurate contracts response
152
158
if ( tokenList . length ) {
153
- await api . authorize ( tokenList [ 0 ] . token ) ;
159
+ try {
160
+ await api . authorize ( tokenList [ 0 ] . token ) ;
161
+ } catch ( e ) {
162
+ removeAllTokens ( ) ;
163
+ tokenList = [ ] ;
164
+ }
154
165
}
155
166
156
167
const response = await api . getContractsForSymbol ( underlyingSymbol ) ;
@@ -176,7 +187,6 @@ export const getAvailableDurations = (symbol, selectedContractType) => {
176
187
setStorage ( 'contractsForStore' , JSON . stringify ( contractsForStore ) ) ;
177
188
}
178
189
api . disconnect ( ) ;
179
- api = null ;
180
190
return contractsForSymbol ;
181
191
} ;
182
192
const getDurationsForContract = contractsForSymbol => {
0 commit comments