-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30c9933
commit 6ced2d3
Showing
22 changed files
with
888 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2768,4 +2768,4 @@ msgstr "" | |
|
||
#: src/components/atomic-swap/ProposalBalanceTable.js:62 | ||
msgid "Receiving" | ||
msgstr "" | ||
msgstr "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (c) Hathor Labs and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { t } from 'ttag' | ||
|
||
import hathorLib from '@hathor/wallet-lib'; | ||
|
||
/** | ||
* Component that shows the current wallet name in use | ||
* | ||
* @memberof Components | ||
*/ | ||
function WalletStatus(props) { | ||
if (hathorLib.wallet.isHardwareWallet()) { | ||
return null; | ||
} | ||
const listOfWallets = hathorLib.storage.store.getListOfWallets(); | ||
const walletName = listOfWallets[hathorLib.storage.store.prefix].name; | ||
return ( | ||
<div className="d-flex flex-column version-wrapper align-items-center"> | ||
<span>{t`Current Wallet`}</span> | ||
<span>{walletName}</span> | ||
</div> | ||
); | ||
} | ||
|
||
export default WalletStatus; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright (c) Hathor Labs and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
export class WalletDoesNotExistError extends Error { | ||
constructor(prefix) { | ||
super(`Wallet does not exist: ${prefix}`); | ||
this.name = "WalletDoesNotExistError"; | ||
} | ||
}; | ||
|
||
export class WalletAlreadyExistError extends Error { | ||
constructor() { | ||
super('Prefix already in use'); | ||
this.name = "WalletAlreadyExistError"; | ||
} | ||
}; | ||
|
||
export class InvalidWalletNameError extends Error { | ||
constructor() { | ||
super('Invalid wallet name'); | ||
this.name = "InvalidWalletNameError"; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import events from 'events'; | ||
import { UnleashClient } from 'unleash-proxy-client'; | ||
import { | ||
UNLEASH_URL, | ||
UNLEASH_CLIENT_KEY, | ||
UNLEASH_POLLING_INTERVAL, | ||
} from './constants'; | ||
|
||
const IGNORE_WALLET_SERVICE_FLAG = 'featureFlags:ignoreWalletServiceFlag'; | ||
|
||
export class FeatureFlags extends events.EventEmitter { | ||
constructor(userId, network) { | ||
super(); | ||
|
||
this.userId = userId; | ||
this.network = network; | ||
this.walletServiceFlag = `wallet-service-wallet-desktop-${this.network}.rollout`; | ||
this.walletServiceEnabled = null; | ||
this.client = new UnleashClient({ | ||
url: UNLEASH_URL, | ||
clientKey: UNLEASH_CLIENT_KEY, | ||
refreshInterval: UNLEASH_POLLING_INTERVAL, | ||
appName: `wallet-service-wallet-desktop`, | ||
}); | ||
|
||
this.client.on('update', () => { | ||
// Get current flag | ||
const walletServiceEnabled = this.client.isEnabled(this.walletServiceFlag); | ||
|
||
// We should only emit an update if we already had a value on the instance | ||
// and if the value has changed | ||
if (this.walletServiceEnabled !== null && ( | ||
this.walletServiceEnabled !== walletServiceEnabled | ||
)) { | ||
this.walletServiceEnabled = walletServiceEnabled; | ||
this.emit('wallet-service-enabled', walletServiceEnabled); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Uses the Hathor Unleash Server and Proxy to determine if the | ||
* wallet should use the WalletService facade or the old facade | ||
* | ||
* @params {string} userId An user identifier (e.g. the firstAddress) | ||
* @params {string} network The network name ('mainnet' or 'testnet') | ||
* | ||
* @return {boolean} The result from the unleash feature flag | ||
*/ | ||
async shouldUseWalletService() { | ||
try { | ||
const shouldIgnore = await localStorage.getItem(IGNORE_WALLET_SERVICE_FLAG); | ||
if (shouldIgnore) { | ||
return false; | ||
} | ||
this.client.updateContext({ userId: this.userId }); | ||
|
||
// Start polling for feature flag updates | ||
await this.client.start(); | ||
|
||
// start() method will have already called the fetchToggles, so the flag should be enabled | ||
const isWalletServiceEnabled = this.client.isEnabled(this.walletServiceFlag); | ||
this.walletServiceEnabled = isWalletServiceEnabled; | ||
|
||
return this.walletServiceEnabled; | ||
} catch (e) { | ||
// If our feature flag service is unavailable, we default to the | ||
// old facade | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Sets the ignore flag on the storage to persist it between app restarts | ||
*/ | ||
async ignoreWalletServiceFlag() { | ||
await localStorage.setItem(IGNORE_WALLET_SERVICE_FLAG, 'true'); | ||
this.walletServiceEnabled = false; | ||
|
||
// Stop the client from polling | ||
this.client.stop(); | ||
} | ||
|
||
/** | ||
* Removes the ignore flag from the storage | ||
*/ | ||
static clearIgnoreWalletServiceFlag() { | ||
localStorage.removeItem(IGNORE_WALLET_SERVICE_FLAG); | ||
} | ||
} |
Oops, something went wrong.