Skip to content
4 changes: 4 additions & 0 deletions apps/wallet/src/features/Send/InputTransaction/TokensTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Button, Select, Text, View } from '@walless/gui';
import type { TokenDocument } from '@walless/store';
import CheckedInput from 'components/CheckedInput';
import { NavButton } from 'components/NavButton';
import { keyState } from 'state/keys';
import { useTokens } from 'utils/hooks';
import { checkValidAddress } from 'utils/transaction';

Expand Down Expand Up @@ -89,6 +90,9 @@ export const TokensTab: FC<Props> = ({ onContinue }) => {
useEffect(() => {
if (type === 'token' && token) {
txActions.update({ network: token.network });
const publicKeys = Array.from(keyState.map.values());
const key = publicKeys.find((k) => k.network === network);
if (key) txActions.update({ sender: key._id });
}
}, [type, token]);

Expand Down
60 changes: 56 additions & 4 deletions apps/wallet/src/features/Send/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ import { ModalId } from 'modals/types';
import { solMint } from 'utils/constants';
import { useSnapshot } from 'utils/hooks';
import {
createAndSendSolanaTransaction,
createAndSendSuiTransaction,
getGasilonFee,
getSolanaTransactionFee,
createAndSendTezosTransaction,
getSuiTransactionFee,
hasEnoughBalanceToMakeTx,
} from 'utils/transaction';
import { constructSuiSendTokenTransaction } from 'utils/transaction/construct';
import { createAndSendSolanaTransaction } from 'utils/transaction';
import { constructSuiSendTokenTransaction } from 'utils/transaction';
import {
getGasilonFee,
getSolanaTransactionFee,
} from 'utils/transaction/solana/send/fee';
import type {
SolanaSendTransaction,
SuiSendTransaction,
TezosSendTokenTransaction,
} from 'utils/transaction/types';
import { proxy } from 'valtio';

Expand Down Expand Up @@ -143,6 +147,18 @@ export const txActions = {
break;
}

// case Networks.tezos: {
// txActions.update({ feeLoading: true });
// const genericTransaction = await createGenericTransaction();
// const { connection } = engine.getContext<TezosContext>(Networks.tezos);
// const fee = await getTezosTransactionFee(
// genericTransaction as TezosSendTokenTransaction,
// connection,
// );
// txActions.update({ feeAmount: fee, feeLoading: false });
// break;
// }

default: {
txActions.update({ feeAmount: 0 });
break;
Expand Down Expand Up @@ -203,6 +219,27 @@ export const txActions = {
});
onComplete?.();
}
} else if (txContext.tx.network === Networks.tezos) {
const payload = {
sender: genericTransaction?.sender,
receiver: genericTransaction?.receiver,
amount: genericTransaction?.amount,
token: genericTransaction?.token,
} as TezosSendTokenTransaction;

const res = await createAndSendTezosTransaction(payload, passcode);

if (res.responseCode === ResponseCode.WRONG_PASSCODE) {
showError({ errorText: 'Passcode is NOT matched' });
} else if (res.responseCode === ResponseCode.SUCCESS) {
const signature = res.signatureString;
txActions.update<TezosTransactionContext>({ signature });
txActions.update({ time: new Date() });
txActions.update({
status: res.isSuccessful ? 'success' : 'failed',
});
onComplete?.();
}
}

return true;
Expand Down Expand Up @@ -268,13 +305,24 @@ const createGenericTransaction = async () => {
} else {
throw new Error('Transfer Sui NFT not supported');
}
} else if (network === Networks.tezos) {
const { token } = txContext.tx as TokenTransactionContext;
transaction = {
sender,
receiver,
token,
amount: parseInt(amount) || 0,
network,
type,
} as TezosSendTokenTransaction;
} else {
throw new Error('Unsupported network');
}

const hasEnoughBalance = await hasEnoughBalanceToMakeTx(transaction);

if (!hasEnoughBalance) {
console.log('100');
showError({ errorText: 'Insufficient balance to send' });
return;
}
Expand Down Expand Up @@ -340,3 +388,7 @@ export type SuiTransactionContext = SuiTokenTransactionContext &
SuiCollectibleTransactionContext & {
signature?: string;
};

export type TezosTransactionContext = TokenTransactionContext & {
signature?: string;
};
3 changes: 2 additions & 1 deletion apps/wallet/src/features/Swap/ConfirmPasscode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import type { SolanaContext } from 'engine/runners';
import { showError } from 'modals/Error';
import assets from 'utils/assets';
import { nativeModules } from 'utils/native';
import { constructSwapTransaction, getAliasedMint } from 'utils/transaction';
import { signAndSendTransaction } from 'utils/transaction/solana';
import { getAliasedMint } from 'utils/transaction/solana/swap';
import { constructSwapTransaction } from 'utils/transaction/solana/swap';

import { swapActions, swapContext } from '../context';

Expand Down
2 changes: 1 addition & 1 deletion apps/wallet/src/features/Swap/InputSwap/ToToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useDebouncedCallback } from 'use-debounce';
import { parseWithDecimals } from 'utils/format';
import type { JupiterToken } from 'utils/hooks';
import { useSnapshot } from 'utils/hooks';
import { getAliasedMint, getSwapQuote } from 'utils/transaction';
import { getAliasedMint, getSwapQuote } from 'utils/transaction/solana/swap';

import type { SwapContext } from '../context';
import { swapActions, swapContext } from '../context';
Expand Down
5 changes: 3 additions & 2 deletions apps/wallet/src/features/Swap/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { AnimateDirections, BindDirections, modalActions } from '@walless/gui';
import type { TokenDocument } from '@walless/store';
import { ModalId } from 'modals/types';
import type { JupiterToken } from 'utils/hooks';
import type { SwapQuote } from 'utils/transaction';
import { checkValidAddress, getAliasedMint } from 'utils/transaction';
import { checkValidAddress } from 'utils/transaction';
import type { SwapQuote } from 'utils/transaction/solana/swap';
import { getAliasedMint } from 'utils/transaction/solana/swap';
import { proxy } from 'valtio';

import SelectFromToken from './Select/SelectFromToken';
Expand Down
1 change: 1 addition & 0 deletions apps/wallet/src/utils/transaction/aptos/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './send';
91 changes: 91 additions & 0 deletions apps/wallet/src/utils/transaction/aptos/send/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { Networks, RequestType, ResponseCode } from '@walless/core';
import type { ResponsePayload } from '@walless/messaging';
import { aptos, utils } from '@walless/network';
import { engine } from 'engine';
import type { AptosContext } from 'engine/runners';
import { storage } from 'utils/storage';

export const sendAptosTransaction = async (
transaction: aptos.AptosCoinPayload | aptos.AptosTokenPayload,
passcode: string,
) => {
const res = {} as ResponsePayload;

let privateKey;
try {
privateKey = await utils.getPrivateKey(storage, Networks.aptos, passcode);
} catch {
res.responseCode = ResponseCode.WRONG_PASSCODE;
return res;
}

const isCoinTransaction = !('creator' in transaction);

const { provider } = engine.getContext<AptosContext>(Networks.aptos);
if (isCoinTransaction) {
res.signatureString = await aptos.handleTransferCoin(
provider,
privateKey,
transaction,
);
} else {
res.signatureString = await aptos.handleTransferToken(
provider,
privateKey,
transaction,
);
}

res.responseCode = ResponseCode.SUCCESS;

return res;
};
export const handleAptosOnChainAction = async ({
passcode,
type,
payload,
}: {
passcode: string;
type: RequestType;
payload: unknown;
}) => {
const res = {} as ResponsePayload;

let privateKey;
try {
privateKey = await utils.getPrivateKey(storage, Networks.aptos, passcode);
} catch {
res.responseCode = ResponseCode.WRONG_PASSCODE;
return res;
}

try {
const { provider } = engine.getContext<AptosContext>(Networks.aptos);
switch (type) {
case RequestType.UPDATE_DIRECT_TRANSFER_ON_APTOS:
res.signatureString = await aptos.handleUpdateDirectTransfer(
provider,
privateKey,
payload as aptos.AptosDirectTransferPayload,
);
break;

case RequestType.CLAIM_TOKEN_ON_APTOS:
res.signatureString = await aptos.handleClaimToken(
provider,
privateKey,
payload as aptos.AptosClaimTokenPayload,
);
break;

default:
break;
}

res.responseCode = ResponseCode.SUCCESS;
} catch {
res.responseCode = ResponseCode.ERROR;
}

return res;
};
20 changes: 20 additions & 0 deletions apps/wallet/src/utils/transaction/aptos/send/index.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { RequestType } from '@walless/core';
import { sendRequest } from 'bridge';

export const handleAptosOnChainAction = async ({
passcode,
payload,
type,
}: {
passcode: string;
type: RequestType;
payload: unknown;
}) => {
const res = await sendRequest({
type,
transaction: JSON.stringify(payload),
passcode,
});

return res;
};
Loading