This repository has been archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve send tx flow, adds receive modal, closes #160
- Loading branch information
1 parent
1325e18
commit 7fa64e5
Showing
25 changed files
with
392 additions
and
146 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
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 +1,9 @@ | ||
export const MNEMONIC_ENTROPY = 256; | ||
|
||
type Environments = 'development' | 'testing' | 'production'; | ||
|
||
export const ENV = (process.env.NODE_ENV ?? 'production') as Environments; | ||
|
||
export const features = { | ||
stackingEnabled: false, | ||
}; |
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,23 @@ | ||
import BN from 'bn.js'; | ||
import { deriveRootKeychainFromMnemonic } from '@blockstack/keychain'; | ||
import { makeSTXTokenTransfer } from '@blockstack/stacks-transactions'; | ||
|
||
import { stacksNetwork } from './environment'; | ||
import { deriveStxAddressKeychain } from './derive-address-keychain'; | ||
|
||
interface CreateStxTxArgs { | ||
mnemonic: string; | ||
recipient: string; | ||
amount: BN; | ||
} | ||
|
||
export async function createStxTransaction({ mnemonic, recipient, amount }: CreateStxTxArgs) { | ||
const rootNode = await deriveRootKeychainFromMnemonic(mnemonic); | ||
const { privateKey } = deriveStxAddressKeychain(rootNode); | ||
return await makeSTXTokenTransfer({ | ||
recipient, | ||
amount, | ||
senderKey: privateKey, | ||
network: stacksNetwork, | ||
}); | ||
} |
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,4 @@ | ||
import { deriveStxAddressChain } from '@blockstack/keychain'; | ||
import { chain } from './environment'; | ||
|
||
export const deriveStxAddressKeychain = deriveStxAddressChain(chain); |
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,14 @@ | ||
import { | ||
ChainID, | ||
StacksNetwork, | ||
StacksTestnet, | ||
StacksMainnet, | ||
} from '@blockstack/stacks-transactions'; | ||
import { ENV } from '../constants'; | ||
|
||
export { ChainID }; | ||
|
||
export const chain = ENV === 'development' || ENV === 'testing' ? ChainID.Testnet : ChainID.Mainnet; | ||
|
||
export const stacksNetwork: StacksNetwork = | ||
ENV === 'development' || ENV === 'testing' ? new StacksTestnet() : new StacksMainnet(); |
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,12 @@ | ||
import { chain, ChainID } from './environment'; | ||
|
||
export function validateAddressChain(address: string) { | ||
const prefix = address.substr(0, 2); | ||
if (chain === ChainID.Testnet) { | ||
return prefix === 'SN' || prefix === 'ST'; | ||
} | ||
if (chain === ChainID.Mainnet) { | ||
return prefix === 'SM' || prefix === 'SP'; | ||
} | ||
return false; | ||
} |
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,64 @@ | ||
import React, { FC, useState } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import Qr from 'qrcode.react'; | ||
import { Text, Modal, Button, Flex, Box, useClipboard } from '@blockstack/ui'; | ||
|
||
import { TxModalHeader, TxModalFooter } from '../transaction/transaction-modal-layout'; | ||
import { homeActions, selectReceiveModalOpen } from '../../store/home/home.reducer'; | ||
|
||
interface ReceiveStxModalProps { | ||
address: string; | ||
} | ||
|
||
export const ReceiveStxModal: FC<ReceiveStxModalProps> = ({ address }) => { | ||
const dispatch = useDispatch(); | ||
const modalOpen = useSelector(selectReceiveModalOpen); | ||
const copyAddressToClipboard = useClipboard(address); | ||
const [buttonText, setButtonText] = useState('Copy address'); | ||
const onCopyAddress = () => { | ||
copyAddressToClipboard.onCopy(); | ||
setButtonText('Copied'); | ||
setTimeout(() => setButtonText('Copy address'), 1000); | ||
}; | ||
const closeModal = () => dispatch(homeActions.closeReceiveModal()); | ||
if (!modalOpen) return null; | ||
return ( | ||
<Modal | ||
minWidth="488px" | ||
isOpen={modalOpen} | ||
headerComponent={<TxModalHeader onSelectClose={closeModal}>Receive STX</TxModalHeader>} | ||
footerComponent={ | ||
<TxModalFooter> | ||
<Button size="lg" onClick={closeModal}> | ||
Close | ||
</Button> | ||
</TxModalFooter> | ||
} | ||
> | ||
<Flex flexDirection="column" alignItems="center" mx="extra-loose"> | ||
<Box border="1px solid #F0F0F5" p="base" mt="extra-loose" borderRadius="8px"> | ||
<Qr value={address} shapeRendering="sharp-edges" /> | ||
</Box> | ||
<Text textStyle="body.large.medium" mt="loose"> | ||
Wallet address | ||
</Text> | ||
<Flex | ||
mt="base-tight" | ||
justifyContent="center" | ||
alignItems="center" | ||
border="1px solid #E1E3E8" | ||
height="48px" | ||
borderRadius="6px" | ||
width="100%" | ||
> | ||
<Text color="ink" fontSize="14px"> | ||
{address} | ||
</Text> | ||
</Flex> | ||
<Button variant="link" mt="tight" mb="loose" onClick={onCopyAddress}> | ||
{buttonText} | ||
</Button> | ||
</Flex> | ||
</Modal> | ||
); | ||
}; |
Oops, something went wrong.