Skip to content

Commit

Permalink
prefer remote params, save params
Browse files Browse the repository at this point in the history
  • Loading branch information
turbocrime committed Jun 27, 2024
1 parent 9b43db5 commit 9a3e352
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions apps/extension/src/wallet-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,17 @@ export const startWalletServices = async () => {
* local storage.
*/
const getChainId = async (baseUrl: string) => {
const localParams = await localExtStorage
.get('params')
.then(jsonParams => (jsonParams ? AppParameters.fromJsonString(jsonParams) : undefined));
const params =
(await createPromiseClient(AppService, createGrpcWebTransport({ baseUrl })).appParameters({}))
.appParameters ??
(await localExtStorage
.get('params')
.then(jsonParams => (jsonParams ? AppParameters.fromJsonString(jsonParams) : undefined)));

let chainId = localParams?.chainId;
if (params?.chainId) void localExtStorage.set('params', params.toJsonString());
else throw new Error('No chainId available');

if (!localParams) {
try {
const remoteParams = (
await createPromiseClient(AppService, createGrpcWebTransport({ baseUrl })).appParameters({})
).appParameters;

chainId ??= remoteParams?.chainId;

if (remoteParams) void localExtStorage.set('params', remoteParams.toJsonString());
} catch (e) {
console.warn(e);
}
}

if (!chainId) throw new Error('No chainId available');

return chainId;
return params.chainId;
};

/**
Expand Down

0 comments on commit 9a3e352

Please sign in to comment.