Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#351 - WalletProvider refactor to move init logic into contexts/*.tsx #380

Merged
merged 58 commits into from
Aug 2, 2021

Conversation

fuxingloh
Copy link
Contributor

@fuxingloh fuxingloh commented Aug 1, 2021

What kind of PR is this?:

/kind refactor

What this PR does / why we need it:

I didn't test the encryption module, I assume it will work because it compiled on native.

  • Renamed WalletManagementProvider to WalletPersistenceProvider as it should not init wallet.
  • WalletProvider can accept any WalletPersistenceData and automatically init the correct wallet type with WalletProvider.
    • Thus, this moves wallet PasscodeAttempt logic into the context instead.
    • Under the hood the same context <WalletContext.Provider value={wallet}> is still used to allow for wallet agnostic implementation.
  • Added PasscodeAttemptCounter from Encrypted Mnemonic Wallet #351
  • Added jellyfish 0.33.0 that uses scrypt-js with pure JS implementation closes ScryptProvider implementation #370
  • Refactored Playground to support new WalletPersistenceProvider implementation with WalletProvider
  • Added WalletAddressProvider for setting address in-store, this is added for legacy reasons. This should be deprecated.

ivan added 30 commits July 22, 2021 15:01
completed verify pin (pending some text and styling)
- ui implementation (page, pin input)
- tx queue (in store), split from broadcast queue
- retry mech + state management
- clear wallet after consecutive failure (persistent failure counter, reset upon valid pin)
@codeclimate
Copy link

codeclimate bot commented Aug 1, 2021

Code Climate has analyzed commit 773c589 and detected 0 issues on this pull request.

View more on Code Climate.

@defichain-bot
Copy link
Contributor

Missing Translations Report

The following translations are missing for this pull request.

View Full Report
{
    "zh-Hans": {
        "missingCount": 135,
        "labels": {
            "screens/OceanInterface": [
                "Transaction Sent",
                "title",
                "An error has occurred",
                "OK"
            ],
            "components/BarCodeScanner": [
                "Requesting for camera permission",
                "You have denied the permission request to use your camera"
            ],
            "screens/OnboardingCarousel": [
                "DeFiChain",
                "Wallet",
                "A wallet dedicated to the native decentralized finance for bitcoin.",
                "title",
                "subtitle"
            ],
            "screens/RestoreWallet": [
                "Error",
                "The recovery words you have entered are invalid. Please double check and try again.",
                "Please provide your 24 recovery words to regain access to your wallet.",
                "ENTER THE CORRECT WORD",
                "RECOVER WALLET"
            ],
            "screens/SendScreen": [
                "`Enter word #${order}`",
                "CONTINUE",
                "Sending",
                "Transaction fee",
                "SEND",
                "TO ADDRESS",
                "Enter an address",
                "Enter an amount",
                "Balance: ",
                "MAX",
                "Wallet Send"
            ],
            "screens/Onboarding": [
                "CREATE A WALLET",
                "RESTORE WALLET"
            ],
            "screens/GuidelinesRecoveryWords": [
                "What are recovery words?",
                "'Your unique 24 recovery words is a human-readable representation of your wallet private key",
                "'You will need your recovery words to restore your wallet on",
                "'If you lose your recovery words",
                "'It is important that you write down your recovery words legibly and in the correct order. Store your recovery words safely and securely"
            ],
            "screens/Guidelines": [
                "Creating a wallet",
                "'Before you create a wallet",
                "Learn more about recovery words",
                "g.title",
                "g.subtitle",
                "'I understand it is my responsibility to keep my recovery words secure",
                "SHOW MY 24 RECOVERY WORDS"
            ],
            "screens/WalletNavigator": [
                "Guidelines",
                "Learn More",
                "Display recovery words",
                "Verify words",
                "Recover Wallet"
            ],
            "screens/LoadingScreen": [
                "Loading"
            ],
            "screens/ErrorBoundary": [
                "Something went wrong",
                "The app ran into a problem and could not recover. Please restart your application."
            ],
            "screens/TransactionDetailScreen": [
                "tx.desc)",
                "tx.amount)",
                "`${tx.block}`)",
                "tx.txid"
            ],
            "screens/TransactionsScreen": [
                "desc",
                "block",
                "LOAD MORE",
                "Transactions",
                "No transactions yet",
                "Start transacting with your wallet. All transactions made will be displayed here.",
                "RECEIVE COINS"
            ],
            "screens/TransactionsDetailScreen": [
                "Transaction"
            ],
            "screens/CommunityScreen": [
                "Connect with the community:",
                "DeFiChain is a community-driven and open project.",
                "The DeFiChain Foundation does not provide direct support.",
                "title",
                "Community"
            ],
            "screens/Settings": [
                "NETWORK",
                "Are you sure you want to unlink your wallet?",
                "You will need to use your recovery words the next time you want to get back to your wallet.",
                "Cancel",
                "Unlink Wallet",
                "UNLINK WALLET"
            ],
            "screens/SettingsNavigator": [
                "Settings"
            ],
            "screens/PoolSwapScreen": [
                "From",
                "To",
                "SWAP",
                "Enter an amount",
                "Balance: ",
                "MAX",
                "Price",
                "Estimated to receive",
                "Minimum to receive",
                "Liquidity provider fee",
                "Swapping Token"
            ],
            "screens/DexScreen": [
                "YOUR LIQUIDITY",
                "'Pick a pool pair below",
                "section.key",
                "Decentralized Exchange",
                "Add Liquidity",
                "Remove Liquidity"
            ],
            "screens/RemoveLiquidity": [
                "Amount of liquidity to remove",
                "Removing Liquidity"
            ],
            "screens/AddLiquidity": [
                "Price",
                "`Token ${props.type === 'primary' ? 'A' : 'B'}`",
                "Balance",
                "MAX",
                "per",
                "Share of pool",
                "Pooled "
            ],
            "components/slider": [
                "None"
            ],
            "components": [
                "All"
            ],
            "components/Button": [
                "CONTINUE"
            ],
            "screens/ConfirmAddLiq": [
                "Adding",
                "Fee",
                "Price",
                "Liquidity tokens received",
                "Share of pool",
                "Pooled"
            ],
            "screens/ConfirmLiquidity": [
                "CONFIRM",
                "Adding Liquidity"
            ],
            "screens/TokensVsUtxoScreen": [
                "'DFI exists in two forms – UTXO and token",
                "'UTXO DFI is the main form DFI and is used for core cryptocurrency purposes like send",
                "Your DFI balance includes both UTXO and tokens.",
                "label",
                "props.label"
            ],
            "screens/TokenDetailScreen": [
                "AMOUNT BALANCE",
                "AVAILABLE OPTIONS",
                "Send to other wallet",
                "Receive",
                "Convert"
            ],
            "screens/ReceiveScreen": [
                "Use this address to receive DFI or any DST",
                "Copy",
                "Wallet Receive"
            ],
            "screens/ConvertScreen": [
                "PREVIEW CONVERSION",
                "\"Tokens vs UTXO",
                "Converting DFI",
                "Convert DFIs",
                "Scan recipient QR",
                "Tokens vs UTXO"
            ],
            "screens/Convert": [
                "titlePrefix",
                "Balance"
            ],
            "components/max": [
                "MAX"
            ],
            "screens/BalancesScreen": [
                "BALANCE DETAILS",
                "props.title",
                "Wallet Balances"
            ]
        },
        "totalCount": 135
    },
    "zh-Hant": {
        "missingCount": 134,
        "labels": {
            "screens/OceanInterface": [
                "Transaction Sent",
                "title",
                "An error has occurred",
                "OK"
            ],
            "components/BarCodeScanner": [
                "Requesting for camera permission",
                "You have denied the permission request to use your camera"
            ],
            "screens/OnboardingCarousel": [
                "DeFiChain",
                "Wallet",
                "A wallet dedicated to the native decentralized finance for bitcoin.",
                "title",
                "subtitle"
            ],
            "screens/RestoreWallet": [
                "Error",
                "The recovery words you have entered are invalid. Please double check and try again.",
                "Please provide your 24 recovery words to regain access to your wallet.",
                "ENTER THE CORRECT WORD",
                "RECOVER WALLET"
            ],
            "screens/SendScreen": [
                "`Enter word #${order}`",
                "CONTINUE",
                "Sending",
                "Transaction fee",
                "SEND",
                "TO ADDRESS",
                "Enter an address",
                "Enter an amount",
                "Balance: ",
                "MAX",
                "Wallet Send"
            ],
            "screens/Onboarding": [
                "CREATE A WALLET",
                "RESTORE WALLET"
            ],
            "screens/GuidelinesRecoveryWords": [
                "What are recovery words?",
                "'Your unique 24 recovery words is a human-readable representation of your wallet private key",
                "'You will need your recovery words to restore your wallet on",
                "'If you lose your recovery words",
                "'It is important that you write down your recovery words legibly and in the correct order. Store your recovery words safely and securely"
            ],
            "screens/Guidelines": [
                "Creating a wallet",
                "'Before you create a wallet",
                "Learn more about recovery words",
                "g.title",
                "g.subtitle",
                "'I understand it is my responsibility to keep my recovery words secure",
                "SHOW MY 24 RECOVERY WORDS"
            ],
            "screens/WalletNavigator": [
                "Guidelines",
                "Learn More",
                "Display recovery words",
                "Verify words",
                "Recover Wallet"
            ],
            "screens/LoadingScreen": [
                "Loading"
            ],
            "screens/ErrorBoundary": [
                "Something went wrong",
                "The app ran into a problem and could not recover. Please restart your application."
            ],
            "screens/TransactionDetailScreen": [
                "tx.desc)",
                "tx.amount)",
                "`${tx.block}`)",
                "tx.txid"
            ],
            "screens/TransactionsScreen": [
                "desc",
                "block",
                "LOAD MORE",
                "No transactions yet",
                "Start transacting with your wallet. All transactions made will be displayed here.",
                "RECEIVE COINS"
            ],
            "screens/TransactionsDetailScreen": [
                "Transaction"
            ],
            "screens/CommunityScreen": [
                "Connect with the community:",
                "DeFiChain is a community-driven and open project.",
                "The DeFiChain Foundation does not provide direct support.",
                "title",
                "Community"
            ],
            "screens/Settings": [
                "NETWORK",
                "Are you sure you want to unlink your wallet?",
                "You will need to use your recovery words the next time you want to get back to your wallet.",
                "Cancel",
                "Unlink Wallet",
                "UNLINK WALLET"
            ],
            "screens/SettingsNavigator": [
                "Settings"
            ],
            "screens/PoolSwapScreen": [
                "From",
                "To",
                "SWAP",
                "Enter an amount",
                "Balance: ",
                "MAX",
                "Price",
                "Estimated to receive",
                "Minimum to receive",
                "Liquidity provider fee",
                "Swapping Token"
            ],
            "screens/DexScreen": [
                "YOUR LIQUIDITY",
                "'Pick a pool pair below",
                "section.key",
                "Decentralized Exchange",
                "Add Liquidity",
                "Remove Liquidity"
            ],
            "screens/RemoveLiquidity": [
                "Amount of liquidity to remove",
                "Removing Liquidity"
            ],
            "screens/AddLiquidity": [
                "Price",
                "`Token ${props.type === 'primary' ? 'A' : 'B'}`",
                "Balance",
                "MAX",
                "per",
                "Share of pool",
                "Pooled "
            ],
            "components/slider": [
                "None"
            ],
            "components": [
                "All"
            ],
            "components/Button": [
                "CONTINUE"
            ],
            "screens/ConfirmAddLiq": [
                "Adding",
                "Fee",
                "Price",
                "Liquidity tokens received",
                "Share of pool",
                "Pooled"
            ],
            "screens/ConfirmLiquidity": [
                "CONFIRM",
                "Adding Liquidity"
            ],
            "screens/TokensVsUtxoScreen": [
                "'DFI exists in two forms – UTXO and token",
                "'UTXO DFI is the main form DFI and is used for core cryptocurrency purposes like send",
                "Your DFI balance includes both UTXO and tokens.",
                "label",
                "props.label"
            ],
            "screens/TokenDetailScreen": [
                "AMOUNT BALANCE",
                "AVAILABLE OPTIONS",
                "Send to other wallet",
                "Receive",
                "Convert"
            ],
            "screens/ReceiveScreen": [
                "Use this address to receive DFI or any DST",
                "Copy",
                "Wallet Receive"
            ],
            "screens/ConvertScreen": [
                "PREVIEW CONVERSION",
                "\"Tokens vs UTXO",
                "Converting DFI",
                "Convert DFIs",
                "Scan recipient QR",
                "Tokens vs UTXO"
            ],
            "screens/Convert": [
                "titlePrefix",
                "Balance"
            ],
            "components/max": [
                "MAX"
            ],
            "screens/BalancesScreen": [
                "BALANCE DETAILS",
                "props.title",
                "Wallet Balances"
            ]
        },
        "totalCount": 135
    },
    "de": {
        "missingCount": 134,
        "labels": {
            "screens/OceanInterface": [
                "Transaction Sent",
                "title",
                "An error has occurred",
                "OK"
            ],
            "components/BarCodeScanner": [
                "Requesting for camera permission",
                "You have denied the permission request to use your camera"
            ],
            "screens/OnboardingCarousel": [
                "DeFiChain",
                "Wallet",
                "A wallet dedicated to the native decentralized finance for bitcoin.",
                "title",
                "subtitle"
            ],
            "screens/RestoreWallet": [
                "Error",
                "The recovery words you have entered are invalid. Please double check and try again.",
                "Please provide your 24 recovery words to regain access to your wallet.",
                "ENTER THE CORRECT WORD",
                "RECOVER WALLET"
            ],
            "screens/SendScreen": [
                "`Enter word #${order}`",
                "CONTINUE",
                "Sending",
                "Transaction fee",
                "SEND",
                "TO ADDRESS",
                "Enter an address",
                "Enter an amount",
                "Balance: ",
                "MAX",
                "Wallet Send"
            ],
            "screens/Onboarding": [
                "CREATE A WALLET",
                "RESTORE WALLET"
            ],
            "screens/GuidelinesRecoveryWords": [
                "What are recovery words?",
                "'Your unique 24 recovery words is a human-readable representation of your wallet private key",
                "'You will need your recovery words to restore your wallet on",
                "'If you lose your recovery words",
                "'It is important that you write down your recovery words legibly and in the correct order. Store your recovery words safely and securely"
            ],
            "screens/Guidelines": [
                "Creating a wallet",
                "'Before you create a wallet",
                "Learn more about recovery words",
                "g.title",
                "g.subtitle",
                "'I understand it is my responsibility to keep my recovery words secure",
                "SHOW MY 24 RECOVERY WORDS"
            ],
            "screens/WalletNavigator": [
                "Guidelines",
                "Learn More",
                "Display recovery words",
                "Verify words",
                "Recover Wallet"
            ],
            "screens/LoadingScreen": [
                "Loading"
            ],
            "screens/ErrorBoundary": [
                "Something went wrong",
                "The app ran into a problem and could not recover. Please restart your application."
            ],
            "screens/TransactionDetailScreen": [
                "tx.desc)",
                "tx.amount)",
                "`${tx.block}`)",
                "tx.txid"
            ],
            "screens/TransactionsScreen": [
                "desc",
                "block",
                "LOAD MORE",
                "No transactions yet",
                "Start transacting with your wallet. All transactions made will be displayed here.",
                "RECEIVE COINS"
            ],
            "screens/TransactionsDetailScreen": [
                "Transaction"
            ],
            "screens/CommunityScreen": [
                "Connect with the community:",
                "DeFiChain is a community-driven and open project.",
                "The DeFiChain Foundation does not provide direct support.",
                "title",
                "Community"
            ],
            "screens/Settings": [
                "NETWORK",
                "Are you sure you want to unlink your wallet?",
                "You will need to use your recovery words the next time you want to get back to your wallet.",
                "Cancel",
                "Unlink Wallet",
                "UNLINK WALLET"
            ],
            "screens/SettingsNavigator": [
                "Settings"
            ],
            "screens/PoolSwapScreen": [
                "From",
                "To",
                "SWAP",
                "Enter an amount",
                "Balance: ",
                "MAX",
                "Price",
                "Estimated to receive",
                "Minimum to receive",
                "Liquidity provider fee",
                "Swapping Token"
            ],
            "screens/DexScreen": [
                "YOUR LIQUIDITY",
                "'Pick a pool pair below",
                "section.key",
                "Decentralized Exchange",
                "Add Liquidity",
                "Remove Liquidity"
            ],
            "screens/RemoveLiquidity": [
                "Amount of liquidity to remove",
                "Removing Liquidity"
            ],
            "screens/AddLiquidity": [
                "Price",
                "`Token ${props.type === 'primary' ? 'A' : 'B'}`",
                "Balance",
                "MAX",
                "per",
                "Share of pool",
                "Pooled "
            ],
            "components/slider": [
                "None"
            ],
            "components": [
                "All"
            ],
            "components/Button": [
                "CONTINUE"
            ],
            "screens/ConfirmAddLiq": [
                "Adding",
                "Fee",
                "Price",
                "Liquidity tokens received",
                "Share of pool",
                "Pooled"
            ],
            "screens/ConfirmLiquidity": [
                "CONFIRM",
                "Adding Liquidity"
            ],
            "screens/TokensVsUtxoScreen": [
                "'DFI exists in two forms – UTXO and token",
                "'UTXO DFI is the main form DFI and is used for core cryptocurrency purposes like send",
                "Your DFI balance includes both UTXO and tokens.",
                "label",
                "props.label"
            ],
            "screens/TokenDetailScreen": [
                "AMOUNT BALANCE",
                "AVAILABLE OPTIONS",
                "Send to other wallet",
                "Receive",
                "Convert"
            ],
            "screens/ReceiveScreen": [
                "Use this address to receive DFI or any DST",
                "Copy",
                "Wallet Receive"
            ],
            "screens/ConvertScreen": [
                "PREVIEW CONVERSION",
                "\"Tokens vs UTXO",
                "Converting DFI",
                "Convert DFIs",
                "Scan recipient QR",
                "Tokens vs UTXO"
            ],
            "screens/Convert": [
                "titlePrefix",
                "Balance"
            ],
            "components/max": [
                "MAX"
            ],
            "screens/BalancesScreen": [
                "BALANCE DETAILS",
                "props.title",
                "Wallet Balances"
            ]
        },
        "totalCount": 135
    }
}

@codecov
Copy link

codecov bot commented Aug 1, 2021

Codecov Report

Merging #380 (773c589) into main (0e027e2) will decrease coverage by 1.68%.
The diff coverage is 71.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #380      +/-   ##
==========================================
- Coverage   88.51%   86.83%   -1.69%     
==========================================
  Files          95       97       +2     
  Lines        1376     1413      +37     
  Branches      210      210              
==========================================
+ Hits         1218     1227       +9     
- Misses        157      185      +28     
  Partials        1        1              
Impacted Files Coverage Δ
App.tsx 0.00% <ø> (ø)
app/api/wallet/persistence.ts 94.73% <ø> (ø)
...creens/PlaygroundNavigator/PlaygroundNavigator.tsx 100.00% <ø> (ø)
...ator/screens/CreateWallet/VerifyMnemonicWallet.tsx 0.00% <0.00%> (ø)
app/store/wallet.ts 100.00% <ø> (ø)
app/api/wallet/passcode_attempt.ts 28.57% <28.57%> (ø)
app/contexts/WalletContext.tsx 41.93% <37.03%> (-58.07%) ⬇️
app/api/wallet/provider/mnemonic_encrypted.ts 61.53% <61.53%> (ø)
app/api/wallet/index.ts 100.00% <100.00%> (ø)
app/contexts/WalletPersistenceContext.tsx 100.00% <100.00%> (ø)
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0e027e2...773c589. Read the comment docs.

@netlify
Copy link

netlify bot commented Aug 1, 2021

✔️ Deploy Preview for defi-wallet ready!

🔨 Explore the source changes: 773c589

🔍 Inspect the deploy log: https://app.netlify.com/sites/defi-wallet/deploys/61067a0cc34aae0007678244

😎 Browse the preview: https://deploy-preview-380--defi-wallet.netlify.app/

@defichain-bot
Copy link
Contributor

Build preview for DeFi Wallet is ready!

Built with commit fea926d

https://expo.io/@defichain/wallet?release-channel=pr-preview-380

@cypress
Copy link

cypress bot commented Aug 1, 2021



Test summary

87 0 0 0


Run details

Project wallet
Status Passed
Commit fea926d ℹ️
Started Aug 1, 2021 11:00 AM
Ended Aug 1, 2021 11:14 AM
Duration 13:34 💡
OS Linux Ubuntu - 20.04
Browser Chrome 92

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@fuxingloh fuxingloh changed the title #351 - WalletProvider refactor to move init logic into tsx #351 - WalletProvider refactor to move init logic into contexts/*.tsx Aug 1, 2021
@fuxingloh fuxingloh requested a review from ivan-zynesis August 1, 2021 11:08
@fuxingloh fuxingloh marked this pull request as ready for review August 2, 2021 02:22
@fuxingloh fuxingloh requested a review from thedoublejay as a code owner August 2, 2021 02:22
@thedoublejay thedoublejay merged commit 5ebaf94 into main Aug 2, 2021
@thedoublejay thedoublejay deleted the fuxingloh/scrypt branch August 2, 2021 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ScryptProvider implementation
4 participants