-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
501 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,4 @@ jspm_packages | |
# Custom | ||
.DS_Store | ||
build | ||
src/Extension |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,166 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import * as bip39 from 'bip39'; | ||
import WAValidator from 'wallet-address-validator'; | ||
import toaster from 'toasted-notes' | ||
|
||
export default function Bitcoin(props) { | ||
const { credentials, setCredentials, subType, onModalClose, selectedItem } = props; | ||
|
||
const defaultValue = selectedItem | ||
? { | ||
walletName: selectedItem.walletName, | ||
walletAddress: selectedItem.walletAddress, | ||
seedWords:selectedItem.seedWords | ||
} | ||
: { | ||
walletName: "", | ||
walletAddress: "", | ||
seedWords:"" | ||
}; | ||
|
||
const [walletName, setWalletName] = useState(defaultValue.walletName); | ||
const [walletAddress, setWalletAddress] = useState(defaultValue.walletAddress); | ||
const [seedWords,setSeedWords]=useState(defaultValue.seedWords) | ||
const [clicked, setClicked] = useState(false); | ||
|
||
useEffect(() => { | ||
if (clicked) { | ||
setClicked(false); | ||
onModalClose(); | ||
} | ||
}, [credentials]); | ||
|
||
const showToast = (text, time) => { | ||
toaster.notify(() => <span className="btn btn-primary mr-2">{text}</span>, { | ||
position: "top", | ||
duration: time | ||
}); | ||
}; | ||
|
||
const validateForm = () => { | ||
const addValid=WAValidator.validate(walletAddress,"BTC") | ||
const valid=bip39.validateMnemonic(seedWords) | ||
console.log("Address ",addValid) | ||
|
||
if (!addValid){ | ||
showToast('Bitcoin wallet address invalid',2000) | ||
} | ||
|
||
if (!valid){ | ||
showToast('Invalid Seed Words',2000) | ||
} | ||
|
||
if (addValid && valid){ | ||
return ( | ||
walletName.length && | ||
walletAddress.length | ||
); | ||
} | ||
}; | ||
|
||
const handleClick = () => { | ||
if (validateForm()) { | ||
const newCred = { | ||
id: Date.now(), | ||
type: 'crypto', | ||
subType: subType, | ||
walletName, | ||
walletAddress, | ||
seedWords | ||
}; | ||
const oldCred = credentials ? JSON.parse(credentials) : []; | ||
setClicked(true); | ||
setCredentials(JSON.stringify([...oldCred, newCred])); | ||
} | ||
}; | ||
|
||
const handleUpdate = () => { | ||
if (validateForm()) { | ||
const updatedCredentials = JSON.parse(credentials).map(item => { | ||
if (item.id === selectedItem.id) { | ||
return { ...item, walletName, walletAddress,seedWords }; | ||
} | ||
return item; | ||
}); | ||
setClicked(true); | ||
setCredentials(JSON.stringify(updatedCredentials)); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="form-group row"> | ||
<label htmlFor="inputName" className="col-4 col-form-label"> | ||
Bitcoin Wallet Name | ||
</label> | ||
<div className="col-8"> | ||
<input | ||
type="text" | ||
className="form-control" | ||
id="inputName" | ||
value={walletName} | ||
onChange={evt => setWalletName(evt.target.value)} | ||
/> | ||
</div> | ||
</div> | ||
<div className="form-group row"> | ||
<label htmlFor="inputAddress" className="col-4 col-form-label"> | ||
Wallet Address | ||
</label> | ||
<div className="col-8"> | ||
<input | ||
type="text" | ||
className="form-control" | ||
id="inputAddress" | ||
value={walletAddress} | ||
onChange={evt => setWalletAddress(evt.target.value)} | ||
/> | ||
</div> | ||
</div> | ||
|
||
<div className="form-group row"> | ||
<label htmlFor="inputSeedWords" className="col-4 col-form-label"> | ||
Seed Words | ||
</label> | ||
<div className="col-8"> | ||
<input | ||
type="text" | ||
className="form-control" | ||
id="inputSeedWords" | ||
value={seedWords} | ||
onChange={evt => setSeedWords(evt.target.value)} | ||
/> | ||
</div> | ||
|
||
</div> | ||
<div className="d-flex justify-content-end"> | ||
{selectedItem ? ( | ||
<button | ||
disabled={clicked} | ||
type="button" | ||
className="btn btn-primary mr-2" | ||
onClick={handleUpdate} | ||
> | ||
Update | ||
</button> | ||
) : ( | ||
<button | ||
disabled={clicked} | ||
type="button" | ||
className="btn btn-primary mr-2" | ||
onClick={handleClick} | ||
> | ||
Save | ||
</button> | ||
)} | ||
<button | ||
type="button" | ||
className="btn btn-primary" | ||
onClick={onModalClose} | ||
> | ||
Cancel | ||
</button> | ||
</div> | ||
</> | ||
); | ||
} |
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.