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.
Improved DB + Full Testnet DB support (#187)
* Improved DB interface, Account class, type-safety * Simple Testnet Database + Encryption support * Fix TXs for unencrypted wallets * Hide "Secure your wallet" during switches * Fix "Import" flow breaking on network switch * Add extra safeguards + improved UI resetting
- Loading branch information
Showing
16 changed files
with
504 additions
and
205 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
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,61 @@ | ||
import { Contact } from './contacts-book'; | ||
|
||
/** | ||
* A local Account, containing sensitive user-data | ||
*/ | ||
export class Account { | ||
/** | ||
* Create an Account. | ||
* @param {Object} accountData - The account data. | ||
* @param {String} accountData.publicKey - The public key. | ||
* @param {String} [accountData.encWif] - The encrypted WIF. | ||
* @param {Array<Object>} [accountData.localProposals] - The local proposals. | ||
* @param {Array<Contact>} [accountData.contacts] - The Contacts saved in this account. | ||
* @param {String} [account.name] - The Contact Name of the account. | ||
*/ | ||
constructor(accountData) { | ||
// Keys take the Constructor as priority, but if missing, default to their "Type" in empty form for type-safety | ||
this.publicKey = accountData?.publicKey || ''; | ||
this.encWif = accountData?.encWif || ''; | ||
this.localProposals = accountData?.localProposals || []; | ||
this.contacts = accountData?.contacts || []; | ||
this.name = accountData?.name || ''; | ||
} | ||
|
||
/** @type {String} The public key. */ | ||
publicKey = ''; | ||
|
||
/** @type {String} The encrypted WIF. */ | ||
encWif = ''; | ||
|
||
/** @type {Array<Object>} The local proposals. */ | ||
localProposals = []; | ||
|
||
/** @type {Array<Contact>} The Contacts saved in this account. */ | ||
contacts = []; | ||
|
||
/** @type {String} The Contact Name of the account. */ | ||
name = ''; | ||
|
||
/** | ||
* Search for a Contact in this account, by specific properties | ||
* @param {Object} settings | ||
* @param {string?} settings.name - The Name of the contact to search for | ||
* @param {string?} settings.pubkey - The Pubkey of the contact to search for | ||
* @returns {Contact?} - A Contact, if found | ||
*/ | ||
getContactBy({ name, pubkey }) { | ||
if (!name && !pubkey) | ||
throw Error( | ||
'getContactBy(): At least ONE search parameter MUST be set!' | ||
); | ||
|
||
// Get by Name | ||
if (name) return this.contacts.find((a) => a.label === name); | ||
// Get by Pubkey | ||
if (pubkey) return this.contacts.find((a) => a.pubkey === pubkey); | ||
|
||
// Nothing found | ||
return null; | ||
} | ||
} |
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.