From 6c14cae259aa5c3977fbac2e83d9d57ed12567fa Mon Sep 17 00:00:00 2001 From: Nathaniel Parke Date: Thu, 5 Nov 2020 10:46:09 +0800 Subject: [PATCH] Auto create token account on order sending --- src/components/StandaloneBalancesDisplay.tsx | 18 ++++++++- src/components/TradeForm.tsx | 5 ++- .../UserInfoTable/WalletBalancesTable.tsx | 14 ++++++- src/utils/send.tsx | 37 ++++++++++++++++++- 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/src/components/StandaloneBalancesDisplay.tsx b/src/components/StandaloneBalancesDisplay.tsx index cd5e173..304e949 100644 --- a/src/components/StandaloneBalancesDisplay.tsx +++ b/src/components/StandaloneBalancesDisplay.tsx @@ -1,4 +1,4 @@ -import { Button, Col, Divider, Row } from 'antd'; +import {Button, Col, Divider, Popover, Row } from 'antd'; import React, { useState } from 'react'; import FloatingElement from './layout/FloatingElement'; import styled from 'styled-components'; @@ -18,6 +18,8 @@ import { useSendConnection } from '../utils/connection'; import { notify } from '../utils/notifications'; import { Balances } from '../utils/types'; import StandaloneTokenAccountsSelect from './StandaloneTokenAccountSelect'; +import LinkAddress from "./LinkAddress"; +import {InfoCircleOutlined} from "@ant-design/icons"; const RowBox = styled(Row)` padding-bottom: 20px; @@ -126,7 +128,19 @@ export default function StandaloneBalancesDisplay() { {formattedBalances.map( ([currency, balances, baseOrQuote, mint], index) => ( - {currency} + + {currency}{" "} + {mint && ( + } + placement="bottomRight" + title="Token mint" + trigger="hover" + > + + + )} + {connected && ( ( + + + {walletBalance.coin || abbreviateAddress(new PublicKey(walletBalance.mint))} + + + ) }, { title: 'Wallet Balance', diff --git a/src/utils/send.tsx b/src/utils/send.tsx index e7622b0..7ee92c4 100644 --- a/src/utils/send.tsx +++ b/src/utils/send.tsx @@ -388,6 +388,37 @@ export async function placeOrder({ return; } const owner = wallet.publicKey; + const transaction = new Transaction(); + const signers: Account[] = []; + + if (!baseCurrencyAccount) { + const { + transaction: createAccountTransaction, + signer: createAccountSigners, + newAccountPubkey + } = await createTokenAccountTransaction({ + connection, + wallet, + mintPublicKey: market.baseMintAddress + }); + transaction.add(createAccountTransaction); + signers.push(createAccountSigners); + baseCurrencyAccount = newAccountPubkey; + } + if (!quoteCurrencyAccount) { + const { + transaction: createAccountTransaction, + signer: createAccountSigners, + newAccountPubkey + } = await createTokenAccountTransaction({ + connection, + wallet, + mintPublicKey: market.quoteMintAddress + }); + transaction.add(createAccountTransaction); + signers.push(createAccountSigners); + quoteCurrencyAccount = newAccountPubkey; + } const payer = side === 'sell' ? baseCurrencyAccount : quoteCurrencyAccount; if (!payer) { @@ -407,10 +438,11 @@ export async function placeOrder({ }; console.log(params); - const transaction = market.makeMatchOrdersTransaction(5); + const matchOrderstransaction = market.makeMatchOrdersTransaction(5); + transaction.add(matchOrderstransaction) let { transaction: placeOrderTx, - signers, + signers: placeOrderSigners, } = await market.makePlaceOrderTransaction( connection, params, @@ -419,6 +451,7 @@ export async function placeOrder({ ); transaction.add(placeOrderTx); transaction.add(market.makeMatchOrdersTransaction(5)); + signers.push(...placeOrderSigners); return await sendTransaction({ transaction,