@@ -32,7 +32,7 @@ export default async function createApiFacade({ web3, chainId }) {
32
32
createApiInstance ( {
33
33
web3,
34
34
archon,
35
- contracts : await getLinguoContracts ( { web3, chainId, address, deployment : Linguo } ) ,
35
+ contracts : await getContracts ( { web3, chainId, address, deployment : Linguo } ) ,
36
36
} )
37
37
) ,
38
38
addressesByLanguageGroupPair
@@ -168,22 +168,28 @@ export default async function createApiFacade({ web3, chainId }) {
168
168
...rest ,
169
169
] ;
170
170
171
- const actualApi = apiInstancesByAddress [ address ] ;
172
- if ( actualApi ) {
173
- return actualApi [ target . name ] . apply ( actualApi , actualArgs ) ;
171
+ const instance = apiInstancesByAddress [ address ] ;
172
+ if ( instance ) {
173
+ return instance [ target . name ] . apply ( instance , actualArgs ) ;
174
174
}
175
175
176
+ /**
177
+ * If a given task is from a contract that is no longer supported and therefore is
178
+ * not wired up when the façade is created, users are still allowed to read from it.
179
+ * To be able to do that, we need to create a new API instnace on the fly for the
180
+ * unsupported contract, but only for the read-only methods.
181
+ */
176
182
if ( ! Object . keys ( readOnlyApiSkeleton ) . includes ( target . name ) ) {
177
183
throw new Error ( `Task with ID ${ ID } is read-only.` ) ;
178
184
}
179
185
180
186
const transientInstance = await createApiInstance ( {
181
187
web3,
182
188
archon,
183
- contracts : await getLinguoContracts ( { web3, chainId, address, deployment : Linguo } ) ,
189
+ contracts : await getContracts ( { web3, chainId, address, deployment : Linguo } ) ,
184
190
} ) ;
185
191
186
- return transientInstance . api [ target . name ] . apply ( actualApi , actualArgs ) ;
192
+ return transientInstance . api [ target . name ] . apply ( instance , actualArgs ) ;
187
193
} ,
188
194
} ;
189
195
@@ -237,7 +243,7 @@ const readOnlyApiSkeleton = {
237
243
getArbitrationCost ( ) { } ,
238
244
} ;
239
245
240
- async function getLinguoContracts ( { web3, chainId, address, deployment } ) {
246
+ async function getContracts ( { web3, chainId, address, deployment } ) {
241
247
// set the max listeners warning threshold
242
248
web3 . eth . maxListenersWarningThreshold = 1000 ;
243
249
0 commit comments