Skip to content

Commit

Permalink
chore: tidy test app, adding request accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Jun 6, 2022
1 parent 5cf51a9 commit f48bf9b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 56 deletions.
6 changes: 2 additions & 4 deletions src/app/pages/choose-account-request/account-request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ export function AccountRequest() {
if (!accounts) throw new Error('Cannot request account details with no account');

if (!tabId || !id || !origin) {
logger.error(
'Missing necessary search param values. All values are necessary to respond to app'
);
logger.error('Missing necessary search param values needed to request account');
return;
}

grantDomainPermission(origin);
sendRequestAccountResponseToTab({ tabId, id, account: accounts[index] });
await delay(1000);
await delay(60);
window.close();
};

Expand Down
4 changes: 2 additions & 2 deletions test-app/src/components/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Button, Text, Box, ButtonGroup } from '@stacks/ui';
import { useConnect } from '@stacks/connect-react';
import { OnboardingSelectors } from '@tests/integration/onboarding/onboarding.selectors';

export const Auth: React.FC = () => {
export const JwtAuth: React.FC = () => {
const { doOpenAuth } = useConnect();
return (
<Box>
Expand All @@ -17,7 +17,7 @@ export const Auth: React.FC = () => {
onClick={() => doOpenAuth()}
data-testid={OnboardingSelectors.SignUpBtn}
>
Sign up
JWT Authentication
</Button>
</ButtonGroup>
</Box>
Expand Down
107 changes: 57 additions & 50 deletions test-app/src/components/home.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useContext, useState } from 'react';
import { AppContext } from '@common/context';
import { Box, Text, Flex, BoxProps, Button } from '@stacks/ui';
import { Auth } from './auth';
import { JwtAuth } from './auth';
import { Tab } from './tab';
import { Status } from './status';
import { Counter } from './counter';
Expand Down Expand Up @@ -63,62 +63,69 @@ const Page: React.FC<{ tab: Tabs; setTab: (value: Tabs) => void }> = ({ tab, set
export const Home: React.FC = () => {
const state = useContext(AppContext);
const [tab, setTab] = useState<Tabs>('debug');
const { doSTXTransfer } = useConnect();
const [account, setAccount] = useState<any>(null);
return (
<Container>
<Text as="h1" textStyle="display.large" fontSize={7} mb={'loose'} display="block">
Testnet Demo
</Text>
{state.userData ? <Page tab={tab} setTab={setTab} /> : <Auth />}
<Button
my="base"
onClick={() => {
// console.log('request accounts app', getStacksProvider());
getStacksProvider()
.request('stx_requestAccounts')
.then(resp => {
setAccount(resp);
console.log('request acct resp', resp);
{state.userData || account ? (
<Page tab={tab} setTab={setTab} />
) : (
<>
<JwtAuth />
<Button
size="lg"
my="base"
onClick={() => {
// console.log('request accounts app', getStacksProvider());
getStacksProvider()
.request('stx_requestAccounts')
.then(resp => {
setAccount(resp);
console.log('request acct resp', resp);
});
}}
>
Request accounts
</Button>
</>
)}
{/*
<Button
my="base"
ml="base"
// isDisabled={account === null}
onClick={() => {
// getStacksProvider()
// .request('stx_signTransactionRequest', [{}])
// .then(resp => {
// // setAccount(resp);
// console.log('transaction req from inpage', resp);
// });
// const stxAddress = getAddressFromPublicKey(
// account[0].stxPublicKey,
// TransactionVersion.Testnet
// );
// console.log({ stxAddress });
doSTXTransfer({
network: network as any,
amount: '100',
memo: 'From demo app',
recipient: 'ST1X6M947Z7E58CNE0H8YJVJTVKS9VW0PHEG3NHN3',
stxAddress: 'ST17YZQB1228EK9MPHQXA8GC4G3HVWZ66X779FEBY',
// stxAddress,
onFinish: data => {
console.log('finished stx transfer!', data);
},
onCancel: () => {
console.log('popup closed!');
},
});
}}
>
Request accounts
</Button>
<Button
my="base"
ml="base"
// isDisabled={account === null}
onClick={() => {
// getStacksProvider()
// .request('stx_signTransactionRequest', [{}])
// .then(resp => {
// // setAccount(resp);
// console.log('transaction req from inpage', resp);
// });
// const stxAddress = getAddressFromPublicKey(
// account[0].stxPublicKey,
// TransactionVersion.Testnet
// );
// console.log({ stxAddress });
doSTXTransfer({
network: network as any,
amount: '100',
memo: 'From demo app',
recipient: 'ST1X6M947Z7E58CNE0H8YJVJTVKS9VW0PHEG3NHN3',
stxAddress: 'ST17YZQB1228EK9MPHQXA8GC4G3HVWZ66X779FEBY',
// stxAddress,
onFinish: data => {
console.log('finished stx transfer!', data);
},
onCancel: () => {
console.log('popup closed!');
},
});
}}
>
Sign transaction
</Button>
}}
>
Sign transaction
</Button> */}

{/* <Button
my="base"
Expand Down

0 comments on commit f48bf9b

Please sign in to comment.