From 310ea9d41763bca43f18ea61dfce7765b09f21f0 Mon Sep 17 00:00:00 2001 From: Jesse Clark Date: Fri, 22 Oct 2021 07:06:56 +0300 Subject: [PATCH] Use RIF Wallet v2 core - Complete (#26) * Replace lib/core with new SmartWallet. * Fix lint issues and install a missing package. * Update context to accept the new structure. * Expose mnemonic from the kms via context. * Update core from rif-wallet. - lint was the only thing changed. * Implement new core changes into the HomeScreen (src/App.tsx) * Update SmartWallet to use the new RIFWallet instance. * Update receive screen to use new RIFWallet. * Fix test, smartWalletAddress is no longer a promise. * Fix lint issues. * Update SmartWallet screen to get RIF and send transaction. * Fix test. * Fix lint. * Update core with October 20th updates - Only changes is: lint and _variable * Query RIF and transfer balance using the library. * Rename files. * Remove check if getSmartAddress has been called. It is no longer a promise. * fix failing test with act(). * Fix type path. * Update core + changes in review tx Co-authored-by: Ilan --- .eslintignore | 1 + package.json | 3 +- src/App.tsx | 37 ++-- src/RootNavigation.tsx | 4 +- src/lib/core/Account.ts | 152 --------------- src/lib/core/KeyManagementSystem.ts | 182 ++++++++++++++++++ src/lib/core/RIFWallet.ts | 97 ++++++++++ src/lib/core/SmartWallet.ts | 39 ++++ .../{smartWallet => }/SmartWalletABI.json | 0 src/lib/core/SmartWalletFactory.ts | 50 +++++ .../SmartWalletFactoryABI.json | 2 +- src/lib/core/Wallet.ts | 47 ----- src/lib/core/filterTxOptions.ts | 8 + src/lib/core/index.ts | 4 +- .../core/smartWallet/smart-wallet-factory.js | 44 ----- src/lib/core/smartWallet/smart-wallet.js | 15 -- src/lib/core/tests/Account.test.ts | 106 ---------- src/lib/core/tests/Wallet.test.ts | 43 ----- src/lib/core/tests/test-case.ts | 15 -- src/lib/token/tokenMetadata.ts | 4 +- src/modal/ReviewTransactionModal.test.tsx | 47 +++-- src/modal/ReviewTransactionModal.tsx | 98 +++++----- src/screens/receive/ReceiveScreen.test.tsx | 10 +- src/screens/receive/ReceiveScreen.tsx | 12 +- src/screens/send/SendTransaction.test.tsx | 25 +-- src/screens/send/SendTransaction.tsx | 11 +- src/state/AppContext.tsx | 100 ++++++---- src/storage/index.ts | 2 +- src/tempScreens/SmartWallet.tsx | 83 ++++---- yarn.lock | 13 +- 30 files changed, 615 insertions(+), 639 deletions(-) create mode 100644 .eslintignore delete mode 100644 src/lib/core/Account.ts create mode 100644 src/lib/core/KeyManagementSystem.ts create mode 100644 src/lib/core/RIFWallet.ts create mode 100644 src/lib/core/SmartWallet.ts rename src/lib/core/{smartWallet => }/SmartWalletABI.json (100%) create mode 100644 src/lib/core/SmartWalletFactory.ts rename src/lib/core/{smartWallet => }/SmartWalletFactoryABI.json (99%) delete mode 100644 src/lib/core/Wallet.ts create mode 100644 src/lib/core/filterTxOptions.ts delete mode 100644 src/lib/core/smartWallet/smart-wallet-factory.js delete mode 100644 src/lib/core/smartWallet/smart-wallet.js delete mode 100644 src/lib/core/tests/Account.test.ts delete mode 100644 src/lib/core/tests/Wallet.test.ts delete mode 100644 src/lib/core/tests/test-case.ts diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000..efd718508 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +src/lib/core diff --git a/package.json b/package.json index 3012e8e7e..252b2768b 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "@react-navigation/native": "^6.0.4", "@react-navigation/stack": "^6.0.9", "@rsksmart/rif-id-ethr-did": "^0.1.0", - "@rsksmart/rif-id-mnemonic": "^0.1.0", + "@rsksmart/rif-id-mnemonic": "^0.1.1", + "@rsksmart/rlogin-dpath": "^1.0.1", "@rsksmart/rsk-contract-metadata": "^1.0.15", "@rsksmart/rsk-testnet-contract-metadata": "^1.0.11", "buffer": "^4.9.2", diff --git a/src/App.tsx b/src/App.tsx index 23db58544..2e30a7c7a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,7 +4,7 @@ import { NavigationProp, ParamListBase } from '@react-navigation/native' import Button from './components/button' import { Header1, Header2, Paragraph } from './components/typography' -import { Account, Wallet } from './lib/core' +import { RIFWallet } from './lib/core/RIFWallet' import { WalletProviderContext } from './state/AppContext' import { removeStorage, StorageKeys } from './storage' @@ -19,17 +19,23 @@ const WalletApp: React.FC = ({ navigation }) => { // Temporary component state: interface componentStateI { confirmResponse?: string - wallet?: Wallet + wallet?: RIFWallet } - const [wallet, setWallet] = useState(undefined) - const [accounts, setAccounts] = useState([]) + const [wallet, setWallet] = useState([]) + const [mnemonic, setMnemonic] = useState('') const context = useContext(WalletProviderContext) useEffect(() => { - setWallet(context.wallet) - }, [context.wallet, wallet]) + context.wallets && setWallet(context.wallets) + }, [context.wallets]) + useEffect(() => { + console.log('setting Mnemonic', context.getMnemonic()) + setMnemonic(context.getMnemonic()) + }, [context.wallets]) + + /* const addAccount = () => { if (wallet) { wallet @@ -37,24 +43,26 @@ const WalletApp: React.FC = ({ navigation }) => { .then(account => setAccounts(accounts.concat(account))) } } + */ - const seeSmartWallet = (account: Account) => + const seeSmartWallet = (account: RIFWallet) => navigation.navigate('SmartWallet', { account }) return ( sWallet - Wallet: - {wallet && } + KMS: + - Accounts: - {accounts.map((account: Account, index: number) => { + RIF Wallets: + {wallet.map((account: RIFWallet, index: number) => { return ( - + EOA Address +