Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/koni/dev/issue-miss…
Browse files Browse the repository at this point in the history
…ion-center' into telegram-dev-01
  • Loading branch information
khanhpv5 committed May 16, 2024
2 parents 657ae6e + 0f86df9 commit 148cd12
Show file tree
Hide file tree
Showing 26 changed files with 1,328 additions and 246 deletions.
10 changes: 9 additions & 1 deletion packages/extension-base/src/background/KoniTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,15 @@ export type RequestSubscribeStaking = null
export type RequestSubscribeStakingReward = null

export enum ThemeNames {
LIGHT = 'light'
DEFAULT = 'default',
SKY = 'sky',
MORNING_SUNNY = 'morning_sunny',
SPRING = 'spring',
LAVENDER = 'lavender',
SUNNY = 'sunny',
BEGIE = 'begie',
CLOVE = 'clove',
AURORA = 'aurora',
}

export enum NETWORK_ERROR {
Expand Down
14 changes: 2 additions & 12 deletions packages/extension-base/src/koni/background/handlers/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from
import { EvmProviderError } from '@subwallet/extension-base/background/errors/EvmProviderError';
import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
import { isSubscriptionRunning, unsubscribe } from '@subwallet/extension-base/background/handlers/subscriptions';
import { AccountRefMap, AddTokenRequestExternal, AmountData, APIItemState, ApiMap, AuthRequestV2, BasicTxErrorType, ChainStakingMetadata, ChainType, ConfirmationsQueue, CrowdloanItem, CrowdloanJson, CurrentAccountInfo, EvmProviderErrorType, EvmSendTransactionParams, EvmSendTransactionRequest, EvmSignatureRequest, ExternalRequestPromise, ExternalRequestPromiseStatus, ExtrinsicType, MantaAuthorizationContext, MantaPayConfig, MantaPaySyncState, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestCrowdloanContributions, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCheckPublicAndSecretKey, ServiceInfo, SingleModeJson, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
import { AccountRefMap, AddTokenRequestExternal, AmountData, APIItemState, ApiMap, AuthRequestV2, BasicTxErrorType, ChainStakingMetadata, ChainType, ConfirmationsQueue, CrowdloanItem, CrowdloanJson, CurrentAccountInfo, EvmProviderErrorType, EvmSendTransactionParams, EvmSendTransactionRequest, EvmSignatureRequest, ExternalRequestPromise, ExternalRequestPromiseStatus, ExtrinsicType, MantaAuthorizationContext, MantaPayConfig, MantaPaySyncState, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestCrowdloanContributions, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCheckPublicAndSecretKey, ServiceInfo, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
import { AccountJson, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning } from '@subwallet/extension-base/background/types';
import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH, MANTA_PAY_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
import BuyService from '@subwallet/extension-base/services/buy-service';
import CampaignService from '@subwallet/extension-base/services/campaign-service';
import { ChainService } from '@subwallet/extension-base/services/chain-service';
import { _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _PREDEFINED_SINGLE_MODES } from '@subwallet/extension-base/services/chain-service/constants';
import { _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
import { _ChainState, _NetworkUpsertParams, _ValidateCustomAssetRequest } from '@subwallet/extension-base/services/chain-service/types';
import { _getEvmChainId, _getSubstrateGenesisHash, _getTokenOnChainAssetId, _isAssetFungibleToken, _isChainEnabled, _isChainTestNet, _parseMetadataForSmartContractAsset } from '@subwallet/extension-base/services/chain-service/utils';
import { EventService } from '@subwallet/extension-base/services/event-service';
Expand Down Expand Up @@ -1242,16 +1242,6 @@ export default class KoniState {
}
}

findSingleMode (genesisHash: string): SingleModeJson | undefined {
const [networkKey] = this.findNetworkKeyByGenesisHash(genesisHash);

if (!networkKey) {
return undefined;
}

return (Object.values(_PREDEFINED_SINGLE_MODES)).find((item) => (item.networkKeys.includes(networkKey)));
}

public accountExportPrivateKey ({ address,
password }: RequestAccountExportPrivateKey): ResponseAccountExportPrivateKey {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import { _DEFAULT_CHAINS } from '@subwallet/chain-list';
import { _SubstrateChainType } from '@subwallet/chain-list/types';
import { SingleModeJson, ThemeNames } from '@subwallet/extension-base/background/KoniTypes';

export const API_AUTO_CONNECT_MS = 3000;
export const API_CONNECT_TIMEOUT = 30000;
Expand All @@ -16,14 +15,6 @@ export const _API_OPTIONS_CHAIN_GROUP = {
goldberg: ['goldberg_testnet']
};

export const _PREDEFINED_SINGLE_MODES: Record<string, SingleModeJson> = {
subspace: {
networkKeys: ['subspace_gemini_2a', 'subspace_test', 'subspace_gemini_3a'],
theme: ThemeNames.LIGHT,
autoTriggerDomain: 'subspace.network'
}
};

export const _PURE_EVM_CHAINS = ['binance', 'binance_test', 'ethereum', 'ethereum_goerli', 'astarEvm', 'shidenEvm', 'shibuyaEvm', 'crabEvm', 'pangolinEvm', 'cloverEvm', 'boba_rinkeby', 'boba', 'bobabase', 'bobabeam', 'watr_network_evm'];

// Get balance----------------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { BrowserConfirmationType, LanguageType, ThemeNames, UiSettings, WalletUnlockType } from '@subwallet/extension-base/background/KoniTypes';
import { TARGET_ENV } from '@subwallet/extension-base/utils';

export const DEFAULT_THEME: ThemeNames = ThemeNames.LIGHT;
export const DEFAULT_THEME: ThemeNames = ThemeNames.DEFAULT;
export const DEFAULT_NOTIFICATION_TYPE: BrowserConfirmationType = 'popup';
export const DEFAULT_AUTO_LOCK_TIME = 15;
export const DEFAULT_UNLOCK_TYPE: WalletUnlockType = TARGET_ENV === 'extension' ? WalletUnlockType.ALWAYS_REQUIRED : WalletUnlockType.WHEN_NEEDED;
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
103 changes: 103 additions & 0 deletions packages/extension-koni-ui/src/Popup/Home/Mission/TaskCategoryList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright 2019-2022 @subwallet/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { TaskCategory, TaskCategoryInfo } from '@subwallet/extension-koni-ui/connector/booka/types';
import { useTranslation } from '@subwallet/extension-koni-ui/hooks';
import { ThemeProps } from '@subwallet/extension-koni-ui/types';
import { formatInteger } from '@subwallet/extension-koni-ui/utils';
import { Icon, Image, Typography } from '@subwallet/react-ui';
import { CaretRight } from 'phosphor-react';
import React, { useCallback, useMemo } from 'react';
import styled from 'styled-components';

type Props = ThemeProps & {
taskCategoryList: TaskCategory[];
taskCategoryInfoMap: Record<number, TaskCategoryInfo>;
onClickCategoryItem: (categoryId: number) => void;
};

const Component = ({ className, onClickCategoryItem, taskCategoryInfoMap, taskCategoryList }: Props): React.ReactElement => {
const { t } = useTranslation();

const filteredTaskCategoryList = useMemo(() => {
return taskCategoryList.filter((tc) => {
return taskCategoryInfoMap[tc.id] && taskCategoryInfoMap[tc.id].tasks.length;
});
}, [taskCategoryInfoMap, taskCategoryList]);

const onClickItem = useCallback((categoryId: number) => {
return () => {
onClickCategoryItem(categoryId);
};
}, [onClickCategoryItem]);

return (
<div className={className}>
<Typography.Title level={4}>
{t('Categories')}
</Typography.Title>

{
filteredTaskCategoryList.map((tc) => (
<div
className={'task-category-item'}
key={tc.id}
onClick={onClickItem(tc.id)}
>
<Image
className={'task-category-banner'}
src={tc.icon || undefined}
width={40}
></Image>
<div className={'task-category-item-content'}>
<div>{tc.name}</div>

<div>
Min point can earn: {formatInteger(taskCategoryInfoMap[tc.id]?.minPoint || 0)}
</div>
</div>
<div className={'task-category-item-caret-icon'}>
<Icon
customSize={'20px'}
phosphorIcon={CaretRight}
/>
</div>
</div>
))
}
</div>
);
};

export const TaskCategoryList = styled(Component)<ThemeProps>(({ theme: { extendToken, token } }: ThemeProps) => {
return {
'.task-category-banner': {
marginRight: token.marginSM
},

'.task-category-item': {
display: 'flex',
backgroundColor: token.colorBgSecondary,
minHeight: 50,
borderRadius: token.borderRadiusLG,
padding: token.padding,
cursor: 'pointer',
alignItems: 'center'
},

'.task-category-item-content': {
flex: 1
},

'.task-category-item-caret-icon': {
minWidth: 40,
marginRight: -token.marginXS,
display: 'flex',
justifyContent: 'center'
},

'.task-category-item + .task-category-item': {
marginTop: token.marginXS
}
};
});
Loading

0 comments on commit 148cd12

Please sign in to comment.