Skip to content

Commit

Permalink
fixed the issue with an empty version for not deployed wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
xtonwallet committed May 3, 2023
1 parent 4dbe6f4 commit b10681a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
18 changes: 9 additions & 9 deletions src/background/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ export const accounts = () => {
const TonLibClient = await TonLib.getClient(server);
const account = await vault.getAccount(accountAddress);
const keyPair = await decrypt(currentPassword, account.encrypted);
return await TonLibClient.walletStateInit(keyPair.public, account.version[server] ? account.version[server] : "");
return await TonLibClient.walletStateInit(keyPair.public, account.version && account.version[server] ? account.version[server] : "");
};

const addAccountByKeys = async (nickname, keyPair, version) => {
Expand Down Expand Up @@ -811,7 +811,7 @@ export const accounts = () => {

let result;
if (txData.params.allBalance) { //@TODO need to be sure, that one-custodial wallet
result = await TonLibClient.calcRunFees(account.version[server], accountAddress,
result = await TonLibClient.calcRunFees(account.version && account.version[server] ? account.version[server]: "", accountAddress,
{
toAddress: txData.params.destination,
amount: 0,
Expand All @@ -820,7 +820,7 @@ export const accounts = () => {
},
keyPair);
} else {
result = await TonLibClient.calcRunFees(account.version[server], accountAddress,
result = await TonLibClient.calcRunFees(account.version && account.version[server] ? account.version[server]: "", accountAddress,
{
toAddress: txData.params.destination,
amount: txData.params.amount,
Expand Down Expand Up @@ -866,7 +866,7 @@ export const accounts = () => {
txDataPrepared.stateInit = TonLibClient.oneFromBoc(Unibabel.base64ToBuffer(txData.params.stateInit));
}

result = await TonLibClient.calcRunFees(account.version[server], accountAddress,
result = await TonLibClient.calcRunFees(account.version && account.version[server] ? account.version[server]: "", accountAddress,
txDataPrepared,
keyPair);

Expand All @@ -891,7 +891,7 @@ export const accounts = () => {
}
let result;
if (txData.params.allBalance) {
result = await TonLibClient.sendTransaction(account.version[server], accountAddress, bounce,
result = await TonLibClient.sendTransaction(account.version && account.version[server] ? account.version[server]: "", accountAddress, bounce,
{
toAddress: txData.params.destination,
amount: 0,
Expand All @@ -900,7 +900,7 @@ export const accounts = () => {
},
keyPair);
} else {
result = await TonLibClient.sendTransaction(account.version[server], accountAddress, bounce,
result = await TonLibClient.sendTransaction(account.version && account.version[server] ? account.version[server]: "", accountAddress, bounce,
{
toAddress: txData.params.destination,
amount: txData.params.amount,
Expand Down Expand Up @@ -943,7 +943,7 @@ export const accounts = () => {
if (txData.params.stateInit) {
txDataPrepared.stateInit = TonLibClient.oneFromBoc(Unibabel.base64ToBuffer(txData.params.stateInit));
}
result = await TonLibClient.sendTransaction(account.version[server], accountAddress, false, txDataPrepared, keyPair);
result = await TonLibClient.sendTransaction(account.version && account.version[server] ? account.version[server]: "", accountAddress, false, txDataPrepared, keyPair);

return {id: 0, reason: `SubmitRawTransaction for ${txData.params.to} with amount ${txData.params.amount}`};
} catch (exp) {
Expand Down Expand Up @@ -1166,7 +1166,7 @@ export const accounts = () => {
const TonLibClient = await TonLib.getClient(server);
const walletAddressOwner = await getTokenType74WalletAddress(server, txData.params.token.address, accountAddress);
const JtWallet = TonLibClient.getFtTokenWallet(walletAddressOwner);
const result = await TonLibClient.estimateTransferFtTokenWallet(account.version[server], JtWallet, accountAddress, walletAddressOwner, {
const result = await TonLibClient.estimateTransferFtTokenWallet(account.version && account.version[server] ? account.version[server]: "", JtWallet, accountAddress, walletAddressOwner, {
"jettonAmount": txData.params.amount,
"toAddress": txData.params.destination,
"responseAddress": accountAddress,
Expand Down Expand Up @@ -1261,7 +1261,7 @@ export const accounts = () => {
const walletAddressOwner = await getTokenType74WalletAddress(server, txData.params.token.address, accountAddress);

const JtWallet = TonLibClient.getFtTokenWallet(walletAddressOwner);
const result = await TonLibClient.sendTransferFtTokenWallet(account.version[server], JtWallet, accountAddress, walletAddressOwner, {
const result = await TonLibClient.sendTransferFtTokenWallet(account.version && account.version[server] ? account.version[server]: "", JtWallet, accountAddress, walletAddressOwner, {
"jettonAmount": txData.params.amount,
"toAddress": txData.params.destination,
"responseAddress": accountAddress,
Expand Down
28 changes: 24 additions & 4 deletions src/common/tonLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ class TonLib {
}
}

async sendTransaction(version, address, bounce, data, keyPair) {
async sendTransaction(_version, address, bounce, data, keyPair) {
try {
let version = this.defaultWalletVersion;
if (_version != "" && this.instance.wallet.all[_version]) {
version = _version;
}

const WalletClass = this.instance.wallet.all[version];
const toAddress = (new TonWeb.Address(address)).toString(true, true, false);
const walletContract = new WalletClass(this.instance.provider, {address: toAddress});
Expand Down Expand Up @@ -295,8 +300,13 @@ class TonLib {
}
}

async calcRunFees(version, address, data, keyPair = null) {
async calcRunFees(_version, address, data, keyPair = null) {
try {
let version = this.defaultWalletVersion;
if (_version != "" && this.instance.wallet.all[_version]) {
version = _version;
}

const WalletClass = this.instance.wallet.all[version];
const toAddress = (new TonWeb.Address(address)).toString(true, true, false);
const walletContract = new WalletClass(this.instance.provider, {address: toAddress});
Expand Down Expand Up @@ -367,12 +377,17 @@ class TonLib {
}
}

async estimateTransferFtTokenWallet(version, JtWallet, accountAddress, walletAddressOwner, params, keyPair) {
async estimateTransferFtTokenWallet(_version, JtWallet, accountAddress, walletAddressOwner, params, keyPair) {
try {
params.toAddress = new TonWeb.Address(params.toAddress);
params.responseAddress = new TonWeb.Address(params.responseAddress);
params.forwardPayload = Unibabel.utf8ToBuffer(params.forwardPayload);

let version = this.defaultWalletVersion;
if (_version != "" && this.instance.wallet.all[_version]) {
version = _version;
}

const WalletClass = this.instance.wallet.all[version];
const toAddress = (new TonWeb.Address(accountAddress)).toString(true, true, false);
const walletContract = new WalletClass(this.instance.provider, {address: toAddress});
Expand All @@ -392,12 +407,17 @@ class TonLib {
}
}

async sendTransferFtTokenWallet(version, JtWallet, accountAddress, walletAddressOwner, params, keyPair) {
async sendTransferFtTokenWallet(_version, JtWallet, accountAddress, walletAddressOwner, params, keyPair) {
try {
params.toAddress = (new TonWeb.Address(params.toAddress));
params.responseAddress = (new TonWeb.Address(params.responseAddress));
params.forwardPayload = Unibabel.utf8ToBuffer(params.forwardPayload);

let version = this.defaultWalletVersion;
if (_version != "" && this.instance.wallet.all[_version]) {
version = _version;
}

const WalletClass = this.instance.wallet.all[version];
const toAddress = (new TonWeb.Address(accountAddress)).toString(true, true, false);
const walletContract = new WalletClass(this.instance.provider, {address: toAddress});
Expand Down

0 comments on commit b10681a

Please sign in to comment.