Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/webapp-dev' into koni/dev/issue-…
Browse files Browse the repository at this point in the history
…2086
  • Loading branch information
lw-cdm committed Oct 31, 2023
2 parents 0e5cdd8 + 0695b92 commit f73ff8d
Show file tree
Hide file tree
Showing 29 changed files with 159 additions and 51 deletions.
1 change: 1 addition & 0 deletions .github/workflows/push-koni-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
PR_NUMBER: ${{ github.event.number }}
TARGET_BRANCH: ${{ github.event.pull_request.base.ref }}
CURRENT_BRANCH: ${{ github.event.pull_request.head.ref || github.ref }}
BRANCH_NAME: ${{ github.ref_name }}
run: |
yarn install --immutable | grep -v 'YN0013'
yarn build:koni-dev
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/push-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
TRANSAK_API_KEY: ${{ secrets.TRANSAK_API_KEY }}
COINBASE_PAY_ID: ${{ secrets.COINBASE_PAY_ID }}
BRANCH_NAME: ${{ github.ref_name }}
run: |
yarn install --immutable | grep -v 'YN0013'
yarn ${{ matrix.step }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/push-webapp-yield.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
TRANSAK_API_KEY: ${{ secrets.TRANSAK_API_KEY }}
COINBASE_PAY_ID: ${{ secrets.COINBASE_PAY_ID }}
NFT_MINTING_HOST: ${{ secrets.NFT_MINTING_HOST }}
BRANCH_NAME: ${{ github.ref_name }}
run: |
yarn webapp:build
- name: Publish to Cloudflare Pages
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/push-webapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
TRANSAK_API_KEY: ${{ secrets.TRANSAK_API_KEY }}
COINBASE_PAY_ID: ${{ secrets.COINBASE_PAY_ID }}
NFT_MINTING_HOST: ${{ secrets.NFT_MINTING_HOST }}
BRANCH_NAME: ${{ github.ref_name }}
run: |
yarn install --immutable | grep -v 'YN0013'
yarn webapp:build
Expand Down
7 changes: 2 additions & 5 deletions packages/extension-base/src/koni/api/dotsama/crowdloan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ACALA_REFRESH_CROWDLOAN_INTERVAL } from '@subwallet/extension-base/cons
import registry from '@subwallet/extension-base/koni/api/dotsama/typeRegistry';
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
import { categoryAddresses, reformatAddress } from '@subwallet/extension-base/utils';
import { fetchStaticData } from '@subwallet/extension-base/utils/fetchStaticData';
import axios from 'axios';

import { DeriveOwnContributions } from '@polkadot/api-derive/types';
Expand All @@ -24,11 +25,7 @@ export type CrowdloanFundInfo = _CrowdloanFund & {
chain: string;
}

const getOnlineFundList = (async () => {
const request = await axios.get<CrowdloanFundInfo[]>('https://static-data.subwallet.app/crowdloan-funds/list.json');

return request.data;
})();
const getOnlineFundList = fetchStaticData<CrowdloanFundInfo[]>('crowdloan-funds');

function getRPCCrowdloan (parentAPI: _SubstrateApi, fundInfo: _CrowdloanFund, hexAddresses: string[], callback: (rs: CrowdloanItem) => void) {
const { auctionIndex, endTime, firstPeriod, fundId, lastPeriod, paraId, startTime, status } = fundInfo;
Expand Down
2 changes: 2 additions & 0 deletions packages/extension-base/src/koni/api/nft/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export const IPFS_GATEWAY_4EVERLAND = 'https://4everland.io/ipfs/';

export const IPFS_FLEEK = 'https://ipfs.fleek.co/ipfs/';

export const SUBWALLET_IPFS = 'https://ipfs.subwallet.app/ipfs/'; // ???

export enum SUPPORTED_NFT_NETWORKS {
karura = 'karura',
acala = 'acala',
Expand Down
28 changes: 28 additions & 0 deletions packages/extension-base/src/koni/api/yield/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,5 +271,33 @@ export const YIELD_POOLS_INFO: Record<string, YieldPoolInfo> = {
waitingTime: 0 // 0 means immediately
}
]
},
xcDOT___stellaswap_liquid_staking: {
slug: 'xcDOT___stellaswap_liquid_staking',
chain: 'moonbeam',
name: 'stDOT Staking',
logo: 'stellaswap',
description: 'Earn rewards by staking xcDOT for stDOT',
type: YieldPoolType.LIQUID_STAKING,
inputAssets: [
'moonbeam-LOCAL-xcDOT'
],
derivativeAssets: [
'moonbeam-LOCAL-stDOT' // TODO: add to chain-list
],
rewardAssets: [
'moonbeam-LOCAL-xcDOT'
],
feeAssets: [
'moonbeam-NATIVE-GLMR'
],
altInputAssets: [],
withdrawalMethods: [
{
name: 'Default withdrawal',
description: 'Withdraw your DOT',
waitingTime: 0 // 0 means immediately
}
]
}
};
17 changes: 11 additions & 6 deletions packages/extension-base/src/koni/api/yield/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import { TransactionError } from '@subwallet/extension-base/background/errors/Tr
import { BasicTxErrorType, ChainStakingMetadata, ExtrinsicType, OptimalYieldPath, OptimalYieldPathParams, RequestBondingSubmit, RequestStakePoolingBonding, RequestYieldStepSubmit, StakingType, SubmitJoinNativeStaking, SubmitJoinNominationPool, SubmitYieldStepData, YieldAssetExpectedEarning, YieldCompoundingPeriod, YieldPoolInfo, YieldPoolType, YieldPositionInfo, YieldProcessValidation, YieldStepType, YieldValidationStatus } from '@subwallet/extension-base/background/KoniTypes';
import { validatePoolBondingCondition, validateRelayBondingCondition } from '@subwallet/extension-base/koni/api/staking/bonding/relayChain';
import { createXcmExtrinsic } from '@subwallet/extension-base/koni/api/xcm';
import { getAcalaLiquidStakingExtrinsic, getAcalaLiquidStakingPosition, getAcalaLiquidStakingRedeem, subscribeAcalaLcDOTLiquidStakingStats, subscribeAcalaLiquidStakingStats } from '@subwallet/extension-base/koni/api/yield/acalaLiquidStaking';
import { getBifrostLiquidStakingExtrinsic, getBifrostLiquidStakingPosition, getBifrostLiquidStakingRedeem, subscribeBifrostLiquidStakingStats } from '@subwallet/extension-base/koni/api/yield/bifrostLiquidStaking';
import { getAcalaLiquidStakingExtrinsic, getAcalaLiquidStakingPosition, getAcalaLiquidStakingRedeem, subscribeAcalaLcDOTLiquidStakingStats, subscribeAcalaLiquidStakingStats } from '@subwallet/extension-base/koni/api/yield/acala-liquid-staking';
import { getBifrostLiquidStakingExtrinsic, getBifrostLiquidStakingPosition, getBifrostLiquidStakingRedeem, subscribeBifrostLiquidStakingStats } from '@subwallet/extension-base/koni/api/yield/bifrost-liquid-staking';
import { YIELD_POOLS_INFO } from '@subwallet/extension-base/koni/api/yield/data';
import { DEFAULT_YIELD_FIRST_STEP, fakeAddress, RuntimeDispatchInfo } from '@subwallet/extension-base/koni/api/yield/helper/utils';
import { getInterlayLendingExtrinsic, getInterlayLendingPosition, getInterlayLendingRedeem, subscribeInterlayLendingStats } from '@subwallet/extension-base/koni/api/yield/interlayLending';
import { subscribeMoonwellLendingStats } from '@subwallet/extension-base/koni/api/yield/moonwellLending';
import { generatePathForNativeStaking, getNativeStakingBondExtrinsic, getNativeStakingPosition, getNominationPoolJoinExtrinsic, getNominationPoolPosition, subscribeNativeStakingYieldStats } from '@subwallet/extension-base/koni/api/yield/nativeStaking';
import { getParallelLiquidStakingExtrinsic, getParallelLiquidStakingPosition, getParallelLiquidStakingRedeem, subscribeParallelLiquidStakingStats } from '@subwallet/extension-base/koni/api/yield/parallelLiquidStaking';
import { getInterlayLendingExtrinsic, getInterlayLendingPosition, getInterlayLendingRedeem, subscribeInterlayLendingStats } from '@subwallet/extension-base/koni/api/yield/interlay-lending';
import { subscribeMoonwellLendingStats } from '@subwallet/extension-base/koni/api/yield/moonwell-lending';
import { generatePathForNativeStaking, getNativeStakingBondExtrinsic, getNativeStakingPosition, getNominationPoolJoinExtrinsic, getNominationPoolPosition, subscribeNativeStakingYieldStats } from '@subwallet/extension-base/koni/api/yield/native-staking';
import { getParallelLiquidStakingExtrinsic, getParallelLiquidStakingPosition, getParallelLiquidStakingRedeem, subscribeParallelLiquidStakingStats } from '@subwallet/extension-base/koni/api/yield/parallel-liquid-staking';
import { subscribestDOTLiquidStakingStats } from '@subwallet/extension-base/koni/api/yield/stDOT-staking';
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
import { SubstrateApi } from '@subwallet/extension-base/services/chain-service/handler/SubstrateApi';
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
Expand Down Expand Up @@ -64,6 +65,10 @@ export function subscribeYieldPoolStats (substrateApiMap: Record<string, _Substr
} else if (poolInfo.slug === 'xcDOT___moonwell_lending') {
const unsub = subscribeMoonwellLendingStats(substrateApi, chainInfoMap, poolInfo, callback);

unsubList.push(unsub);
} else if (poolInfo.slug === 'xcDOT___stellaswap_liquid_staking') {
const unsub = subscribestDOTLiquidStakingStats(substrateApi, chainInfoMap, poolInfo, callback);

unsubList.push(unsub);
}
}
Expand Down
44 changes: 44 additions & 0 deletions packages/extension-base/src/koni/api/yield/stDOT-staking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2019-2022 @subwallet/extension-base
// SPDX-License-Identifier: Apache-2.0

import { _ChainInfo } from '@subwallet/chain-list/types';
import { YieldPoolInfo } from '@subwallet/extension-base/background/KoniTypes';
import { YIELD_POOL_STAT_REFRESH_INTERVAL } from '@subwallet/extension-base/koni/api/yield/helper/utils';
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';

export function subscribestDOTLiquidStakingStats (chainApi: _SubstrateApi, chainInfoMap: Record<string, _ChainInfo>, poolInfo: YieldPoolInfo, callback: (rs: YieldPoolInfo) => void) {
function getPoolStat () {
// eslint-disable-next-line node/no-callback-literal
callback({
...poolInfo,
stats: {
isAvailable: false,
assetEarning: [
{
slug: poolInfo.rewardAssets[0],
apr: -1,
exchangeRate: -1
}
],
maxCandidatePerFarmer: 1,
maxWithdrawalRequestPerFarmer: 1,
minJoinPool: '50000000000',
minWithdrawal: '0',
totalApr: -1,
tvl: '0'
}
});
}

function getStatInterval () {
getPoolStat();
}

getStatInterval();

const interval = setInterval(getStatInterval, YIELD_POOL_STAT_REFRESH_INTERVAL);

return () => {
clearInterval(interval);
};
}
2 changes: 1 addition & 1 deletion packages/extension-base/src/koni/api/yield/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { ChainAssetMap, ChainInfoMap } from '@subwallet/chain-list';
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
import { OptimalYieldPath, YieldPoolInfo, YieldStepType } from '@subwallet/extension-base/background/KoniTypes';
import { BifrostLiquidStakingMeta } from '@subwallet/extension-base/koni/api/yield/bifrostLiquidStaking';
import { BifrostLiquidStakingMeta } from '@subwallet/extension-base/koni/api/yield/bifrost-liquid-staking';
import { YIELD_POOLS_INFO } from '@subwallet/extension-base/koni/api/yield/data';
import { DEFAULT_YIELD_FIRST_STEP } from '@subwallet/extension-base/koni/api/yield/helper/utils';
import fetch from 'cross-fetch';
Expand Down
15 changes: 15 additions & 0 deletions packages/extension-base/src/utils/fetchStaticData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2019-2022 @subwallet/extension-base
// SPDX-License-Identifier: Apache-2.0

import axios from 'axios';

const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
const branchName = process.env.BRANCH_NAME || 'koni-dev';
const fetchTarget = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'list.json' : 'preview.json';

export async function fetchStaticData<T> (slug: string, targetFile?: string) {
const fetchFile = targetFile || fetchTarget;
const rs = await axios.get(`https://static-data.subwallet.app/${slug}/${fetchFile}`);

return rs.data as T;
}
30 changes: 29 additions & 1 deletion packages/extension-base/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { CrowdloanParaState, MobileOS, NetworkJson } from '@subwallet/extension-base/background/KoniTypes';
import { AccountAuthType, AccountJson } from '@subwallet/extension-base/background/types';
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
import { getRandomIpfsGateway } from '@subwallet/extension-base/koni/api/nft/config';
import { getRandomIpfsGateway, SUBWALLET_IPFS } from '@subwallet/extension-base/koni/api/nft/config';
import { getOS } from '@subwallet/extension-base/utils/environment';
import { t } from 'i18next';

Expand Down Expand Up @@ -385,6 +385,34 @@ export const baseParseIPFSUrl = (input: string): string | undefined => {
return getRandomIpfsGateway() + input.split('ipfs://ipfs/')[1]; // starts with ipfs://ipfs/
};

export const swParseIPFSUrl = (input: string): string | undefined => {
if (!input || input.length === 0) {
return undefined;
}

if (isUrl(input)) {
return input;
}

if (isUrl(input) || input.includes('https://') || input.includes('http')) {
return input;
}

if (input.startsWith('/ipfs/')) {
return SUBWALLET_IPFS + input.split('/ipfs/')[1];
}

if (!input.includes('ipfs://') && !input.includes('ipfs://ipfs/')) { // just the IPFS hash
return SUBWALLET_IPFS + input;
}

if (input.includes('ipfs://') && !input.includes('ipfs://ipfs/')) { // starts with ipfs://
return SUBWALLET_IPFS + input.split('ipfs://')[1];
}

return SUBWALLET_IPFS + input.split('ipfs://ipfs/')[1]; // starts with ipfs://ipfs/
};

export * from './array';
export * from './environment';
export * from './number';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// SPDX-License-Identifier: Apache-2.0

import { _ChainInfo } from '@subwallet/chain-list/types';
import { fetchStaticData } from '@subwallet/extension-base/utils/fetchStaticData';
import { PageWrapper } from '@subwallet/extension-koni-ui/components';
import { CROWDLOAN_UNLOCK_TIME } from '@subwallet/extension-koni-ui/constants';
import { DEFAULT_CROWDLOAN_UNLOCK_TIME } from '@subwallet/extension-koni-ui/constants/event';
import { DataContext } from '@subwallet/extension-koni-ui/contexts/DataContext';
import { updateLogoMaps } from '@subwallet/extension-koni-ui/stores/utils';
import { CrowdloanFundInfo, ThemeProps } from '@subwallet/extension-koni-ui/types';
import CN from 'classnames';
import fetch from 'cross-fetch';
import React, { useContext, useEffect, useState } from 'react';
import { Outlet } from 'react-router-dom';
import styled from 'styled-components';
Expand Down Expand Up @@ -68,21 +68,9 @@ const Component: React.FC<Props> = (props: Props) => {

useEffect(() => {
Promise.all([
(async () => {
const res = await fetch('https://static-data.subwallet.app/crowdloan-funds/list.json');

return await res.json() as CrowdloanFundInfo[];
})(),
(async () => {
const res = await fetch('https://static-data.subwallet.app/chains/preview.json');

return await res.json() as _ChainInfo[];
})(),
(async () => {
const res = await fetch('https://static-data.subwallet.app/events/period-time.json');

return await res.json() as PeriodTimeInfo;
})()
fetchStaticData<CrowdloanFundInfo[]>('crowdloan-funds'),
fetchStaticData<_ChainInfo[]>('chains'),
fetchStaticData<PeriodTimeInfo>('events', 'period-time.json')
]).then(([crowdloanFunds, chainInfoItems, periodTimeInfo]) => {
setCrowdloanFundInfoMap(crowdloanFundsToMap(crowdloanFunds));
setChainInfoMap(chainInfoItemsToMap(chainInfoItems));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { YieldPoolType } from '@subwallet/extension-base/background/KoniTypes';
import { baseParseIPFSUrl, detectTranslate } from '@subwallet/extension-base/utils';
import { detectTranslate, swParseIPFSUrl } from '@subwallet/extension-base/utils';
import { ImageSlash } from '@subwallet/extension-koni-ui/components';
import { ScreenContext } from '@subwallet/extension-koni-ui/contexts/ScreenContext';
import { useSelector, useTranslation } from '@subwallet/extension-koni-ui/hooks';
Expand Down Expand Up @@ -36,6 +36,10 @@ const Component: React.FC<Props> = (props: Props) => {

const pool = useMemo(() => Object.values(poolInfo).find((value) => value.chain === chain), [chain, poolInfo]);

const imageUrl = useMemo(() => {
return swParseIPFSUrl(url);
}, [url]);

const [imageDone, setImageDone] = useState(false);

const onImageLoad = useCallback(() => {
Expand Down Expand Up @@ -94,7 +98,7 @@ const Component: React.FC<Props> = (props: Props) => {
height={300}
onLoad={onImageLoad}
shape='default'
src={baseParseIPFSUrl(url)}
src={imageUrl}
width={300}
/>
)
Expand Down
1 change: 1 addition & 0 deletions packages/extension-koni-ui/src/assets/logo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const DefaultLogosMap: Record<string, string> = {
peaq: '/images/projects/peaq.jpg',
t3rn: '/images/projects/t3rn.png',
moonwell: '/images/projects/moonwell-apollo.png',
stellaswap: '/images/projects/stellaswap.png',
subwallet_gradient: '/images/projects/subwallet-gradient.png',
subwallet_mc: '/images/projects/subwallet-monochrome.svg',
polkadot_js: '/images/projects/polkadot-js.png',
Expand Down
3 changes: 2 additions & 1 deletion packages/extension-koni-ui/src/assets/subwallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const SwLogosMap: Record<string, string> = {
coinversation: DefaultLogosMap.coinversation,
peaq: DefaultLogosMap.peaq,
t3rn: DefaultLogosMap.t3rn,
moonwell: DefaultLogosMap.moonwell
moonwell: DefaultLogosMap.moonwell,
stellaswap: DefaultLogosMap.stellaswap
};

export default SwLogosMap;
2 changes: 1 addition & 1 deletion packages/extension-koni-ui/src/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export const TELEGRAM_URL = 'https://t.me/subwallet';
export const TWITTER_URL = 'https://twitter.com/subwalletapp';
export const DISCORD_URL = 'https://discord.com/invite/vPCN4vdB8v';
export const EXTENSION_URL = 'https://subwallet.app/download.html';
export const CONTACT_US = 'mailto:agent@subwallet.app';
export const CONTACT_US = 'https://t.me/subwallet';
export const ALL_KEY = 'all';
export const HELP_URL = 'https://docs.subwallet.app/main/';
20 changes: 4 additions & 16 deletions packages/extension-koni-ui/src/stores/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import { _ChainState } from '@subwallet/extension-base/services/chain-service/ty
import { SWTransactionResult } from '@subwallet/extension-base/services/transaction-service/types';
import { WalletConnectNotSupportRequest, WalletConnectSessionRequest } from '@subwallet/extension-base/services/wallet-connect-service/types';
import { addLazy, canDerive, isEmptyObject } from '@subwallet/extension-base/utils';
import { fetchStaticData } from '@subwallet/extension-base/utils/fetchStaticData';
import { lazySendMessage, lazySubscribeMessage } from '@subwallet/extension-koni-ui/messaging';
import { store } from '@subwallet/extension-koni-ui/stores';
import { DAppCategory, DAppInfo } from '@subwallet/extension-koni-ui/types/dapp';
import { MissionInfo } from '@subwallet/extension-koni-ui/types/missionPool';
import { noop, noopBoolean } from '@subwallet/extension-koni-ui/utils';
import { buildHierarchy } from '@subwallet/extension-koni-ui/utils/account/buildHierarchy';
import { SessionTypes } from '@walletconnect/types';
import fetch from 'cross-fetch';

// Setup redux stores

Expand Down Expand Up @@ -342,16 +342,8 @@ export const getDAppsData = (() => {
promise,
start: () => {
Promise.all([
(async () => {
const res = await fetch('https://static-data.subwallet.app/dapps/list.json');

return await res.json() as [];
})(),
(async () => {
const res = await fetch('https://static-data.subwallet.app/categories/list.json');

return await res.json() as [];
})()
fetchStaticData<DAppInfo[]>('dapps'),
fetchStaticData<DAppCategory[]>('categories')
])
.then((data) => {
handler.resolve?.(data);
Expand Down Expand Up @@ -388,11 +380,7 @@ export const getMissionPoolData = (() => {
const rs = {
promise,
start: () => {
(async () => {
const res = await fetch('https://static-data.subwallet.app/airdrop-campaigns/list.json');

return await res.json() as [];
})()
fetchStaticData<MissionInfo[]>('airdrop-campaigns')
.then((data) => {
handler.resolve?.(data);
})
Expand Down
1 change: 1 addition & 0 deletions packages/extension-koni/webpack.shared.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ module.exports = (entry, alias = {}, useSplitChunk = false) => {
PKG_NAME: JSON.stringify(pkgJson.name),
PKG_VERSION: JSON.stringify(pkgJson.version),
TARGET_ENV: JSON.stringify('extension'),
BRANCH_NAME: JSON.stringify(process.env.BRANCH_NAME),
ID_PREDIX: JSON.stringify('sw-ext-'),
...additionalEnv
}
Expand Down
Loading

0 comments on commit f73ff8d

Please sign in to comment.