Skip to content

Commit

Permalink
Merge pull request #2517 from RabbyHub/fix-first-load-dev
Browse files Browse the repository at this point in the history
fix: async init store to fix dev load bug
  • Loading branch information
jinming0618 authored Sep 19, 2024
2 parents 056a2a1 + 5b514d0 commit 2cbdd30
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions src/background/service/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ export * from '@rabby-wallet/rabby-api/dist/types';
import { WebSignApiPlugin } from '@rabby-wallet/rabby-api/dist/plugins/web-sign';
import fetchAdapter from '@vespaiach/axios-fetch-adapter';

const testnetStore = new (class TestnetStore {
store!: { host: string; testnetHost: string };
class baseStore {
store: { host: string; testnetHost: string };

constructor() {
this.store = {
host: INITIAL_OPENAPI_URL,
testnetHost: INITIAL_TESTNET_OPENAPI_URL,
};
createPersistStore({
name: 'openapi',
template: {
Expand All @@ -19,6 +23,12 @@ const testnetStore = new (class TestnetStore {
this.store = res;
});
}
}

const testnetStore = new (class TestnetStore extends baseStore {
constructor() {
super();
}
get host() {
return this.store.testnetHost;
}
Expand All @@ -27,6 +37,25 @@ const testnetStore = new (class TestnetStore {
}
})();

const proxyStore = new (class ProxyStore extends baseStore {
constructor() {
super();
}

get host() {
return this.store.host;
}
set host(value) {
this.store.host = value;
}
get testnetHost() {
return this.store.testnetHost;
}
set testnetHost(value) {
this.store.testnetHost = value;
}
})();

const service = new OpenApiService({
plugin: WebSignApiPlugin,
adapter: fetchAdapter,
Expand All @@ -35,13 +64,7 @@ const service = new OpenApiService({
host: INITIAL_OPENAPI_URL,
testnetHost: INITIAL_TESTNET_OPENAPI_URL,
}
: createPersistStore({
name: 'openapi',
template: {
host: INITIAL_OPENAPI_URL,
testnetHost: INITIAL_TESTNET_OPENAPI_URL,
},
}),
: proxyStore,
});

export const testnetOpenapiService = new OpenApiService({
Expand Down

0 comments on commit 2cbdd30

Please sign in to comment.