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

feat(portal) new avatar creation #1280

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions src/containers/portal/PasportMoonCitizenship.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ import { Button } from '../../components';
import { routes } from 'src/routes';
import { useAppSelector } from 'src/redux/hooks';
import { selectCurrentPassport } from 'src/features/passport/passports.redux';
import usePassportByAddress from 'src/features/passport/hooks/usePassportByAddress';
import { useAdviser } from 'src/features/adviser/context';
import { selectAccountsPassports } from 'src/features/passport/passports.redux';
import usePassportContract from 'src/features/passport/usePassportContract';
import PassportLoader from 'src/features/passport/PassportLoader';
import convertPassportToCitizenship from './convertPassportToCitizenship';

const portalAmbient = require('../../sounds/portalAmbient112.mp3');

Expand All @@ -46,6 +49,7 @@ const stopPortalAmbient = () => {
function PassportMoonCitizenship() {
const { isMobile: mobile } = useDevice();
const defaultAccount = useAppSelector((state) => state.pocket.defaultAccount);
const accountsPassports = useAppSelector(selectAccountsPassports);

const citizenship = useAppSelector(selectCurrentPassport);
// FIXME: backward compatibility
Expand Down Expand Up @@ -126,20 +130,40 @@ function PassportMoonCitizenship() {
setTxHash(data);
};

const passportIds = usePassportContract<{ tokens: string[] }>({
query: {
tokens: {
owner: addressActive?.bech32,
},
},
});

return (
<>
<MainContainer>
<Stars />
{!mobile && <MoonAnimation />}

<PasportCitizenship
citizenship={citizenship}
txHash={txHash}
onClickProveeAddress={onClickProveeAddress}
onClickDeleteAddress={onClickDeleteAddress}
onClickEditAvatar={onClickEditAvatar}
updateFunc={setSelectedAddress}
/>
{passportIds.data?.tokens.map((tokenId) => (
<PassportLoader
key={tokenId}
tokenId={tokenId}
render={(passport) => (
<PasportCitizenship
citizenship={convertPassportToCitizenship(
passport,
addressActive?.bech32
)}
initStateCard={false}
txHash={txHash}
onClickProveeAddress={onClickProveeAddress}
onClickDeleteAddress={onClickDeleteAddress}
onClickEditAvatar={onClickEditAvatar}
updateFunc={setSelectedAddress}
/>
)}
/>
))}
</MainContainer>
{Math.floor(appStep) === STEP_INFO.STATE_INIT && (
<ActionBarSteps>
Expand Down
4 changes: 2 additions & 2 deletions src/containers/portal/citizenship/Info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function Info({
let content;

switch (stepCurrent) {
case STEP_INIT:
/* case STEP_INIT:
content = (
<div
style={{
Expand All @@ -79,7 +79,7 @@ function Info({
)}
</div>
);
break;
break; */

case STEP_NICKNAME_CHOSE:
content = (
Expand Down
17 changes: 17 additions & 0 deletions src/containers/portal/convertPassportToCitizenship.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Citizenship } from 'src/types/citizenship';

const convertPassportToCitizenship = (
passport: any,
owner: string
): Citizenship => {
return {
owner: owner,
extension: {
nickname: passport.extension?.nickname,
avatar: passport.extension?.avatar,
addresses: passport.extension?.addresses,
},
};
};

export default convertPassportToCitizenship;
3 changes: 2 additions & 1 deletion src/containers/portal/mainPortal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function MainPartal({ defaultAccount }) {
if (responseActivePassport !== null) {
const { addresses } = responseActivePassport.extension;
if (addresses !== null) {
setStagePortal(STAGE_RELEASE);
setStagePortal(STAGE_INIT);
} else {
setStagePortal(STAGE_PROVE);
}
Expand All @@ -83,6 +83,7 @@ function MainPartal({ defaultAccount }) {
};
getPasport();
}, [queryClient, defaultAccount, stagePortal]);
console.debug('stagePortal', stagePortal);

const { setAdviser } = useAdviser();

Expand Down
25 changes: 25 additions & 0 deletions src/features/passport/PassportLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Citizenship } from 'src/types/citizenship';
import usePassportContract from './usePassportContract';

function PassportLoader({
tokenId,
render,
}: {
tokenId: string;
render: (passport: Citizenship) => JSX.Element | null;
}) {
const { data: passport } = usePassportContract<Citizenship>({
query: {
nft_info: {
token_id: tokenId,
},
},
});

if (!passport) {
return null;
}
return render(passport);
}

export default PassportLoader;
23 changes: 1 addition & 22 deletions src/pages/Keys/KeyItem/KeyItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,12 @@ import cx from 'classnames';
import { useSelector } from 'react-redux';
import { RootState } from 'src/redux/store';
import MusicalAddress from 'src/components/MusicalAddress/MusicalAddress';
import PassportLoader from 'src/features/passport/PassportLoader';

type Props = {
account: AccountValue;
};

function PassportLoader({
tokenId,
render,
}: {
tokenId: string;
render: (passport: Citizenship) => JSX.Element | null;
}) {
const { data: passport } = usePassportContract<Citizenship>({
query: {
nft_info: {
token_id: tokenId,
},
},
});

if (!passport) {
return null;
}

return render(passport);
}

function KeyItem({ account, selected, selectKey }: Props) {
const { name, bech32, keys, path } = account;

Expand Down