diff --git a/src/utils/constants.js b/src/utils/constants.js index d7a8d1f..655999a 100644 --- a/src/utils/constants.js +++ b/src/utils/constants.js @@ -1,5 +1,3 @@ -export const STOREAGE_SALT = 'b9f4088bd3a93783147e3d78aa10cc911a2449a0d79a226ae33a5957b368cc18' - export const KS_PRF = { 'hmac-sha256': 'SHA-256', } diff --git a/src/utils/dash/local.js b/src/utils/dash/local.js index a77b7fe..93a74cb 100644 --- a/src/utils/dash/local.js +++ b/src/utils/dash/local.js @@ -190,35 +190,6 @@ export async function deriveAddressData( return address } -// export async function batchAddressGenerate( -// wallet, -// accountIndex = 0, -// addressIndex = 0, -// use = DashHd.RECEIVE, -// batchSize = 20 -// ) { -// let batchLimit = addressIndex + batchSize -// let addresses = [] - -// let account = await wallet.deriveAccount(accountIndex); -// let xkey = await account.deriveXKey(use); - -// for (;addressIndex < batchLimit; addressIndex++) { -// let key = await xkey.deriveAddress(addressIndex); -// let address = await DashHd.toAddr(key.publicKey); -// addresses.push({ -// address, -// addressIndex, -// accountIndex, -// }) -// } - -// return { -// addresses, -// finalAddressIndex: addressIndex, -// } -// } - export function phraseToEl(phrase, el = 'span', cls = 'tag') { let words = phrase?.split(' ') return words?.map( @@ -328,9 +299,6 @@ export function formatDash( return balance } - - - export async function getUnusedChangeAddress(account) { let filterQuery = { xkeyId: account.xkeyId, @@ -386,11 +354,6 @@ export async function initWalletsInfo( } } - - - - - export async function initWallet( encryptionPassword, wallet, @@ -479,10 +442,6 @@ export async function initWallet( } } - - - - export function filterPairedContacts(contact) { let outLen = Object.keys(contact.outgoing || {}).length return outLen > 0 // && !!contact.alias @@ -688,10 +647,6 @@ export function generateContactPairingURI( } let scope = claims.map(p => p[0]).join(',') - // let searchParams = new URLSearchParams([ - // ...claims, - // ['scope', scope] - // ]) let searchParams = new DashURLSearchParams([ ...claims, ['scope', scope] @@ -761,9 +716,6 @@ export function generatePaymentRequestURI( ) } - // let searchParams = new URLSearchParams([ - // ...claims, - // ]) let searchParams = new DashURLSearchParams([ ...claims, ]) @@ -777,9 +729,6 @@ export function generatePaymentRequestURI( return res } - - - export async function getRandomWords(len = 32) { return await DashPhrase.generate(len) } @@ -853,9 +802,6 @@ export function getAddressIndexFromUsage(wallet, account, usageIdx) { } } - - - export async function generateAddressIterator( xkey, xkeyId, @@ -1034,10 +980,6 @@ export async function batchAddressUsageGenerate( } } - - - - export async function getTotalFunds(wallet) { let funds = 0 let result = {} @@ -1274,8 +1216,6 @@ export function sortAddrs(a, b) { return indexDiff; } - - export function getBalance(utxos) { return utxos.reduce(function (total, utxo) { return total + utxo.satoshis; @@ -1344,12 +1284,6 @@ export function selectOptimalUtxos(utxos, output) { return included; } - - - - - - export function sortIncomingAndOutgoingTxs({ conAddr, tx, addr, dir, sentAmount = null, receivedAmount = null, byAlias = {}, byAddress = {}, byTx = {}, @@ -1399,8 +1333,6 @@ export function sortIncomingAndOutgoingTxs({ } } - - export async function getContactsByXkeyId( appState, ) { @@ -1495,19 +1427,6 @@ export function getTransactionsByContactAlias(appState) { appState.contacts = res - // let contactAddrs = await deriveContactAddrs(appState) || {} - // let addrs = Object.keys(contactAddrs) - - // console.log('contactAddrs', addrs) - - // if (addrs?.length) { - // getAddrsTransactions({ - // appState, addrs, contactAddrs - // }) - // } - - // console.log('contacts', res, contactAddrs) - return res } } diff --git a/src/utils/dash/network.js b/src/utils/dash/network.js index ed420dd..e259793 100644 --- a/src/utils/dash/network.js +++ b/src/utils/dash/network.js @@ -54,64 +54,9 @@ export async function initDashSocket( await dashsocket.init() .catch((e) => console.log('dashsocket catch err', e)); - // setTimeout(() => { - // dashsocket.close() - // }, 15*60*1000); - return dashsocket } -// export async function checkWalletFunds(addr, wallet = {}) { -// const HOUR = 1000 * 60 * 60; - -// let { -// address, -// accountIndex, -// addressIndex, -// usageIndex, -// } = addr -// let updatedAt = Date.now() -// let $addr = await store.addresses.getItem(address) || {} - -// $addr = { -// walletId: wallet.id, -// accountIndex, -// addressIndex, -// usageIndex, -// ...$addr, -// } -// // console.log('checkWalletFunds $addr', $addr) -// let walletFunds = $addr?.insight - -// if ( -// !walletFunds?.updatedAt || -// updatedAt - walletFunds?.updatedAt > HOUR -// ) { -// // console.info('check insight api for addr', addr) - -// let insightRes = await dashsight.getInstantBalance(address) - -// if (insightRes) { -// let { addrStr, ...res } = insightRes -// walletFunds = res - -// $addr.insight = { -// ...walletFunds, -// updatedAt, -// } - -// store.addresses.setItem( -// address, -// $addr, -// ) -// } -// } - -// // console.info('check addr funds', addr, walletFunds) - -// return $addr -// } - export async function updateAddrFunds( wallet, insightRes, ) { @@ -123,14 +68,6 @@ export async function updateAddrFunds( xkeyId, } = $addr - // console.log( - // 'checkWalletFunds $addr', - // $addr, - // walletId, - // wallet?.id, - // walletId === wallet?.id - // ) - if (walletId && walletId === wallet?.id) { let storedWallet = await store.wallets.getItem(walletId) || {} let storedAccount = await store.accounts.getItem(xkeyId) || {} @@ -171,7 +108,6 @@ export async function updateAddrFunds( if ($addr.accountIndex >= storeAcctLen) { batchGenAccts(wallet.recoveryPhrase, $addr.accountIndex) .then(() => { - // updateAllFunds(wallet) batchGenAcctsAddrs(wallet) .then(accts => { console.log('batchGenAcctsAddrs', { accts }) @@ -208,11 +144,6 @@ export async function updateAllFunds(wallet) { ) let balances = await dashsight.getInstantBalances(addrKeys) - // let txs = await dashsight.getAllTxs( - // addrKeys - // ) - - // console.log('getAllTxs', txs) if (balances.length >= 0) { walletFunds.balance = funds @@ -246,11 +177,6 @@ export async function updateAllFunds(wallet) { return funds } - - - - - export async function deriveTxWallet( fromWallet, fundAddrs, @@ -258,7 +184,6 @@ export async function deriveTxWallet( let cachedAddrs = {} let privateKeys = {} let coreUtxos - // let transactions let tmpWallet if (Array.isArray(fundAddrs) && fundAddrs.length > 0) { @@ -285,9 +210,6 @@ export async function deriveTxWallet( coreUtxos = await dashsight.getMultiCoreUtxos( Object.keys(privateKeys) ) - // transactions = await dashsight.getAllTxs( - // Object.keys(privateKeys) - // ) } else { tmpWallet = await deriveWalletData( fromWallet.recoveryPhrase, @@ -307,24 +229,15 @@ export async function deriveTxWallet( coreUtxos = await dashsight.getCoreUtxos( tmpWallet.address ) - // transactions = await dashsight.getAllTxs( - // [tmpWallet.address] - // ) } - // console.log('getAllTxs', transactions) - return { privateKeys, cachedAddrs, coreUtxos, - // transactions, } } - - - export async function createStandardTx( fromWallet, fundAddrs, @@ -783,8 +696,6 @@ export async function getAddrsTransactions({ } } - - export async function getTxs(appState, transactions = []) { let contactAddrs = await getContactsFromAddrs(appState) let contactOutAddrs = await deriveContactAddrs(appState) diff --git a/src/utils/db.js b/src/utils/db.js index a75d500..03b7222 100644 --- a/src/utils/db.js +++ b/src/utils/db.js @@ -22,32 +22,23 @@ export const localForageBaseCfg = { const loadedStores = {} -export async function DatabaseSetup() { - loadedStores.wallets = loadedStores.wallets || localforage.createInstance({ - ...localForageBaseCfg, - storeName: 'wallets', - }); - loadedStores.aliases = loadedStores.aliases || localforage.createInstance({ - ...localForageBaseCfg, - storeName: 'aliases', - }); - loadedStores.contacts = loadedStores.contacts || localforage.createInstance({ - ...localForageBaseCfg, - storeName: 'contacts', - }); - loadedStores.accounts = loadedStores.accounts || localforage.createInstance({ +export function loadInstance(name) { + loadedStores[name] = loadedStores[name] || localforage.createInstance({ ...localForageBaseCfg, - storeName: 'accounts', - }); - loadedStores.addresses = loadedStores.addresses || localforage.createInstance({ - ...localForageBaseCfg, - storeName: 'addresses', - }); - loadedStores.transactions = loadedStores.transactions || localforage.createInstance({ - ...localForageBaseCfg, - storeName: 'transactions', + storeName: [name], }); + return loadedStores[name] +} + +export async function DatabaseSetup() { + loadInstance('wallets'); + loadInstance('aliases'); + loadInstance('contacts'); + loadInstance('accounts'); + loadInstance('addresses'); + loadInstance('transactions'); + return loadedStores } diff --git a/src/utils/generic.js b/src/utils/generic.js index 03b6f78..68531db 100644 --- a/src/utils/generic.js +++ b/src/utils/generic.js @@ -1,6 +1,5 @@ import { - TIMEAGO_LOCALE_EN, - MOMENT, MOMENTS, NEVER, + TIMEAGO_LOCALE_EN, MOMENTS, NEVER, SECONDS, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR, } from './constants.js' @@ -29,7 +28,6 @@ let eventHandlers = [] * @returns {string} */ export const lit = (s, ...v) => String.raw({ raw: s }, ...(v.map(x => x || ''))) -// export const lit = (s, ...v) => String.raw({ raw: s }, ...v) export function isEmpty(value) { if (value === null) { diff --git a/src/utils/qr.js b/src/utils/qr.js index 4671602..771aaf9 100644 --- a/src/utils/qr.js +++ b/src/utils/qr.js @@ -1,7 +1,5 @@ "use strict"; -import { toDash } from './dash/local.js' - /** * @typedef QrOpts * @property {String} [background] @@ -31,7 +29,7 @@ export function create(data, opts) { background: opts?.background || "#fff", ecl: opts?.ecl || "M", }); -}; +} /** * @param {String} data @@ -41,18 +39,4 @@ export function qrSvg (data, opts) { // console.log('qrSvg', data) let qrcode = create(data, opts); return qrcode.svg(); -}; - -/** - * @param {String} addr - Base58Check pubKeyHash address - * @param {Number} duffs - 1/100000000 of a DASH - */ -export function showQr(addr, duffs = 0) { - let dashAmount = toDash(duffs); - let dashUri = `dash://${addr}`; - if (duffs) { - dashUri += `?amount=${dashAmount}`; - } - - return qrSvg(dashUri, { indent: 4, size: "mini" }); }