finish: fix types
This commit is contained in:
parent
d49839b3e4
commit
997ebcea78
15 changed files with 461 additions and 263 deletions
|
|
@ -30,7 +30,9 @@
|
|||
}
|
||||
],
|
||||
"import/no-unresolved": "off",
|
||||
"import/no-mutable-exports": "off",
|
||||
"no-async-promise-executor": "off",
|
||||
"default-param-last": "off",
|
||||
"no-use-before-define": ["error", { "functions": false, "classes": true, "variables": true }],
|
||||
"func-names": "off",
|
||||
"consistent-return": "off",
|
||||
|
|
|
|||
113
src/app/App.tsx
113
src/app/App.tsx
|
|
@ -45,7 +45,7 @@ import {
|
|||
AcceptSwapReq,
|
||||
AssetWhitelistReq,
|
||||
dispatchType,
|
||||
RequestType,
|
||||
BurnAssetRequestType,
|
||||
SwapRequest,
|
||||
transferType,
|
||||
} from '../types';
|
||||
|
|
@ -82,6 +82,7 @@ function App() {
|
|||
const response = await fetchBackground({
|
||||
method: 'EXECUTE_BRIDGING_TRANSFER',
|
||||
});
|
||||
|
||||
if (response.data.error) {
|
||||
return { sent: false, status: response.data.error };
|
||||
}
|
||||
|
|
@ -129,6 +130,7 @@ function App() {
|
|||
const walletActive = await fetchBackground({
|
||||
method: 'GET_WALLET_DATA',
|
||||
});
|
||||
|
||||
updateWalletConnected(dispatch as dispatchType, !walletActive.error);
|
||||
updateLoading(dispatch as dispatchType, false);
|
||||
};
|
||||
|
|
@ -137,6 +139,7 @@ function App() {
|
|||
if (!chrome?.runtime?.sendMessage) return;
|
||||
|
||||
const walletsList = await fetchBackground({ method: 'GET_WALLETS' });
|
||||
|
||||
if (!walletsList.data) return;
|
||||
updateWalletsList(dispatch as dispatchType, walletsList.data);
|
||||
|
||||
|
|
@ -192,7 +195,7 @@ function App() {
|
|||
|
||||
useEffect(() => {
|
||||
const listener = (
|
||||
request: RequestType,
|
||||
request: BurnAssetRequestType,
|
||||
sender: chrome.runtime.MessageSender,
|
||||
sendResponse: (response: { status: string }) => void,
|
||||
) => {
|
||||
|
|
@ -380,7 +383,11 @@ function App() {
|
|||
const swapPageReqs = swapRequests.map((e: SwapRequest) => {
|
||||
const { swap } = e;
|
||||
|
||||
const swapParams: { address: string } | any = {};
|
||||
const swapParams: {
|
||||
address?: string;
|
||||
receiving?: React.JSX.Element;
|
||||
sending?: React.JSX.Element;
|
||||
} | null = {};
|
||||
|
||||
swapParams.address = swap.destinationAddress;
|
||||
|
||||
|
|
@ -389,13 +396,16 @@ function App() {
|
|||
|
||||
swapParams.receiving = getSwapAmountText(
|
||||
receivingAmount,
|
||||
receivingAsset as any,
|
||||
receivingAsset as unknown as { ticker: string },
|
||||
);
|
||||
|
||||
const sendingAsset = swap.currentAsset;
|
||||
const sendingAmount = new Big(swap.currentAssetAmount);
|
||||
|
||||
swapParams.sending = getSwapAmountText(sendingAmount, sendingAsset as any);
|
||||
swapParams.sending = getSwapAmountText(
|
||||
sendingAmount,
|
||||
sendingAsset as unknown as { ticker: string },
|
||||
);
|
||||
|
||||
return {
|
||||
id: e.id,
|
||||
|
|
@ -433,7 +443,10 @@ function App() {
|
|||
|
||||
const swap = e?.swapProposal;
|
||||
|
||||
const swapParams: { receiving: string } | any = {};
|
||||
const swapParams: {
|
||||
receiving?: React.JSX.Element;
|
||||
sending?: React.JSX.Element;
|
||||
} = {};
|
||||
|
||||
function toBigWithDecimal(amount: Big, decimalPoint: number) {
|
||||
if (amount) {
|
||||
|
|
@ -451,7 +464,7 @@ function App() {
|
|||
if (receivingAmount !== undefined) {
|
||||
swapParams.receiving = getSwapAmountText(
|
||||
receivingAmount,
|
||||
receivingAsset as any,
|
||||
receivingAsset as unknown as { ticker: string },
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -464,7 +477,7 @@ function App() {
|
|||
if (sendingAmount !== undefined) {
|
||||
swapParams.sending = getSwapAmountText(
|
||||
sendingAmount,
|
||||
sendingAsset as any,
|
||||
sendingAsset as unknown as { ticker: string },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -532,7 +545,7 @@ function App() {
|
|||
const response = await fetchBackground({ method: 'GET_BURN_ASSET_REQUESTS' });
|
||||
const burnRequests = response.data;
|
||||
|
||||
const pageReqs = burnRequests.map((e: any) => {
|
||||
const pageReqs = burnRequests.map((e: { burn: unknown; id: string }) => {
|
||||
const data = e.burn;
|
||||
|
||||
return {
|
||||
|
|
@ -569,7 +582,7 @@ function App() {
|
|||
credentials: {
|
||||
token: state.connectCredentials.token,
|
||||
port: state?.connectCredentials?.port || defaultPort,
|
||||
} as any,
|
||||
} as { token: string; port: string },
|
||||
});
|
||||
}
|
||||
}, [state.connectCredentials]);
|
||||
|
|
@ -617,44 +630,50 @@ function App() {
|
|||
{loggedIn && state.isConnected && <Header />}
|
||||
<AppLoader firstWalletLoaded={firstWalletLoaded} loggedIn={loggedIn} />
|
||||
|
||||
{appConnected && !connectOpened ? (
|
||||
loggedIn ? (
|
||||
state.isConnected ? (
|
||||
<div className="container">
|
||||
<Router>
|
||||
<Wallet setConnectOpened={setConnectOpened} />
|
||||
<TokensTabs />
|
||||
</Router>
|
||||
</div>
|
||||
) : (
|
||||
<AppPlug setConnectOpened={setConnectOpened} />
|
||||
)
|
||||
) : (
|
||||
PasswordPages()
|
||||
)
|
||||
) : (
|
||||
<ConnectPage
|
||||
incorrectPassword={incorrectPassword}
|
||||
setIncorrectPassword={setIncorrectPassword}
|
||||
passwordExists={passwordExists()}
|
||||
setConnectOpened={setConnectOpened}
|
||||
onConfirm={async (inputPassword, connectKey, walletPort) => {
|
||||
const password = inputPassword || (await getSessionPassword());
|
||||
|
||||
if (!password) return;
|
||||
setPassword(password);
|
||||
|
||||
if (connectKey)
|
||||
ConnectKeyUtils.setConnectData(
|
||||
connectKey,
|
||||
String(walletPort),
|
||||
password,
|
||||
{(() => {
|
||||
if (appConnected && !connectOpened) {
|
||||
if (loggedIn) {
|
||||
if (state.isConnected) {
|
||||
return (
|
||||
<div className="container">
|
||||
<Router>
|
||||
<Wallet setConnectOpened={setConnectOpened} />
|
||||
<TokensTabs />
|
||||
</Router>
|
||||
</div>
|
||||
);
|
||||
setLoggedIn(true);
|
||||
await setSessionPassword(password);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
}
|
||||
return <AppPlug setConnectOpened={setConnectOpened} />;
|
||||
}
|
||||
return PasswordPages();
|
||||
}
|
||||
|
||||
return (
|
||||
<ConnectPage
|
||||
incorrectPassword={incorrectPassword}
|
||||
setIncorrectPassword={setIncorrectPassword}
|
||||
passwordExists={passwordExists()}
|
||||
setConnectOpened={setConnectOpened}
|
||||
onConfirm={async (inputPassword, connectKey, walletPort) => {
|
||||
const password = inputPassword || (await getSessionPassword());
|
||||
if (!password) return;
|
||||
|
||||
setPassword(password);
|
||||
|
||||
if (connectKey) {
|
||||
ConnectKeyUtils.setConnectData(
|
||||
connectKey,
|
||||
String(walletPort),
|
||||
password,
|
||||
);
|
||||
}
|
||||
|
||||
setLoggedIn(true);
|
||||
await setSessionPassword(password);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
})()}
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -10,9 +10,14 @@ interface ModalConfirmationProps {
|
|||
onConfirm: () => void;
|
||||
}
|
||||
|
||||
interface confirmationModalType {
|
||||
params: string;
|
||||
method: string;
|
||||
}
|
||||
|
||||
const ModalConfirmation = ({ isOpen, onClose, onConfirm }: ModalConfirmationProps) => {
|
||||
const { state } = useContext(Store);
|
||||
const { method, params } = state.confirmationModal || {};
|
||||
const { method, params } = (state.confirmationModal as unknown as confirmationModalType) || {};
|
||||
|
||||
const closeHandler = useCallback(() => {
|
||||
onClose();
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ const OuterConfirmation = () => {
|
|||
const transactionParams = params
|
||||
? Object.fromEntries((params as ParamsType[]).map((item) => [item.key, item.value]))
|
||||
: {};
|
||||
|
||||
const totalAmount = Number(
|
||||
isMultipleDestinations
|
||||
? destinations.reduce(
|
||||
|
|
@ -113,7 +114,7 @@ const OuterConfirmation = () => {
|
|||
<div className={styles.confirmation__block}>
|
||||
<div className={styles.row}>
|
||||
<h5>From</h5>
|
||||
<p>{transactionParams?.F}</p>
|
||||
<p>{transactionParams?.From}</p>
|
||||
</div>
|
||||
<div className={styles.row}>
|
||||
<h5>Asset</h5>
|
||||
|
|
@ -248,12 +249,14 @@ const OuterConfirmation = () => {
|
|||
<h5>Burn Amount</h5>
|
||||
<p>{burnAmount}</p>
|
||||
</div>
|
||||
{nativeAmount && (
|
||||
|
||||
{typeof nativeAmount === 'string' && (
|
||||
<div className={styles.row}>
|
||||
<h5>Native Amount</h5>
|
||||
<p>{nativeAmount}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{pointTxToAddress && (
|
||||
<div className={styles.row}>
|
||||
<h5>Send Tx To</h5>
|
||||
|
|
@ -317,6 +320,7 @@ const OuterConfirmation = () => {
|
|||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className={styles.confirmation__block}>
|
||||
|
|
@ -344,28 +348,27 @@ const OuterConfirmation = () => {
|
|||
<div className={styles.confirmation__content}>{getConfirmationContent()}</div>
|
||||
|
||||
<div className={styles.confirmation__bottom}>
|
||||
{isTransferMethod ||
|
||||
(isBurnMethod && (
|
||||
<>
|
||||
<div className={styles.confirmation__bottom_fee}>
|
||||
<h5>
|
||||
Transaction fee <InfoTooltip title="Total network fee" />
|
||||
</h5>
|
||||
<p>0.01 ZANO</p>
|
||||
</div>
|
||||
{(isTransferMethod || isBurnMethod) && (
|
||||
<>
|
||||
<div className={styles.confirmation__bottom_fee}>
|
||||
<h5>
|
||||
Transaction fee <InfoTooltip title="Total network fee" />
|
||||
</h5>
|
||||
<p>0.01 ZANO</p>
|
||||
</div>
|
||||
|
||||
{isTransferMethod && (
|
||||
<>
|
||||
<div className={styles.divider} />
|
||||
{isTransferMethod && (
|
||||
<>
|
||||
<div className={styles.divider} />
|
||||
|
||||
<div className={styles.confirmation__bottom_total}>
|
||||
<h5>Total</h5>
|
||||
<p>{totalAmount}</p>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
))}
|
||||
<div className={styles.confirmation__bottom_total}>
|
||||
<h5>Total</h5>
|
||||
<p>{totalAmount}</p>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
<div className={styles.confirmation__bottom_buttons}>
|
||||
<Button
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useContext, useEffect, useState } from 'react';
|
||||
import React, { Dispatch, SetStateAction, useContext, useEffect, useState } from 'react';
|
||||
import { popToTop } from 'react-chrome-extension-router';
|
||||
import failedImage from '../../assets/images/failed-round.png';
|
||||
import successImage from '../../assets/images/success-round.png';
|
||||
|
|
@ -28,7 +28,7 @@ interface FetchBackgroundParams {
|
|||
};
|
||||
}
|
||||
|
||||
interface AssetProps {
|
||||
export interface AssetProps {
|
||||
unlockedBalance: number;
|
||||
balance: number;
|
||||
}
|
||||
|
|
@ -63,7 +63,7 @@ const WalletSend = () => {
|
|||
decimalPoint: number,
|
||||
) =>
|
||||
new Promise(async (resolve, reject) => {
|
||||
if (chrome.runtime.sendMessage as any) {
|
||||
try {
|
||||
const response = await fetchBackground({
|
||||
method: 'SEND_TRANSFER',
|
||||
assetId,
|
||||
|
|
@ -80,8 +80,8 @@ const WalletSend = () => {
|
|||
} else {
|
||||
reject(new Error('No data or error received in response.'));
|
||||
}
|
||||
} else {
|
||||
reject(new Error('chrome.runtime.sendMessage is not available.'));
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -151,7 +151,14 @@ const WalletSend = () => {
|
|||
inputData={address as inputDataProps}
|
||||
isValid={!!submitAddress}
|
||||
/>
|
||||
<AssetsSelect value={asset} setValue={setAsset} />
|
||||
|
||||
<AssetsSelect
|
||||
value={asset}
|
||||
setValue={
|
||||
setAsset as Dispatch<SetStateAction<{ name: string }>>
|
||||
}
|
||||
/>
|
||||
|
||||
<MyInput
|
||||
type="number"
|
||||
placeholder="Amount to transfer"
|
||||
|
|
@ -176,7 +183,11 @@ const WalletSend = () => {
|
|||
!submitAddress ||
|
||||
!amount.value ||
|
||||
!amountValid ||
|
||||
!checkAvailableBalance(amount.value, asset)
|
||||
!asset.unlockedBalance ||
|
||||
!checkAvailableBalance(
|
||||
amount.value,
|
||||
asset as AssetProps,
|
||||
)
|
||||
}
|
||||
>
|
||||
Send
|
||||
|
|
@ -203,14 +214,14 @@ const WalletSend = () => {
|
|||
|
||||
<Button
|
||||
onClick={async () => {
|
||||
const transferStatus = await sendTransfer(
|
||||
const transferStatus = (await sendTransfer(
|
||||
submitAddress,
|
||||
amount.value,
|
||||
String(comment.value),
|
||||
String(asset.assetId),
|
||||
Number(asset.decimalPoint),
|
||||
);
|
||||
console.log('transfer status', transferStatus);
|
||||
)) as { result?: { tx_hash: string } };
|
||||
|
||||
if (transferStatus.result) {
|
||||
setTxId(transferStatus.result.tx_hash);
|
||||
setTransactionSuccess(true);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ export function useCensorDigits() {
|
|||
const { state, dispatch } = useContext(Store);
|
||||
|
||||
const changeCensor = () => {
|
||||
updateBalancesHidden(dispatch, (prevState: boolean) => !prevState);
|
||||
updateBalancesHidden(dispatch, !state.isBalancesHidden);
|
||||
};
|
||||
|
||||
const censorValue = (number: number | string): string | number => {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,13 @@
|
|||
import { useContext } from 'react';
|
||||
import { Store } from '../store/store-reducer';
|
||||
|
||||
interface Asset {
|
||||
assetId: string;
|
||||
}
|
||||
|
||||
export default function useGetAsset() {
|
||||
const { state } = useContext(Store);
|
||||
|
||||
function getAssetById(id: string) {
|
||||
return state.wallet.assets.find((asset: Asset | any) => asset.assetId === id);
|
||||
return state.wallet.assets.find(
|
||||
(asset) => asset.assetId !== undefined && asset.assetId === id,
|
||||
);
|
||||
}
|
||||
|
||||
return { getAssetById };
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ export const useValidation = (value: string | number, validations: Validations)
|
|||
|
||||
useEffect(() => {
|
||||
for (const validation in validations) {
|
||||
if (!Object.prototype.hasOwnProperty.call(validations, validation)) continue;
|
||||
switch (validation) {
|
||||
case 'minLength':
|
||||
if (typeof value === 'string' && value.length < validations[validation]!) {
|
||||
|
|
@ -26,14 +27,15 @@ export const useValidation = (value: string | number, validations: Validations)
|
|||
case 'isEmpty':
|
||||
setIsEmpty(!value);
|
||||
break;
|
||||
case 'isAmountCorrect':
|
||||
case 'isAmountCorrect': {
|
||||
const amountCheckResult =
|
||||
typeof value === 'number' &&
|
||||
!isNaN(value) &&
|
||||
!Number.isNaN(value) &&
|
||||
value >= 0.000000000001 &&
|
||||
value <= 1000000000;
|
||||
setAmountCorrectError(!amountCheckResult);
|
||||
break;
|
||||
}
|
||||
case 'customValidation':
|
||||
setInputValid(true);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -79,7 +79,10 @@ export const updateLoading = (dispatch: DispatchFunction, state: WalletState['is
|
|||
payload: state,
|
||||
});
|
||||
|
||||
export const updateBalancesHidden = (dispatch: any, state: any): void =>
|
||||
export const updateBalancesHidden = (
|
||||
dispatch: React.Dispatch<{ type: 'BALANCES_HIDDEN_UPDATED'; payload: boolean }>,
|
||||
state: boolean,
|
||||
): void =>
|
||||
dispatch({
|
||||
type: 'BALANCES_HIDDEN_UPDATED',
|
||||
payload: state,
|
||||
|
|
@ -96,7 +99,7 @@ export const updateConfirmationModal = (
|
|||
|
||||
export const updateTransactionStatus = (
|
||||
dispatch: DispatchFunction,
|
||||
state: WalletState['transactionStatus'] | any,
|
||||
state: WalletState['transactionStatus'] | object,
|
||||
): void =>
|
||||
dispatch({
|
||||
type: 'TRANSACTION_STATUS_UPDATED',
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ interface State {
|
|||
isConnected: boolean | undefined;
|
||||
isBalancesHidden: boolean;
|
||||
priceData: PriceData;
|
||||
confirmationModal: string | null | any;
|
||||
confirmationModal: null | string;
|
||||
transactionStatus: TransactionStatus;
|
||||
connectCredentials: ConnectCredentials;
|
||||
whitelistedAssets: string[];
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@ export const classNames = (
|
|||
cls,
|
||||
...additional.filter(Boolean),
|
||||
...Object.entries(mods)
|
||||
.filter(([className, value]) => Boolean(value))
|
||||
.filter(([_className, value]) => Boolean(value))
|
||||
.map(([classNames]) => classNames),
|
||||
].join(' ');
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ export async function fetchBackground(data: {
|
|||
success?: boolean;
|
||||
credentials?: { port: string };
|
||||
alias?: string;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
}): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* global chrome */
|
||||
import JSONbig from 'json-bigint';
|
||||
import { ZANO_ASSET_ID } from '../constants';
|
||||
import { BurnAssetDataType, ionicSwapType, RequestType, TransferDataType } from '../types/index';
|
||||
import {
|
||||
fetchData,
|
||||
getWalletData,
|
||||
|
|
@ -52,8 +52,8 @@ async function getAsset(assetId: string): Promise<Asset | undefined> {
|
|||
}
|
||||
|
||||
interface PopupRequest {
|
||||
windowId: number;
|
||||
finalizer: (data: unknown) => void;
|
||||
windowId?: number;
|
||||
finalizer?: (data: unknown) => void;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
|
|
@ -68,9 +68,35 @@ interface ErrorMessages {
|
|||
reqNotFound: string;
|
||||
}
|
||||
|
||||
type SavedRequestType =
|
||||
| 'IONIC_SWAP'
|
||||
| 'ACCEPT_IONIC_SWAP'
|
||||
| 'CREATE_ALIAS'
|
||||
| 'TRANSFER'
|
||||
| 'ASSETS_WHITELIST_ADD'
|
||||
| 'BURN_ASSET';
|
||||
|
||||
const savedRequests: Record<
|
||||
| 'IONIC_SWAP'
|
||||
| 'ACCEPT_IONIC_SWAP'
|
||||
| 'CREATE_ALIAS'
|
||||
| 'TRANSFER'
|
||||
| 'ASSETS_WHITELIST_ADD'
|
||||
| 'BURN_ASSET',
|
||||
Record<string, PopupRequest>
|
||||
> = {
|
||||
IONIC_SWAP: {},
|
||||
ACCEPT_IONIC_SWAP: {},
|
||||
CREATE_ALIAS: {},
|
||||
TRANSFER: {},
|
||||
ASSETS_WHITELIST_ADD: {},
|
||||
BURN_ASSET: {},
|
||||
};
|
||||
|
||||
const allPopupIds: number[] = [];
|
||||
class PopupRequestsMethods {
|
||||
static onRequestCreate(
|
||||
requestType: keyof typeof savedRequests,
|
||||
requestType: SavedRequestType,
|
||||
request: { timeout?: number },
|
||||
sendResponse: (response: RequestResponse) => void,
|
||||
reqParams: PopupRequest,
|
||||
|
|
@ -82,11 +108,11 @@ class PopupRequestsMethods {
|
|||
const req = {
|
||||
...reqParams,
|
||||
windowId: requestWindow.id,
|
||||
finalizer: (data: unknown) => sendResponse(data as any),
|
||||
finalizer: (data: unknown) => sendResponse(data as RequestResponse),
|
||||
};
|
||||
|
||||
allPopupIds.push(requestWindow.id as number);
|
||||
(savedRequests[requestType][reqId] as any) = req;
|
||||
savedRequests[requestType][reqId] = req;
|
||||
|
||||
if (typeof request.timeout === 'number') {
|
||||
setTimeout(() => {
|
||||
|
|
@ -121,13 +147,13 @@ class PopupRequestsMethods {
|
|||
const { success } = request;
|
||||
const req = savedRequests[requestType][reqId];
|
||||
|
||||
if (req) {
|
||||
function finalize(data: unknown) {
|
||||
req.finalizer(data);
|
||||
delete savedRequests[requestType][reqId];
|
||||
chrome.windows.remove(req.windowId);
|
||||
}
|
||||
function finalize(data: unknown) {
|
||||
if (req.finalizer) req.finalizer(data);
|
||||
delete savedRequests[requestType][reqId];
|
||||
if (req.windowId) chrome.windows.remove(req.windowId);
|
||||
}
|
||||
|
||||
if (req) {
|
||||
if (!success) {
|
||||
finalize({ error: 'Request denied by user' });
|
||||
sendResponse({ data: true });
|
||||
|
|
@ -228,26 +254,11 @@ interface SignReqFinalizer {
|
|||
}
|
||||
|
||||
const signReqFinalizers: SignReqFinalizer = {};
|
||||
const signReqs: unknown[] = [];
|
||||
|
||||
const savedRequests: Record<
|
||||
| 'IONIC_SWAP'
|
||||
| 'ACCEPT_IONIC_SWAP'
|
||||
| 'CREATE_ALIAS'
|
||||
| 'TRANSFER'
|
||||
| 'ASSETS_WHITELIST_ADD'
|
||||
| 'BURN_ASSET',
|
||||
Record<string, PopupRequest>
|
||||
> = {
|
||||
IONIC_SWAP: {},
|
||||
ACCEPT_IONIC_SWAP: {},
|
||||
CREATE_ALIAS: {},
|
||||
TRANSFER: {},
|
||||
ASSETS_WHITELIST_ADD: {},
|
||||
BURN_ASSET: {},
|
||||
};
|
||||
|
||||
const allPopupIds: number[] = [];
|
||||
const signReqs: {
|
||||
id: string;
|
||||
windowId: number;
|
||||
message: string;
|
||||
}[] = [];
|
||||
|
||||
chrome.storage.local.get('pendingTx', (result) => {
|
||||
if (result.pendingTx) {
|
||||
|
|
@ -289,62 +300,22 @@ const SELF_ONLY_REQUESTS = [
|
|||
'GET_BURN_ASSET_REQUESTS',
|
||||
'FINALIZE_BURN_ASSET_REQUEST',
|
||||
];
|
||||
|
||||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
processRequest(request, sender as any, sendResponse);
|
||||
return true;
|
||||
});
|
||||
|
||||
interface RequestType {
|
||||
method: string;
|
||||
credentials: Object;
|
||||
id: string;
|
||||
assetId: string;
|
||||
destination: string;
|
||||
amount: string;
|
||||
decimalPoint: string;
|
||||
success: boolean;
|
||||
destinationAssetID: string;
|
||||
currentAssetID: string;
|
||||
currentAsset: Asset;
|
||||
destinationAsset: Asset;
|
||||
hex_raw_proposal?: string;
|
||||
alias?: string;
|
||||
sender?: string;
|
||||
transfer?: any;
|
||||
swapProposal?: any;
|
||||
password?: string;
|
||||
key?: string;
|
||||
aliasDetails?: any;
|
||||
signReqs?: any[];
|
||||
windowId?: number;
|
||||
message?: string;
|
||||
timeout?: number;
|
||||
destinationChainId?: string;
|
||||
destinationAddress?: string;
|
||||
receivingAsset?: any;
|
||||
sendingAsset?: any;
|
||||
asset?: Asset;
|
||||
asset_id?: string;
|
||||
asset_name?: string;
|
||||
comment: string;
|
||||
burnAmount: number;
|
||||
nativeAmount?: number;
|
||||
pointTxToAddress?: string;
|
||||
serviceEntries?: any[];
|
||||
}
|
||||
|
||||
interface Sender {
|
||||
id: string;
|
||||
name?: string;
|
||||
email?: string;
|
||||
phoneNumber?: string;
|
||||
address?: string;
|
||||
[key: string]: any;
|
||||
[key: string]: string | undefined;
|
||||
}
|
||||
|
||||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
processRequest(request, sender as Sender, sendResponse);
|
||||
return true;
|
||||
});
|
||||
|
||||
interface SendResponse {
|
||||
(_response: any): void;
|
||||
(_response: unknown): void;
|
||||
}
|
||||
|
||||
async function processRequest(request: RequestType, sender: Sender, sendResponse: SendResponse) {
|
||||
|
|
@ -375,8 +346,8 @@ async function processRequest(request: RequestType, sender: Sender, sendResponse
|
|||
case 'PING_WALLET':
|
||||
fetch(`http://localhost:${apiCredentials.port}/ping`)
|
||||
.then((res) => res.json())
|
||||
.then((res) => sendResponse({ data: true }))
|
||||
.catch((err) => sendResponse({ data: false }));
|
||||
.then((_res) => sendResponse({ data: true }))
|
||||
.catch((_err) => sendResponse({ data: false }));
|
||||
break;
|
||||
|
||||
case 'SET_ACTIVE_WALLET':
|
||||
|
|
@ -457,7 +428,7 @@ async function processRequest(request: RequestType, sender: Sender, sendResponse
|
|||
'IONIC_SWAP',
|
||||
request,
|
||||
sendResponse,
|
||||
(req) => ionicSwap(req.swap),
|
||||
(req) => ionicSwap(req.swap as ionicSwapType),
|
||||
{
|
||||
console: 'Error creating ionic swap:',
|
||||
response: 'An error occurred while creating ionic swap',
|
||||
|
|
@ -485,7 +456,7 @@ async function processRequest(request: RequestType, sender: Sender, sendResponse
|
|||
|
||||
PopupRequestsMethods.onRequestCreate('IONIC_SWAP', request, sendResponse, {
|
||||
swap: request,
|
||||
} as any);
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -512,7 +483,7 @@ async function processRequest(request: RequestType, sender: Sender, sendResponse
|
|||
|
||||
PopupRequestsMethods.onRequestCreate('TRANSFER', request, sendResponse, {
|
||||
transfer: request,
|
||||
} as any);
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -522,9 +493,9 @@ async function processRequest(request: RequestType, sender: Sender, sendResponse
|
|||
request,
|
||||
sendResponse,
|
||||
(req) => {
|
||||
const transferData: any = req.transfer;
|
||||
const transferData = req.transfer;
|
||||
const { assetId, destination, amount, asset, comment, destinations } =
|
||||
transferData;
|
||||
transferData as TransferDataType;
|
||||
|
||||
const hasMultipleDestinations =
|
||||
Array.isArray(destinations) && destinations.length > 0;
|
||||
|
|
@ -574,7 +545,7 @@ async function processRequest(request: RequestType, sender: Sender, sendResponse
|
|||
sendResponse,
|
||||
async (req) =>
|
||||
createAlias({
|
||||
alias: req.alias,
|
||||
alias: String(req.alias),
|
||||
address: (await getWalletData()).address,
|
||||
}),
|
||||
{
|
||||
|
|
@ -623,7 +594,7 @@ async function processRequest(request: RequestType, sender: Sender, sendResponse
|
|||
'ACCEPT_IONIC_SWAP',
|
||||
request,
|
||||
sendResponse,
|
||||
request as any,
|
||||
request as unknown as PopupRequest,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
|
@ -648,7 +619,7 @@ async function processRequest(request: RequestType, sender: Sender, sendResponse
|
|||
burnBridge(
|
||||
pendingTx.assetId,
|
||||
pendingTx.amount,
|
||||
pendingTx.destinationAddress,
|
||||
String(pendingTx.destinationAddress),
|
||||
pendingTx.destinationChainId,
|
||||
)
|
||||
.then((data) => {
|
||||
|
|
@ -706,14 +677,17 @@ async function processRequest(request: RequestType, sender: Sender, sendResponse
|
|||
case 'FINALIZE_MESSAGE_SIGN': {
|
||||
const reqId = request.id;
|
||||
const { success } = request;
|
||||
const signReq: any = signReqs.find((req: any) => req.id === reqId);
|
||||
const signReq = signReqs.find((req) => req.id === reqId);
|
||||
|
||||
if (signReq && signReqFinalizers[reqId]) {
|
||||
function finalize(data: any) {
|
||||
// eslint-disable-next-line no-inner-declarations
|
||||
function finalize(data: unknown) {
|
||||
signReqFinalizers[reqId](data);
|
||||
signReqs.splice(signReqs.indexOf(signReq), 1);
|
||||
delete signReqFinalizers[reqId];
|
||||
chrome.windows.remove(signReq.windowId);
|
||||
if (signReq) {
|
||||
signReqs.splice(signReqs.indexOf(signReq), 1);
|
||||
delete signReqFinalizers[reqId];
|
||||
chrome.windows.remove(signReq.windowId);
|
||||
}
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
|
|
@ -758,13 +732,13 @@ async function processRequest(request: RequestType, sender: Sender, sendResponse
|
|||
|
||||
signReqs.push({
|
||||
id: signReqId,
|
||||
windowId: requestWindow.id,
|
||||
message: request.message,
|
||||
windowId: Number(requestWindow.id),
|
||||
message: String(request.message),
|
||||
});
|
||||
|
||||
if (typeof request.timeout === 'number') {
|
||||
setTimeout(() => {
|
||||
const signReqIndex = signReqs.findIndex((req: any) => req.id === signReqId);
|
||||
const signReqIndex = signReqs.findIndex((req) => req.id === signReqId);
|
||||
|
||||
if (signReqIndex === -1) {
|
||||
return;
|
||||
|
|
@ -832,7 +806,7 @@ async function processRequest(request: RequestType, sender: Sender, sendResponse
|
|||
|
||||
PopupRequestsMethods.onRequestCreate('CREATE_ALIAS', request, sendResponse, {
|
||||
alias: request.alias,
|
||||
} as any);
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -853,7 +827,7 @@ async function processRequest(request: RequestType, sender: Sender, sendResponse
|
|||
'ASSETS_WHITELIST_ADD',
|
||||
request,
|
||||
sendResponse,
|
||||
request as any,
|
||||
request as unknown as PopupRequest,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
|
@ -877,7 +851,7 @@ async function processRequest(request: RequestType, sender: Sender, sendResponse
|
|||
method: 'FINALIZE_BURN_ASSET_REQUEST',
|
||||
name: 'Burn asset',
|
||||
burn: request,
|
||||
} as any);
|
||||
});
|
||||
break;
|
||||
|
||||
case 'GET_BURN_ASSET_REQUESTS':
|
||||
|
|
@ -890,7 +864,7 @@ async function processRequest(request: RequestType, sender: Sender, sendResponse
|
|||
request,
|
||||
sendResponse,
|
||||
async (req) => {
|
||||
const burnReq = req.burn as any;
|
||||
const burnReq = req.burn as BurnAssetDataType;
|
||||
return burnAsset({
|
||||
assetId: burnReq.assetId,
|
||||
burnAmount: burnReq.burnAmount,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,17 @@ import JSONbig from 'json-bigint';
|
|||
import { apiCredentials } from './background';
|
||||
import { addZeros, removeZeros } from '../app/utils/utils';
|
||||
import { ZANO_ASSET_ID } from '../constants';
|
||||
import {
|
||||
BurnAssetDataType,
|
||||
BurnAssetParamsType,
|
||||
ionicSwapType,
|
||||
ParsedAddress,
|
||||
ParsedBalance,
|
||||
Transaction,
|
||||
TransactionRaw,
|
||||
WalletAsset,
|
||||
WalletRaw,
|
||||
} from '../types';
|
||||
// window.Buffer = Buffer;
|
||||
|
||||
interface JWTPayload {
|
||||
|
|
@ -66,7 +77,7 @@ interface fetchDataProps {
|
|||
|
||||
export const fetchData = async (
|
||||
method: string,
|
||||
params: fetchDataProps | object = {},
|
||||
params: string | fetchDataProps | object = {},
|
||||
): Promise<Response> => {
|
||||
const httpBody: string = JSON.stringify({
|
||||
jsonrpc: '2.0',
|
||||
|
|
@ -102,7 +113,7 @@ const fetchTxData = async () => {
|
|||
return JSONbig.parse(data);
|
||||
};
|
||||
|
||||
export const getAlias = async (address: string) => {
|
||||
export const getAlias = async (address: string | fetchDataProps | object = {}) => {
|
||||
const response = await fetchData('get_alias_by_address', address);
|
||||
const data = await response.json();
|
||||
if (data.result?.status === 'OK') {
|
||||
|
|
@ -131,17 +142,17 @@ export const getWallets = async () => {
|
|||
// console.log("wallets:", data.result.wallets);
|
||||
|
||||
const wallets = await Promise.all(
|
||||
data.result.wallets.map(async (wallet: any) => {
|
||||
data.result.wallets.map(async (wallet: WalletRaw) => {
|
||||
const alias = await getAlias(wallet.wi.address);
|
||||
const balance = wallet.wi.balances.find(
|
||||
(asset: any) => asset.asset_info.asset_id === ZANO_ASSET_ID,
|
||||
).total;
|
||||
const balanceRaw =
|
||||
wallet.wi.balances.find((asset) => asset.asset_info.asset_id === ZANO_ASSET_ID)
|
||||
?.total || '0';
|
||||
|
||||
return {
|
||||
address: wallet.wi.address,
|
||||
alias,
|
||||
balance: removeZeros(balance),
|
||||
is_watch_only: wallet?.wi?.is_watch_only,
|
||||
balance: removeZeros(balanceRaw),
|
||||
is_watch_only: wallet.wi.is_watch_only,
|
||||
wallet_id: wallet.wallet_id,
|
||||
};
|
||||
}),
|
||||
|
|
@ -157,13 +168,14 @@ export const getWallets = async () => {
|
|||
|
||||
export const getWalletData = async () => {
|
||||
const addressResponse = await fetchData('getaddress');
|
||||
const addressParsed = await addressResponse.json();
|
||||
const addressParsed: ParsedAddress = await addressResponse.json();
|
||||
const { address } = addressParsed.result;
|
||||
const balanceResponse = await fetchData('getbalance');
|
||||
const balanceParsed = JSONbig.parse(await balanceResponse.text());
|
||||
|
||||
const assets = balanceParsed.result.balances
|
||||
.map((asset: any) => ({
|
||||
const balanceResponse = await fetchData('getbalance');
|
||||
const balanceParsed: ParsedBalance = JSONbig.parse(await balanceResponse.text());
|
||||
|
||||
const assets: WalletAsset[] = balanceParsed.result.balances
|
||||
.map((asset) => ({
|
||||
name: asset.asset_info.full_name,
|
||||
ticker: asset.asset_info.ticker,
|
||||
assetId: asset.asset_info.asset_id,
|
||||
|
|
@ -171,33 +183,30 @@ export const getWalletData = async () => {
|
|||
balance: removeZeros(asset.total, asset.asset_info.decimal_point),
|
||||
unlockedBalance: removeZeros(asset.unlocked, asset.asset_info.decimal_point),
|
||||
}))
|
||||
.sort((a: any, b: any) => {
|
||||
if (a.assetId === ZANO_ASSET_ID) {
|
||||
return -1;
|
||||
}
|
||||
if (b.assetId === ZANO_ASSET_ID) {
|
||||
return 1;
|
||||
}
|
||||
.sort((a, b) => {
|
||||
if (a.assetId === ZANO_ASSET_ID) return -1;
|
||||
if (b.assetId === ZANO_ASSET_ID) return 1;
|
||||
return 0;
|
||||
});
|
||||
|
||||
function getAssetDecimalPoint(assetId: any) {
|
||||
return assets.find((asset: any) => asset.assetId === assetId)?.decimalPoint;
|
||||
function getAssetDecimalPoint(assetId: string): number | undefined {
|
||||
return assets.find((asset) => asset.assetId === assetId)?.decimalPoint;
|
||||
}
|
||||
|
||||
const balance = removeZeros(
|
||||
balanceParsed.result.balances.find(
|
||||
(asset: any) => asset.asset_info.asset_id === ZANO_ASSET_ID,
|
||||
).total,
|
||||
balanceParsed.result.balances.find((asset) => asset.asset_info.asset_id === ZANO_ASSET_ID)
|
||||
?.total || '0',
|
||||
);
|
||||
|
||||
const txDataResponse = await fetchTxData();
|
||||
const txData = txDataResponse.result.transfers;
|
||||
let transactions = [];
|
||||
const txData: TransactionRaw[] = txDataResponse.result.transfers;
|
||||
|
||||
let transactions: Transaction[] = [];
|
||||
|
||||
if (txData) {
|
||||
transactions = txData
|
||||
.filter((tx: any) => !tx.is_service)
|
||||
.map((tx: any) => ({
|
||||
.filter((tx) => !tx.is_service)
|
||||
.map((tx) => ({
|
||||
isConfirmed: tx.height !== 0,
|
||||
txHash: tx.tx_hash,
|
||||
blobSize: tx.tx_blob_size,
|
||||
|
|
@ -207,8 +216,8 @@ export const getWalletData = async () => {
|
|||
comment: tx.comment,
|
||||
fee: removeZeros(tx.fee),
|
||||
addresses: tx.remote_addresses,
|
||||
isInitiator: !!tx.employed_entries?.spent?.some?.((e: any) => e?.index === 0),
|
||||
transfers: tx.subtransfers.map((transfer: any) => ({
|
||||
isInitiator: !!tx.employed_entries?.spent?.some((e) => e?.index === 0),
|
||||
transfers: tx.subtransfers.map((transfer) => ({
|
||||
amount: removeZeros(
|
||||
transfer.amount,
|
||||
getAssetDecimalPoint(transfer.asset_id) || 12,
|
||||
|
|
@ -219,9 +228,8 @@ export const getWalletData = async () => {
|
|||
}));
|
||||
}
|
||||
|
||||
// console.log("get alias:", address);
|
||||
|
||||
const alias = await getAlias(address);
|
||||
|
||||
return {
|
||||
address,
|
||||
alias,
|
||||
|
|
@ -231,7 +239,7 @@ export const getWalletData = async () => {
|
|||
};
|
||||
};
|
||||
|
||||
export const ionicSwap = async (swapParams: any) => {
|
||||
export const ionicSwap = async (swapParams: ionicSwapType) => {
|
||||
const response = await fetchData('ionic_swap_generate_proposal', {
|
||||
proposal: {
|
||||
to_initiator: [
|
||||
|
|
@ -267,7 +275,7 @@ export const ionicSwap = async (swapParams: any) => {
|
|||
return data;
|
||||
};
|
||||
|
||||
export const ionicSwapAccept = async (swapParams: any) => {
|
||||
export const ionicSwapAccept = async (swapParams: { hex_raw_proposal: unknown }) => {
|
||||
console.log(swapParams.hex_raw_proposal);
|
||||
|
||||
const response = await fetchData('ionic_swap_accept_proposal', {
|
||||
|
|
@ -296,9 +304,9 @@ export const createAlias = async ({ alias, address }: { address: string; alias:
|
|||
|
||||
export const transfer = async (
|
||||
assetId = ZANO_ASSET_ID,
|
||||
destination: string,
|
||||
amount: string,
|
||||
decimalPoint: any,
|
||||
destination: string | undefined,
|
||||
amount: string | undefined,
|
||||
decimalPoint: number,
|
||||
comment?: string,
|
||||
destinations: { address: string; amount: number }[] = [],
|
||||
) => {
|
||||
|
|
@ -316,7 +324,7 @@ export const transfer = async (
|
|||
{
|
||||
address: destination,
|
||||
amount: addZeros(
|
||||
amount,
|
||||
String(amount),
|
||||
typeof decimalPoint === 'number' ? decimalPoint : 12,
|
||||
),
|
||||
asset_id: assetId,
|
||||
|
|
@ -342,15 +350,15 @@ export const transfer = async (
|
|||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
return response.json();
|
||||
};
|
||||
|
||||
// TODO: move bridge address to the config
|
||||
export const burnBridge = async (
|
||||
amount: string,
|
||||
destinationAddress: string,
|
||||
destinationChainId: string,
|
||||
assetId = ZANO_ASSET_ID,
|
||||
amount: any,
|
||||
destinationAddress: any,
|
||||
destinationChainId: any,
|
||||
) => {
|
||||
const bodyData = {
|
||||
service_id: 'B',
|
||||
|
|
@ -394,7 +402,7 @@ export const burnBridge = async (
|
|||
return data;
|
||||
};
|
||||
|
||||
export const signMessage = async (message: any) => {
|
||||
export const signMessage = async (message: string) => {
|
||||
const base64 = Buffer.from(message).toString('base64');
|
||||
|
||||
const signRequest = {
|
||||
|
|
@ -411,15 +419,15 @@ export const signMessage = async (message: any) => {
|
|||
return data;
|
||||
};
|
||||
export const createConnectKey = async () =>
|
||||
await fetch(`http://localhost:${apiCredentials.port}/connect-api-consumer`, {
|
||||
fetch(`http://localhost:${apiCredentials.port}/connect-api-consumer`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}).then((r) => r.json());
|
||||
|
||||
export const validateConnectKey = async (key: any) =>
|
||||
await fetch(`http://localhost:${apiCredentials.port}/validate-connection-key`, {
|
||||
export const validateConnectKey = async (key: string | undefined) =>
|
||||
fetch(`http://localhost:${apiCredentials.port}/validate-connection-key`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
|
@ -427,7 +435,7 @@ export const validateConnectKey = async (key: any) =>
|
|||
body: JSON.stringify({ key }),
|
||||
}).then((r) => r.json());
|
||||
|
||||
export const getSwapProposalInfo = async (hex: any) => {
|
||||
export const getSwapProposalInfo = async (hex: string | undefined) => {
|
||||
const response = await fetchData('ionic_swap_get_proposal_info', {
|
||||
hex_raw_proposal: hex,
|
||||
});
|
||||
|
|
@ -446,7 +454,7 @@ export async function getWhiteList() {
|
|||
.then((response) => response.json())
|
||||
.then((data) => data.assets);
|
||||
|
||||
if (fetchedWhiteList.every((e: any) => e.asset_id !== ZANO_ASSET_ID)) {
|
||||
if (fetchedWhiteList.every((e: { asset_id: string }) => e.asset_id !== ZANO_ASSET_ID)) {
|
||||
fetchedWhiteList.push({
|
||||
asset_id: ZANO_ASSET_ID,
|
||||
ticker: 'ZANO',
|
||||
|
|
@ -458,7 +466,7 @@ export async function getWhiteList() {
|
|||
return fetchedWhiteList;
|
||||
}
|
||||
|
||||
export async function getAssetInfo(assetId: any) {
|
||||
export async function getAssetInfo(assetId: string) {
|
||||
const response = await fetchData('get_asset_info', { asset_id: assetId });
|
||||
|
||||
if (!response.ok) {
|
||||
|
|
@ -485,30 +493,17 @@ export const burnAsset = async ({
|
|||
assetId,
|
||||
burnAmount,
|
||||
decimalPoint = 12,
|
||||
nativeAmount = 0,
|
||||
nativeAmount = '0',
|
||||
pointTxToAddress,
|
||||
serviceEntries = [],
|
||||
}: {
|
||||
assetId: string;
|
||||
burnAmount: number;
|
||||
decimalPoint?: number;
|
||||
nativeAmount?: number;
|
||||
pointTxToAddress?: string;
|
||||
serviceEntries?: {
|
||||
body: string;
|
||||
flags: number;
|
||||
instruction: string;
|
||||
security?: string;
|
||||
service_id: string;
|
||||
}[];
|
||||
}) => {
|
||||
const params: any = {
|
||||
}: BurnAssetDataType) => {
|
||||
const params: BurnAssetParamsType = {
|
||||
asset_id: assetId,
|
||||
burn_amount: addZeros(burnAmount, decimalPoint).toFixed(0),
|
||||
};
|
||||
|
||||
if (nativeAmount) {
|
||||
params.native_amount = nativeAmount;
|
||||
params.native_amount = addZeros(nativeAmount, 12).toFixed(0);
|
||||
}
|
||||
|
||||
if (pointTxToAddress) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
// Types
|
||||
export type dispatchType = () => void;
|
||||
export type destinationsType = { address: string; amount: number }[];
|
||||
|
||||
export type transferType = {
|
||||
id?: string;
|
||||
transfer: {
|
||||
sender: string;
|
||||
destination: string;
|
||||
|
|
@ -23,7 +23,7 @@ type serviceEntriesType = {
|
|||
service_id: string;
|
||||
};
|
||||
|
||||
export type RequestType = {
|
||||
export type BurnAssetRequestType = {
|
||||
method: string;
|
||||
assetId: string;
|
||||
amount: string;
|
||||
|
|
@ -82,9 +82,194 @@ export interface BurnAssetRequest {
|
|||
|
||||
export interface BurnAssetDataType {
|
||||
assetId: string;
|
||||
burnAmount: number;
|
||||
burnAmount: string;
|
||||
decimalPoint?: number;
|
||||
nativeAmount?: string;
|
||||
pointTxToAddress?: string;
|
||||
serviceEntries?: serviceEntriesType[];
|
||||
}
|
||||
|
||||
export interface BurnAssetParamsType {
|
||||
asset_id: string;
|
||||
burn_amount: string;
|
||||
native_amount?: string;
|
||||
point_tx_to_address?: string;
|
||||
service_entries?: serviceEntriesType[];
|
||||
}
|
||||
|
||||
export interface ionicSwapType {
|
||||
destinationAssetID: string;
|
||||
destinationAssetAmount: string;
|
||||
destinationAsset: {
|
||||
decimal_point: number;
|
||||
};
|
||||
currentAssetID: string;
|
||||
currentAssetAmount: string;
|
||||
currentAsset: {
|
||||
decimal_point: number;
|
||||
};
|
||||
expirationTimestamp: string;
|
||||
destinationAddress: string;
|
||||
}
|
||||
|
||||
interface AssetInfo {
|
||||
full_name: string;
|
||||
ticker: string;
|
||||
asset_id: string;
|
||||
decimal_point: number;
|
||||
}
|
||||
|
||||
interface BalanceItem {
|
||||
asset_info: AssetInfo;
|
||||
total: string;
|
||||
unlocked: string;
|
||||
}
|
||||
|
||||
export interface ParsedBalance {
|
||||
result: {
|
||||
balances: BalanceItem[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface ParsedAddress {
|
||||
result: {
|
||||
address: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface TransferRaw {
|
||||
amount: string;
|
||||
asset_id: string;
|
||||
is_income: boolean;
|
||||
}
|
||||
|
||||
export interface TransactionRaw {
|
||||
tx_hash: string;
|
||||
tx_blob_size: number;
|
||||
timestamp: number;
|
||||
height: number;
|
||||
payment_id: string;
|
||||
comment?: string;
|
||||
fee: string;
|
||||
remote_addresses: string[];
|
||||
is_service: boolean;
|
||||
subtransfers: TransferRaw[];
|
||||
employed_entries?: {
|
||||
spent?: { index: number }[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface Transaction {
|
||||
isConfirmed: boolean;
|
||||
txHash: string;
|
||||
blobSize: number;
|
||||
timestamp: number;
|
||||
height: number;
|
||||
paymentId: string;
|
||||
comment?: string;
|
||||
fee: string;
|
||||
addresses: string[];
|
||||
isInitiator: boolean;
|
||||
transfers: {
|
||||
amount: string;
|
||||
assetId: string;
|
||||
incoming: boolean;
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface WalletAsset {
|
||||
name: string;
|
||||
ticker: string;
|
||||
assetId: string;
|
||||
decimalPoint: number;
|
||||
balance: string;
|
||||
unlockedBalance: string;
|
||||
}
|
||||
|
||||
interface AssetInfo {
|
||||
asset_id: string;
|
||||
full_name: string;
|
||||
ticker: string;
|
||||
decimal_point: number;
|
||||
}
|
||||
|
||||
interface Balance {
|
||||
total: string;
|
||||
unlocked: string;
|
||||
asset_info: AssetInfo;
|
||||
}
|
||||
|
||||
interface WalletWI {
|
||||
address: string;
|
||||
balances: Balance[];
|
||||
is_watch_only?: boolean;
|
||||
}
|
||||
|
||||
export interface WalletRaw {
|
||||
wallet_id: string;
|
||||
wi: WalletWI;
|
||||
}
|
||||
|
||||
export interface WalletDataResponse {
|
||||
result: {
|
||||
wallets: WalletRaw[];
|
||||
};
|
||||
}
|
||||
|
||||
interface AssetDataType {
|
||||
asset_id: string;
|
||||
ticker: string;
|
||||
full_name: string;
|
||||
decimal_point: number;
|
||||
}
|
||||
|
||||
export interface RequestType {
|
||||
method: string;
|
||||
credentials: object;
|
||||
id: string;
|
||||
assetId: string;
|
||||
destination: string;
|
||||
amount: string;
|
||||
decimalPoint: number;
|
||||
success: boolean;
|
||||
destinationAssetID: string;
|
||||
currentAssetID: string;
|
||||
currentAsset: AssetDataType;
|
||||
destinationAsset: AssetDataType;
|
||||
hex_raw_proposal?: string;
|
||||
alias?: string;
|
||||
sender?: string;
|
||||
transfer?: unknown;
|
||||
swapProposal?: unknown;
|
||||
password?: string;
|
||||
key?: string;
|
||||
aliasDetails?: unknown;
|
||||
signReqs?: unknown[];
|
||||
windowId?: number;
|
||||
message?: string;
|
||||
timeout?: number;
|
||||
destinationChainId?: string;
|
||||
destinationAddress?: string;
|
||||
receivingAsset?: unknown;
|
||||
sendingAsset?: unknown;
|
||||
asset?: AssetDataType;
|
||||
asset_id?: string;
|
||||
asset_name?: string;
|
||||
comment: string;
|
||||
burnAmount: number;
|
||||
nativeAmount?: number;
|
||||
pointTxToAddress?: string;
|
||||
serviceEntries?: serviceEntriesType[];
|
||||
}
|
||||
|
||||
export interface TransferDataType {
|
||||
destination: string;
|
||||
amount: string;
|
||||
decimalPoint: number;
|
||||
comment?: string;
|
||||
destinations: { address: string; amount: number }[];
|
||||
assetId: string;
|
||||
asset: {
|
||||
decimal_point: number;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue