forked from JSKitty/scc-web3
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Dashboard with useWallet and useSettings composables (#271)
* Refactor Dashboard with useWallet and useSettings composables * Review changes
- Loading branch information
Showing
4 changed files
with
145 additions
and
58 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { getEventEmitter } from '../event_bus.js'; | ||
import { ref } from 'vue'; | ||
import { nDisplayDecimals, fAdvancedMode } from '../settings.js'; | ||
|
||
export function useSettings() { | ||
const advancedMode = ref(fAdvancedMode); | ||
const displayDecimals = ref(0); | ||
|
||
getEventEmitter().on('advanced-mode', (fAdvancedMode) => { | ||
advancedMode.value = fAdvancedMode; | ||
}); | ||
getEventEmitter().on('balance-update', async () => { | ||
displayDecimals.value = nDisplayDecimals; | ||
}); | ||
return { | ||
advancedMode, | ||
displayDecimals, | ||
}; | ||
} |
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,74 @@ | ||
import { getEventEmitter } from '../event_bus.js'; | ||
import { hasEncryptedWallet, wallet } from '../wallet.js'; | ||
import { ref } from 'vue'; | ||
import { strCurrency } from '../settings.js'; | ||
import { mempool } from '../global.js'; | ||
import { cMarket } from '../settings.js'; | ||
|
||
/** | ||
* This is the middle ground between vue and the wallet class | ||
* It makes sure that everything is up to date and provides | ||
* a reactive interface to it | ||
*/ | ||
export function useWallet() { | ||
// Eventually we want to create a new wallet | ||
// For now we'll just import the existing one | ||
// const wallet = new Wallet(); | ||
|
||
const isImported = ref(wallet.isLoaded()); | ||
const isViewOnly = ref(wallet.isViewOnly()); | ||
const getKeyToBackup = async () => await wallet.getKeyToBackup(); | ||
const isEncrypted = ref(true); | ||
|
||
const setMasterKey = (mk) => { | ||
wallet.setMasterKey(mk); | ||
isImported.value = wallet.isLoaded(); | ||
isHardwareWallet.value = wallet.isHardwareWallet(); | ||
isHD.value = wallet.isHD(); | ||
isViewOnly.value = wallet.isViewOnly(); | ||
hasEncryptedWallet().then((i) => (isEncrypted.value = i)); | ||
}; | ||
const getAddress = () => wallet.getAddress(); | ||
const isHardwareWallet = ref(wallet.isHardwareWallet()); | ||
const isHD = ref(wallet.isHD()); | ||
const checkDecryptPassword = async (passwd) => | ||
await wallet.checkDecryptPassword(passwd); | ||
|
||
hasEncryptedWallet().then((r) => { | ||
isEncrypted.value = r; | ||
}); | ||
|
||
const encrypt = async (passwd) => { | ||
await wallet.encrypt(passwd); | ||
isEncrypted.value = await hasEncryptedWallet(); | ||
}; | ||
const balance = ref(0); | ||
const currency = ref('USD'); | ||
const price = ref(0.0); | ||
|
||
getEventEmitter().on('balance-update', async () => { | ||
balance.value = mempool.balance; | ||
currency.value = strCurrency.toUpperCase(); | ||
price.value = await cMarket.getPrice(strCurrency); | ||
}); | ||
|
||
return { | ||
isImported, | ||
isViewOnly, | ||
isEncrypted, | ||
getKeyToBackup, | ||
setMasterKey, | ||
isHardwareWallet, | ||
checkDecryptPassword, | ||
encrypt, | ||
getAddress, | ||
wipePrivateData: () => { | ||
wallet.wipePrivateData(); | ||
isViewOnly.value = wallet.isViewOnly(); | ||
}, | ||
isHD, | ||
balance, | ||
currency, | ||
price, | ||
}; | ||
} |
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
Oops, something went wrong.