Skip to content

Commit

Permalink
[Issue-219] Fix minting sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
saltict committed Dec 4, 2024
1 parent 6f77acb commit e5047e6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4258,7 +4258,8 @@ export default class KoniExtension {
chainType: ChainType.EVM,
extrinsicType: ExtrinsicType.MINT_NFT,
transaction: transaction,
transferNativeAmount: '0'
transferNativeAmount: '0',
resolveOnHasExtrinsicHash: true
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/extension-koni-ui/src/Popup/Home/Mint/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const Component = ({ className }: Props): React.ReactElement => {
}, []);

useEffect(() => {
apiSDK.getNftMintingLog().catch(console.error);
const sub = apiSDK.subscribeNftMintingLog().subscribe((data) => {
setMintingLog(data.data);
setIsFetchingNftMintingLog(!data.isFetched);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import { noop, toShort } from '@subwallet/extension-koni-ui/utils';
import { Button, Icon, ModalContext, SwModalFuncProps } from '@subwallet/react-ui';
import CN from 'classnames';
import { ArrowCircleRight, CheckCircle, HouseLine, SmileySad } from 'phosphor-react';
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
import { Trans } from 'react-i18next';
import { useSelector } from 'react-redux';
import styled, { useTheme } from 'styled-components';
import {isHex} from "@polkadot/util";

import { isHex } from '@polkadot/util';

type Props = ThemeProps & {
airdropNftInfo: IAirdropNftMinting,
Expand Down Expand Up @@ -63,19 +64,7 @@ const Component: React.FC<Props> = (props: Props) => {
const [isLoading, setIsLoading] = useState<boolean>(false);
const { connectWC, requireWC } = useContext(WalletConnectContext);
const { alertModal } = useContext(WalletModalContext);

useEffect(() => {
apiSDK.getNftMintingLog().catch(console.error);
}, []);

useEffect(() => {
if (mintingLog?.status === 'success') {
onSuccess(mintingLog.address);
setIsLoading(false);
} else if (mintingLog?.status === 'submitted') {
setIsLoading(true);
}
}, [mintingLog, onSuccess]);
const mintingFlag = useRef(false);

const tabGroupItems = useMemo<TabGroupItemType[]>(() => {
return [
Expand Down Expand Up @@ -486,6 +475,19 @@ const Component: React.FC<Props> = (props: Props) => {
);
};

useEffect(() => {
if (mintingLog?.status === 'success') {
onSuccess(mintingLog.address);
setIsLoading(false);
} else if (mintingLog?.status === 'submitted' || mintingLog?.status === 'minting') {
mintingFlag.current = true;
setIsLoading(true);
} else if (mintingLog?.status === 'failed') {
setIsLoading(false);
mintingFlag.current && handleFailedToMintModal().then(goHome).catch(console.error);
}
}, [goHome, handleFailedToMintModal, mintingLog, onSuccess]);

return (
<>
<div className={CN(className, '-mint-nft-detail')}>
Expand Down
22 changes: 19 additions & 3 deletions packages/extension-koni-ui/src/connector/booka/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ export class BookaSdk {
// this.fetchGameInventoryItemList(),
// this.fetchGameItemInGameList()
]);

this.autoSyncMintingLog();
}
} catch (error: any) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
Expand Down Expand Up @@ -982,16 +984,16 @@ export class BookaSdk {
icon: '/images/mint-event-logo.png',
nft_url: '/images/default-nft-logo.png',
banner: '',
start_snapshot: getUCTPlus7('2024-11-05 10:00'),
start_mint: getUCTPlus7('2024-12-02 10:00'),
start_snapshot: getUCTPlus7('2024-12-05 10:00'),
start_mint: getUCTPlus7('2024-12-06 10:00'),
network: 'Polkadot',
total_badges: 5000,
sub_title: 'Phase 2',
symbol: 'badge',
// decimal: number;
// method: string;
// raffle_count: number;
start: getUCTPlus7('2024-11-02 07:00'),
start: getUCTPlus7('2024-12-02 07:00'),
end: getUCTPlus7('2024-12-07 10:00'),
conditionDescription: '',
share: {
Expand Down Expand Up @@ -1084,6 +1086,20 @@ export class BookaSdk {
return this.mintingLogSubject;
}

autoSyncMintingLog () {
let runCheck = false;

this.mintingLogSubject.subscribe((data) => {
runCheck = data.data?.status === 'minting' || data.data?.status === 'submitted';
});

setInterval(() => {
if (runCheck) {
this.getNftMintingLog().catch(console.error);
}
}, 10000);
}

async nftMintingRequestSignature (address: string, campaign = 'default') {
const data = await this.postRequest<APIResponse<NftMintingLog>>(`${GAME_API_HOST}/api/mint-nft/request-signature`, { address, campaign });

Expand Down

0 comments on commit e5047e6

Please sign in to comment.