diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-12-08 03:29:37 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-12-08 03:29:37 +0800 |
commit | b74b4eb053e9e4210dbf507fed88361741ce1d63 (patch) | |
tree | 9c77457f7c82b4e3fffed3e18d54bbc7f8f39db7 /packages/instant/src/util/provider_state_factory.ts | |
parent | 57dc5b6fc086762d9cfedfc8adbfa55adf77fd73 (diff) | |
download | dexon-sol-tools-b74b4eb053e9e4210dbf507fed88361741ce1d63.tar dexon-sol-tools-b74b4eb053e9e4210dbf507fed88361741ce1d63.tar.gz dexon-sol-tools-b74b4eb053e9e4210dbf507fed88361741ce1d63.tar.bz2 dexon-sol-tools-b74b4eb053e9e4210dbf507fed88361741ce1d63.tar.lz dexon-sol-tools-b74b4eb053e9e4210dbf507fed88361741ce1d63.tar.xz dexon-sol-tools-b74b4eb053e9e4210dbf507fed88361741ce1d63.tar.zst dexon-sol-tools-b74b4eb053e9e4210dbf507fed88361741ce1d63.zip |
feat: refactor provider name and displayName logic
Diffstat (limited to 'packages/instant/src/util/provider_state_factory.ts')
-rw-r--r-- | packages/instant/src/util/provider_state_factory.ts | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/packages/instant/src/util/provider_state_factory.ts b/packages/instant/src/util/provider_state_factory.ts index 7c788dff2..bd2d6dad5 100644 --- a/packages/instant/src/util/provider_state_factory.ts +++ b/packages/instant/src/util/provider_state_factory.ts @@ -10,27 +10,40 @@ import { assetBuyerFactory } from './asset_buyer_factory'; import { providerFactory } from './provider_factory'; export const providerStateFactory = { - getInitialProviderState: (orderSource: OrderSource, network: Network, provider?: Provider): ProviderState => { + getInitialProviderState: ( + orderSource: OrderSource, + network: Network, + provider?: Provider, + walletDisplayName?: string, + ): ProviderState => { if (!_.isUndefined(provider)) { - return providerStateFactory.getInitialProviderStateFromProvider(orderSource, network, provider); + return providerStateFactory.getInitialProviderStateFromProvider( + orderSource, + network, + provider, + walletDisplayName, + ); } const providerStateFromWindowIfExits = providerStateFactory.getInitialProviderStateFromWindowIfExists( orderSource, network, + walletDisplayName, ); if (providerStateFromWindowIfExits) { return providerStateFromWindowIfExits; } else { - return providerStateFactory.getInitialProviderStateFallback(orderSource, network); + return providerStateFactory.getInitialProviderStateFallback(orderSource, network, walletDisplayName); } }, getInitialProviderStateFromProvider: ( orderSource: OrderSource, network: Network, provider: Provider, + walletDisplayName?: string, ): ProviderState => { const providerState: ProviderState = { name: envUtil.getProviderName(provider), + displayName: walletDisplayName || envUtil.getProviderDisplayName(provider), provider, web3Wrapper: new Web3Wrapper(provider), assetBuyer: assetBuyerFactory.getAssetBuyer(provider, orderSource, network), @@ -38,11 +51,16 @@ export const providerStateFactory = { }; return providerState; }, - getInitialProviderStateFromWindowIfExists: (orderSource: OrderSource, network: Network): Maybe<ProviderState> => { + getInitialProviderStateFromWindowIfExists: ( + orderSource: OrderSource, + network: Network, + walletDisplayName?: string, + ): Maybe<ProviderState> => { const injectedProviderIfExists = providerFactory.getInjectedProviderIfExists(); if (!_.isUndefined(injectedProviderIfExists)) { const providerState: ProviderState = { name: envUtil.getProviderName(injectedProviderIfExists), + displayName: walletDisplayName || envUtil.getProviderDisplayName(injectedProviderIfExists), provider: injectedProviderIfExists, web3Wrapper: new Web3Wrapper(injectedProviderIfExists), assetBuyer: assetBuyerFactory.getAssetBuyer(injectedProviderIfExists, orderSource, network), @@ -53,10 +71,15 @@ export const providerStateFactory = { return undefined; } }, - getInitialProviderStateFallback: (orderSource: OrderSource, network: Network): ProviderState => { + getInitialProviderStateFallback: ( + orderSource: OrderSource, + network: Network, + walletDisplayName?: string, + ): ProviderState => { const provider = providerFactory.getFallbackNoSigningProvider(network); const providerState: ProviderState = { name: 'Fallback', + displayName: walletDisplayName || envUtil.getProviderDisplayName(provider), provider, web3Wrapper: new Web3Wrapper(provider), assetBuyer: assetBuyerFactory.getAssetBuyer(provider, orderSource, network), |