Skip to content

Commit

Permalink
Merge branch 'koni/dev/issue-task-onchain' into telegram-dev-02
Browse files Browse the repository at this point in the history
  • Loading branch information
anhnhu committed May 14, 2024
2 parents 9f06eb2 + 2c8da6b commit 1ff54f3
Show file tree
Hide file tree
Showing 24 changed files with 1,274 additions and 127 deletions.
9 changes: 8 additions & 1 deletion packages/extension-base/src/background/KoniTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ export enum ExtrinsicType {
TOKEN_APPROVE = 'evm.token_approve',

EVM_EXECUTE = 'evm.execute',
UNKNOWN = 'unknown'
UNKNOWN = 'unknown',
REMARK_WITH_EVENT = 'remark_with_event'
}

export interface ExtrinsicDataTypeMap {
Expand Down Expand Up @@ -1121,6 +1122,12 @@ export interface NftTransactionRequest {
nftItem: NftItem
}

export interface RemarkWithEvent {
networkKey: string,
address: string,
dataRemark: string
}

export interface EvmNftTransaction extends ValidateTransactionResponse {
tx: Record<string, any> | null;
}
Expand Down
170 changes: 169 additions & 1 deletion packages/extension-base/src/koni/background/handlers/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,153 @@ import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
import { createSubscription } from '@subwallet/extension-base/background/handlers/subscriptions';
import { AccountExternalError, AccountExternalErrorCode, AccountsWithCurrentAddress, AddressBookInfo, AmountData, AmountDataWithId, AssetSetting, AssetSettingUpdateReq, BasicTxErrorType, BasicTxWarningCode, BondingOptionParams, BrowserConfirmationType, CampaignBanner, CampaignData, CampaignDataType, ChainType, CreateDeriveAccountInfo, CronReloadRequest, CurrentAccountInfo, DeriveAccountInfo, ExternalRequestPromiseStatus, ExtrinsicType, KeyringState, MantaPayEnableMessage, MantaPayEnableParams, MantaPayEnableResponse, MantaPaySyncState, NftCollection, NftJson, NftTransactionRequest, NftTransactionResponse, OptionInputAddress, PriceJson, RequestAccountCreateExternalV2, RequestAccountCreateHardwareMultiple, RequestAccountCreateHardwareV2, RequestAccountCreateSuriV2, RequestAccountCreateWithSecretKey, RequestAccountExportPrivateKey, RequestAccountMeta, RequestAddInjectedAccounts, RequestApproveConnectWalletSession, RequestApproveWalletConnectNotSupport, RequestAuthorization, RequestAuthorizationBlock, RequestAuthorizationPerAccount, RequestAuthorizationPerSite, RequestAuthorizeApproveV2, RequestBatchRestoreV2, RequestBondingSubmit, RequestCameraSettings, RequestCampaignBannerComplete, RequestChangeEnableChainPatrol, RequestChangeLanguage, RequestChangeMasterPassword, RequestChangeShowBalance, RequestChangeShowZeroBalance, RequestChangeTimeAutoLock, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestConnectWalletConnect, RequestCrossChainTransfer, RequestDeleteContactAccount, RequestDeriveCreateMultiple, RequestDeriveCreateV2, RequestDeriveCreateV3, RequestDeriveValidateV2, RequestDisconnectWalletConnectSession, RequestEditContactAccount, RequestFindRawMetadata, RequestForgetSite, RequestFreeBalance, RequestGetDeriveAccounts, RequestGetTransaction, RequestJsonRestoreV2, RequestKeyringExportMnemonic, RequestMaxTransferable, RequestMigratePassword, RequestParseEvmContractInput, RequestParseTransactionSubstrate, RequestPassPhishingPage, RequestQrParseRLP, RequestQrSignEvm, RequestQrSignSubstrate, RequestRejectConnectWalletSession, RequestRejectExternalRequest, RequestRejectWalletConnectNotSupport, RequestRemoveInjectedAccounts, RequestResetWallet, RequestResolveExternalRequest, RequestSaveRecentAccount, RequestSeedCreateV2, RequestSeedValidateV2, RequestSettingsType, RequestSigningApprovePasswordV2, RequestStakePoolingBonding, RequestStakePoolingUnbonding, RequestSubscribeHistory, RequestSubstrateNftSubmitTransaction, RequestTransfer, RequestTransferCheckReferenceCount, RequestTransferCheckSupporting, RequestTransferExistentialDeposit, RequestTuringCancelStakeCompound, RequestTuringStakeCompound, RequestUnbondingSubmit, RequestUnlockKeyring, RequestUnlockType, ResolveAddressToDomainRequest, ResolveDomainRequest, ResponseAccountCreateSuriV2, ResponseAccountCreateWithSecretKey, ResponseAccountExportPrivateKey, ResponseAccountMeta, ResponseChangeMasterPassword, ResponseCheckPublicAndSecretKey, ResponseDeriveValidateV2, ResponseFindRawMetadata, ResponseGetDeriveAccounts, ResponseKeyringExportMnemonic, ResponseMigratePassword, ResponseParseEvmContractInput, ResponseParseTransactionSubstrate, ResponsePrivateKeyValidateV2, ResponseQrParseRLP, ResponseQrSignEvm, ResponseQrSignSubstrate, ResponseRejectExternalRequest, ResponseResetWallet, ResponseResolveExternalRequest, ResponseSeedCreateV2, ResponseSeedValidateV2, ResponseSubscribeHistory, ResponseUnlockKeyring, StakingTxErrorType, StakingType, SupportTransferResponse, ThemeNames, TransactionHistoryItem, TransactionResponse, TransferTxErrorType, ValidateNetworkRequest, ValidateNetworkResponse, ValidatorInfo } from '@subwallet/extension-base/background/KoniTypes';
import {
AccountExternalError,
AccountExternalErrorCode,
AccountsWithCurrentAddress,
AddressBookInfo,
AmountData,
AmountDataWithId,
AssetSetting,
AssetSettingUpdateReq,
BasicTxErrorType,
BasicTxWarningCode,
BondingOptionParams,
BrowserConfirmationType,
CampaignBanner,
CampaignData,
CampaignDataType,
ChainType,
CreateDeriveAccountInfo,
CronReloadRequest,
CurrentAccountInfo,
DeriveAccountInfo,
ExternalRequestPromiseStatus,
ExtrinsicType,
KeyringState,
MantaPayEnableMessage,
MantaPayEnableParams,
MantaPayEnableResponse,
MantaPaySyncState,
NftCollection,
NftJson,
NftTransactionRequest,
NftTransactionResponse,
OptionInputAddress,
PriceJson,
RemarkWithEvent,
RequestAccountCreateExternalV2,
RequestAccountCreateHardwareMultiple,
RequestAccountCreateHardwareV2,
RequestAccountCreateSuriV2,
RequestAccountCreateWithSecretKey,
RequestAccountExportPrivateKey,
RequestAccountMeta,
RequestAddInjectedAccounts,
RequestApproveConnectWalletSession,
RequestApproveWalletConnectNotSupport,
RequestAuthorization,
RequestAuthorizationBlock,
RequestAuthorizationPerAccount,
RequestAuthorizationPerSite,
RequestAuthorizeApproveV2,
RequestBatchRestoreV2,
RequestBondingSubmit,
RequestCameraSettings,
RequestCampaignBannerComplete,
RequestChangeEnableChainPatrol,
RequestChangeLanguage,
RequestChangeMasterPassword,
RequestChangeShowBalance,
RequestChangeShowZeroBalance,
RequestChangeTimeAutoLock,
RequestCheckPublicAndSecretKey,
RequestConfirmationComplete,
RequestConnectWalletConnect,
RequestCrossChainTransfer,
RequestDeleteContactAccount,
RequestDeriveCreateMultiple,
RequestDeriveCreateV2,
RequestDeriveCreateV3,
RequestDeriveValidateV2,
RequestDisconnectWalletConnectSession,
RequestEditContactAccount,
RequestFindRawMetadata,
RequestForgetSite,
RequestFreeBalance,
RequestGetDeriveAccounts,
RequestGetTransaction,
RequestJsonRestoreV2,
RequestKeyringExportMnemonic,
RequestMaxTransferable,
RequestMigratePassword,
RequestParseEvmContractInput,
RequestParseTransactionSubstrate,
RequestPassPhishingPage,
RequestQrParseRLP,
RequestQrSignEvm,
RequestQrSignSubstrate,
RequestRejectConnectWalletSession,
RequestRejectExternalRequest,
RequestRejectWalletConnectNotSupport,
RequestRemoveInjectedAccounts,
RequestResetWallet,
RequestResolveExternalRequest,
RequestSaveRecentAccount,
RequestSeedCreateV2,
RequestSeedValidateV2,
RequestSettingsType,
RequestSigningApprovePasswordV2,
RequestStakePoolingBonding,
RequestStakePoolingUnbonding,
RequestSubscribeHistory,
RequestSubstrateNftSubmitTransaction,
RequestTransfer,
RequestTransferCheckReferenceCount,
RequestTransferCheckSupporting,
RequestTransferExistentialDeposit,
RequestTuringCancelStakeCompound,
RequestTuringStakeCompound,
RequestUnbondingSubmit,
RequestUnlockKeyring,
RequestUnlockType,
ResolveAddressToDomainRequest,
ResolveDomainRequest,
ResponseAccountCreateSuriV2,
ResponseAccountCreateWithSecretKey,
ResponseAccountExportPrivateKey,
ResponseAccountMeta,
ResponseChangeMasterPassword,
ResponseCheckPublicAndSecretKey,
ResponseDeriveValidateV2,
ResponseFindRawMetadata,
ResponseGetDeriveAccounts,
ResponseKeyringExportMnemonic,
ResponseMigratePassword,
ResponseParseEvmContractInput,
ResponseParseTransactionSubstrate,
ResponsePrivateKeyValidateV2,
ResponseQrParseRLP,
ResponseQrSignEvm,
ResponseQrSignSubstrate,
ResponseRejectExternalRequest,
ResponseResetWallet,
ResponseResolveExternalRequest,
ResponseSeedCreateV2,
ResponseSeedValidateV2,
ResponseSubscribeHistory,
ResponseUnlockKeyring,
StakingTxErrorType,
StakingType,
SupportTransferResponse,
ThemeNames,
TransactionHistoryItem,
TransactionResponse,
TransferTxErrorType,
ValidateNetworkRequest,
ValidateNetworkResponse,
ValidatorInfo
} from '@subwallet/extension-base/background/KoniTypes';
import RequestBytesSign from '@subwallet/extension-base/background/RequestBytesSign';
import RequestExtrinsicSign from '@subwallet/extension-base/background/RequestExtrinsicSign';
import { AccountAuthType, AccountJson, AuthorizeRequest, MessageTypes, MetadataRequest, RequestAccountChangePassword, RequestAccountCreateExternal, RequestAccountCreateHardware, RequestAccountCreateSuri, RequestAccountEdit, RequestAccountExport, RequestAccountForget, RequestAccountShow, RequestAccountTie, RequestAccountValidate, RequestAuthorizeCancel, RequestAuthorizeReject, RequestBatchRestore, RequestCurrentAccountAddress, RequestDeriveCreate, RequestDeriveValidate, RequestJsonRestore, RequestMetadataApprove, RequestMetadataReject, RequestSeedCreate, RequestSeedValidate, RequestSigningApproveSignature, RequestSigningCancel, RequestTypes, ResponseAccountExport, ResponseAuthorizeList, ResponseDeriveValidate, ResponseJsonGetAccountInfo, ResponseSeedCreate, ResponseSeedValidate, ResponseSigning, ResponseType, SigningRequest, WindowOpenParams } from '@subwallet/extension-base/background/types';
Expand Down Expand Up @@ -3963,6 +4109,25 @@ export default class KoniExtension {
return this.#koniState.sign('https://booka.games', new RequestExtrinsicSign(request), { address, ...pair.meta });
}

private async remarkWithEvent (request: RemarkWithEvent): Promise<SWTransactionResponse> {
const address = request.address;
const networkKey = request.networkKey;

const apiProps = this.#koniState.getSubstrateApi(networkKey);
const transaction = apiProps.api.tx.system.remarkWithEvent(request.dataRemark);
const rs = await this.#koniState.transactionService.handleTransaction({
address: address,
chain: networkKey,
transaction: transaction,
extrinsicType: ExtrinsicType.REMARK_WITH_EVENT,
chainType: ChainType.SUBSTRATE,
resolveOnDone: true,
data: {}
});

return rs;
}

// --------------------------------------------------------------
// eslint-disable-next-line @typescript-eslint/require-await
public async handle<TMessageType extends MessageTypes> (id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise<ResponseType<TMessageType>> {
Expand Down Expand Up @@ -4273,6 +4438,9 @@ export default class KoniExtension {
return this.evmNftSubmitTransaction(request as NftTransactionRequest);
case 'pri(substrateNft.submitTransaction)':
return this.substrateNftSubmitTransaction(request as RequestSubstrateNftSubmitTransaction);
/// Remark
case 'pri(remark.remarkWithEvent)':
return this.remarkWithEvent(request as RemarkWithEvent);

/// Transfer
case 'pri(accounts.transfer)':
Expand Down
3 changes: 2 additions & 1 deletion packages/extension-base/src/services/chain-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const forceChainInfoMap = (() => {
const enableList = [
'polkadot',
'goldberg_testnet',
'kusama'
'kusama',
'alephTest'
];

return Object.fromEntries(enableList.map((slug) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ const Component = function ({ className }: Props) {
case ExtrinsicType.CROWDLOAN:
case ExtrinsicType.EVM_EXECUTE:
case ExtrinsicType.UNKNOWN:
case ExtrinsicType.REMARK_WITH_EVENT:
return t('Transaction confirm');
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const getTransactionComponent = (extrinsicType: ExtrinsicType): typeof BaseTrans
case ExtrinsicType.STAKING_CANCEL_COMPOUNDING:
case ExtrinsicType.STAKING_COMPOUNDING:
case ExtrinsicType.EVM_EXECUTE:
case ExtrinsicType.REMARK_WITH_EVENT:
case ExtrinsicType.UNKNOWN:
return BaseTransactionConfirmation;
}
Expand Down
87 changes: 77 additions & 10 deletions packages/extension-koni-ui/src/Popup/Home/Games/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// Copyright 2019-2022 @subwallet/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { ShopModal } from '@subwallet/extension-koni-ui/components';
import GameAccount from '@subwallet/extension-koni-ui/components/Games/GameAccount';
import GameEnergy from '@subwallet/extension-koni-ui/components/Games/GameEnergy';
import { ShopModalId } from '@subwallet/extension-koni-ui/components/Modal/Shop/ShopModal';
import { BookaSdk } from '@subwallet/extension-koni-ui/connector/booka/sdk';
import { Game } from '@subwallet/extension-koni-ui/connector/booka/types';
import { EnergyConfig, Game, GameInventoryItem, GameItem } from '@subwallet/extension-koni-ui/connector/booka/types';
import { useSetCurrentPage, useTranslation } from '@subwallet/extension-koni-ui/hooks';
import { GameApp } from '@subwallet/extension-koni-ui/Popup/Home/Games/gameSDK';
import { ThemeProps } from '@subwallet/extension-koni-ui/types';
import { Button, Image, Typography } from '@subwallet/react-ui';
import { Button, Icon, Image, ModalContext, Typography } from '@subwallet/react-ui';
import CN from 'classnames';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { ShoppingBag } from 'phosphor-react';
import React, { useCallback, useContext, useEffect, useRef, useState } from 'react';
import styled from 'styled-components';

type Props = ThemeProps;
Expand All @@ -28,10 +31,17 @@ function checkComingSoon (game: Game): boolean {
return gameStartTime > Date.now();
}

const shopModalId = ShopModalId;

const Component = ({ className }: Props): React.ReactElement => {
useSetCurrentPage('/home/games');
const gameIframe = useRef<HTMLIFrameElement>(null);
const [gameList, setGameList] = useState<Game[]>(apiSDK.gameList);
const [energyConfig, setEnergyConfig] = useState<EnergyConfig | undefined>(apiSDK.energyConfig);
const [gameItemMap, setGameItemMap] = useState<Record<string, GameItem[]>>(apiSDK.gameItemMap);
const [gameInventoryItemList, setGameInventoryItemList] = useState<GameInventoryItem[]>(apiSDK.gameInventoryItemList);
const [currentGameShopId, setCurrentGameShopId] = useState<number>();
const { activeModal } = useContext(ModalContext);
const [account, setAccount] = useState(apiSDK.account);
const [currentGame, setCurrentGame] = useState<Game | undefined>(undefined);
const { t } = useTranslation();
Expand Down Expand Up @@ -67,6 +77,13 @@ const Component = ({ className }: Props): React.ReactElement => {
};
}, [exitGame]);

const onOpenShop = useCallback((gameId?: number) => {
return () => {
setCurrentGameShopId(gameId);
activeModal(shopModalId);
};
}, [activeModal]);

useEffect(() => {
const accountSub = apiSDK.subscribeAccount().subscribe((data) => {
setAccount(data);
Expand All @@ -76,9 +93,24 @@ const Component = ({ className }: Props): React.ReactElement => {
setGameList(data);
});

const energyConfigSub = apiSDK.subscribeEnergyConfig().subscribe((data) => {
setEnergyConfig(data);
});

const gameItemMapSub = apiSDK.subscribeGameItemMap().subscribe((data) => {
setGameItemMap(data);
});

const gameInventoryItemListSub = apiSDK.subscribeGameInventoryItemList().subscribe((data) => {
setGameInventoryItemList(data);
});

return () => {
accountSub.unsubscribe();
energyConfigSub.unsubscribe();
gameListSub.unsubscribe();
gameItemMapSub.unsubscribe();
gameInventoryItemListSub.unsubscribe();
};
}, []);

Expand All @@ -92,8 +124,21 @@ const Component = ({ className }: Props): React.ReactElement => {
/>
<GameEnergy
energy={account.attributes.energy}
maxEnergy={energyConfig?.maxEnergy}
startTime={account.attributes.lastEnergyUpdated}
/>

<Button
icon={(
<Icon
phosphorIcon={ShoppingBag}
size='md'
/>
)}
onClick={onOpenShop()}
size='xs'
type='ghost'
/>
</div>}
{gameList.map((game) => (<div
className={CN('game-item', { 'coming-soon': checkComingSoon(game) })}
Expand Down Expand Up @@ -131,13 +176,28 @@ const Component = ({ className }: Props): React.ReactElement => {
</Typography.Title>
</div>
<div className={'play-area'}>
<Button
className={'play-button'}
onClick={playGame(game)}
size={'xs'}
>
{t('Open')}
</Button>
<div>
<Button
icon={(
<Icon
phosphorIcon={ShoppingBag}
size='md'
/>
)}
onClick={onOpenShop(game.id)}
size='xs'
type='ghost'
/>

<Button
className={'play-button'}
onClick={playGame(game)}
size={'xs'}
>
{t('Open')}
</Button>
</div>

<Typography.Text
className={'game-energy'}
size={'sm'}
Expand All @@ -156,6 +216,13 @@ const Component = ({ className }: Props): React.ReactElement => {
src={currentGame.url}
/>
</div>}

<ShopModal
energyConfig={energyConfig}
gameId={currentGameShopId}
gameInventoryItemList={gameInventoryItemList}
gameItemMap={gameItemMap}
/>
</div>;
};

Expand Down
Loading

0 comments on commit 1ff54f3

Please sign in to comment.