-
Notifications
You must be signed in to change notification settings - Fork 6
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
Create a loan backup file when confirming #226
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
72da67e
Split up sign_loan function into logical parts.
bonomat 17dbbdc
Add loan backup feature.
bonomat 2be7a09
Add load loan backup feature into option page.
bonomat 2b21b57
Clean up confirm loan by merging the files.
bonomat 3a9e86c
Download file instead of opening a new tab.
bonomat 933758c
Update extension/wallet/src/wallet/loan_backup.rs
bonomat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import Debug from "debug"; | ||
import { browser } from "webextension-polyfill-ts"; | ||
import WavesProvider from "../in-page"; | ||
import { LoanDetails, LoanToSign, SwapToSign, Txid } from "../models"; | ||
import { BackupDetails, LoanDetails, LoanToSign, SwapToSign, Txid } from "../models"; | ||
import { | ||
bip39SeedWords, | ||
createLoanBackup, | ||
createNewBip39Wallet, | ||
extractLoan, | ||
extractTrade, | ||
|
@@ -12,6 +13,7 @@ import { | |
getBlockHeight, | ||
getOpenLoans, | ||
getPastTransactions, | ||
loadLoanBackup, | ||
makeBuyCreateSwapPayload, | ||
makeLoanRequestPayload, | ||
makeSellCreateSwapPayload, | ||
|
@@ -171,11 +173,32 @@ window.signLoan = async () => { | |
// on the pop-up matches what is stored in the extension's | ||
// storage. It would be better to send around the swap ID to check | ||
// that the wallet is signing the same transaction the user has authorised | ||
signLoan(walletName) | ||
.then(resolveLoanSignRequest) | ||
.catch(rejectLoanSignRequest) | ||
.then(cleanupPendingLoan); | ||
|
||
// if we receive an error, we respond directly, else we return the details | ||
return await signLoan(walletName).catch(rejectLoanSignRequest); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}; | ||
|
||
// @ts-ignore | ||
window.confirmLoan = async (payload: string) => { | ||
if (!resolveLoanSignRequest || !rejectLoanSignRequest) { | ||
throw new Error("No pending promise functions for loan sign request"); | ||
} | ||
// once sent to the page, we assume the business is done. | ||
// TODO: a feedback loop is required where the wallet gets told if bobtimus successfully published the transaction | ||
resolveLoanSignRequest(payload); | ||
await cleanupPendingLoan(); | ||
}; | ||
|
||
// @ts-ignore | ||
window.createLoanBackup = async (loanTx: string) => { | ||
return createLoanBackup(walletName, loanTx); | ||
}; | ||
|
||
// @ts-ignore | ||
window.loadLoanBackup = async (backupDetails: BackupDetails) => { | ||
return loadLoanBackup(backupDetails); | ||
}; | ||
|
||
// @ts-ignore | ||
window.rejectLoan = () => { | ||
if (!resolveLoanSignRequest || !rejectLoanSignRequest) { | ||
|
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,122 @@ | ||
import { Alert, AlertDescription, AlertIcon, AlertTitle, Button, Flex, VStack } from "@chakra-ui/react"; | ||
import { Step, Steps, useSteps } from "chakra-ui-steps"; | ||
import * as React from "react"; | ||
import { useState } from "react"; | ||
import { FiCheck, FiClipboard, FiExternalLink } from "react-icons/all"; | ||
import { confirmLoan, createLoanBackup } from "../background-proxy"; | ||
import { LoanToSign } from "../models"; | ||
import ConfirmLoan from "./ConfirmLoan"; | ||
|
||
interface ConfirmLoanWizardProps { | ||
onCancel: () => void; | ||
onSuccess: () => void; | ||
loanToSign: LoanToSign; | ||
} | ||
|
||
const ConfirmLoanWizard = ({ onCancel, onSuccess, loanToSign }: ConfirmLoanWizardProps) => { | ||
const { nextStep, activeStep } = useSteps({ | ||
initialStep: 0, | ||
}); | ||
let [signedTransaction, setSignedTransaction] = useState(""); | ||
|
||
const onSigned = (tx: string) => { | ||
setSignedTransaction(tx); | ||
nextStep(); | ||
}; | ||
|
||
const downloadLoanBackup = async () => { | ||
const loanBackup = await createLoanBackup(signedTransaction); | ||
const file = new Blob([JSON.stringify(loanBackup)], { type: "text/json" }); | ||
const url = URL.createObjectURL(file); | ||
// Note: it would be nicer to open a dialog to download the file. However, we would lose focus | ||
// of the window. We don't want that, hence we just open a new tab with the content | ||
window.open(url, "_blank"); | ||
nextStep(); | ||
}; | ||
|
||
const onPublish = async () => { | ||
await confirmLoan(signedTransaction); | ||
onSuccess(); | ||
}; | ||
|
||
return ( | ||
<VStack width="100%"> | ||
<Steps activeStep={activeStep}> | ||
<Step label={"Sign"} key={"sign"} icon={FiClipboard}> | ||
<Flex py={4}> | ||
<ConfirmLoan | ||
loanToSign={loanToSign} | ||
onCancel={onCancel} | ||
onSigned={onSigned} | ||
/> | ||
</Flex> | ||
</Step> | ||
<Step label={"Backup"} key={"backup"} icon={FiExternalLink}> | ||
<Flex py={4}> | ||
<VStack> | ||
<Alert | ||
status="warning" | ||
variant="subtle" | ||
flexDirection="column" | ||
alignItems="center" | ||
justifyContent="center" | ||
textAlign="center" | ||
height="250px" | ||
> | ||
<AlertIcon boxSize="40px" mr={0} /> | ||
<AlertTitle mt={4} mb={1} fontSize="lg"> | ||
Create a backup! | ||
</AlertTitle> | ||
<AlertDescription> | ||
Click below to download a backup of the loan details. Together with your seed words | ||
you can recover your loan details in case your browser storage gets purged. Keep it | ||
safe! You can restore your backup through the settings. | ||
</AlertDescription> | ||
</Alert> | ||
<Button | ||
onClick={async () => { | ||
await downloadLoanBackup(); | ||
}} | ||
data-cy="data-cy-download-loan-button" | ||
> | ||
Download backup | ||
</Button> | ||
</VStack> | ||
</Flex> | ||
</Step> | ||
|
||
<Step label={"Confirm"} key={"confirm"} icon={FiCheck}> | ||
<Flex py={4}> | ||
<VStack> | ||
<Alert | ||
status="info" | ||
variant="subtle" | ||
flexDirection="column" | ||
alignItems="center" | ||
justifyContent="center" | ||
textAlign="center" | ||
height="200px" | ||
> | ||
<AlertIcon boxSize="40px" mr={0} /> | ||
<AlertTitle mt={4} mb={1} fontSize="lg"> | ||
Backup saved? | ||
</AlertTitle> | ||
<AlertDescription> | ||
The lender will publish the transaction once signed. | ||
</AlertDescription> | ||
</Alert> | ||
<Button | ||
onClick={() => onPublish()} | ||
data-cy="data-cy-confirm-loan-button" | ||
> | ||
Confirm | ||
</Button> | ||
</VStack> | ||
</Flex> | ||
</Step> | ||
</Steps> | ||
</VStack> | ||
); | ||
}; | ||
|
||
export default ConfirmLoanWizard; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noice! I also found that one and wanted to use it at some point :D