Skip to content

Commit

Permalink
Use RIF Wallet v2 core - Complete (#26)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
jessgusclark and ilanolkies authored Oct 22, 2021
1 parent d7f015f commit 310ea9d
Show file tree
Hide file tree
Showing 30 changed files with 615 additions and 639 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/lib/core
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
37 changes: 22 additions & 15 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -19,42 +19,50 @@ const WalletApp: React.FC<Interface> = ({ navigation }) => {
// Temporary component state:
interface componentStateI {
confirmResponse?: string
wallet?: Wallet
wallet?: RIFWallet
}

const [wallet, setWallet] = useState<Wallet | undefined>(undefined)
const [accounts, setAccounts] = useState<Account[]>([])
const [wallet, setWallet] = useState<RIFWallet[]>([])
const [mnemonic, setMnemonic] = useState<string>('')

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
?.getAccount(accounts.length)
.then(account => setAccounts(accounts.concat(account)))
}
}
*/

const seeSmartWallet = (account: Account) =>
const seeSmartWallet = (account: RIFWallet) =>
navigation.navigate('SmartWallet', { account })

return (
<ScrollView>
<Header1>sWallet</Header1>
<View style={styles.section}>
<Header2>Wallet:</Header2>
{wallet && <CopyComponent value={wallet.getMnemonic} />}
<Header2>KMS:</Header2>
<CopyComponent value={mnemonic} />
</View>

<View style={styles.section}>
<Header2>Accounts:</Header2>
{accounts.map((account: Account, index: number) => {
<Header2>RIF Wallets:</Header2>
{wallet.map((account: RIFWallet, index: number) => {
return (
<View key={index}>
<CopyComponent value={account.address} />
<Paragraph>EOA Address</Paragraph>
<CopyComponent value={account.smartWallet.wallet.address} />
<Button
title="See smart wallet"
onPress={() => seeSmartWallet(account)}
Expand All @@ -65,21 +73,20 @@ const WalletApp: React.FC<Interface> = ({ navigation }) => {
/>
<Button
onPress={() => {
// @ts-ignore
navigation.navigate('SendTransaction', { account })
}}
title="Send Transaction"
/>
</View>
)
})}
<Button onPress={addAccount} title="Add account" />
{/*<Button onPress={addAccount} title="Add account" />*/}
</View>

<View style={styles.section}>
<Header2>Settings</Header2>
<Button
onPress={() => removeStorage(StorageKeys.MNEMONIC)}
onPress={() => removeStorage(StorageKeys.KMS)}
title="Clear RN Storage"
/>
<Paragraph>
Expand Down
4 changes: 2 additions & 2 deletions src/RootNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ const RootNavigation: React.FC<Interface> = () => {
</NavigationContainer>

{/* Modals: */}
{context.userInteractionQue.length !== 0 && (
{context.walletRequests[0] && (
<ReviewTransactionModal
closeModal={closeReviewTransactionModal}
queuedTransactionRequest={context.userInteractionQue[0]}
queuedTransactionRequest={context.walletRequests[0]}
/>
)}
</View>
Expand Down
152 changes: 0 additions & 152 deletions src/lib/core/Account.ts

This file was deleted.

Loading

0 comments on commit 310ea9d

Please sign in to comment.