Skip to content

Commit

Permalink
createPayloadOfStandardTonAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
KuznetsovNikita committed Nov 25, 2024
1 parent 22bcf97 commit a0b1909
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions packages/core/src/service/walletService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,16 @@ export const getContextApiByNetwork = (context: CreateWalletContext, network: Ne
return [api, context.defaultWalletVersion] as const;
};

export const createStandardTonAccountByMnemonic = async (
const createPayloadOfStandardTonAccount = async (
appContext: CreateWalletContext,
storage: IStorage,
mnemonic: string[],
mnemonicType: MnemonicType,
options: {
versions?: WalletVersion[];
auth: AuthPassword | Omit<AuthKeychain, 'keychainStoreKey'>;
}
},
network: Network
) => {
const keyPair = await mnemonicToKeypair(mnemonic, mnemonicType);

Expand All @@ -137,13 +138,13 @@ export const createStandardTonAccountByMnemonic = async (
let tonWallets: { rawAddress: string; version: WalletVersion }[] = [];
if (options.versions) {
tonWallets = options.versions
.map(v => getWalletAddress(publicKey, v, Network.MAINNET))
.map(v => getWalletAddress(publicKey, v, network))
.map(i => ({
rawAddress: i.address.toRawString(),
version: i.version
}));
} else {
tonWallets = [await findWalletAddress(appContext, Network.MAINNET, publicKey)];
tonWallets = [await findWalletAddress(appContext, network, publicKey)];
}

let walletAuth: AuthPassword | AuthKeychain;
Expand All @@ -158,11 +159,33 @@ export const createStandardTonAccountByMnemonic = async (

const { name, emoji } = await accountsStorage(storage).getNewAccountNameAndEmoji(publicKey);

const wallets = tonWallets
.slice()
.map(item => getTonWalletStandard(item, publicKey, Network.MAINNET));
const wallets = tonWallets.slice().map(item => getTonWalletStandard(item, publicKey, network));

const walletIdToActivate = wallets.slice().sort(sortWalletsByVersion)[0].id;

return { name, emoji, publicKey, walletAuth, walletIdToActivate, wallets };
};

export const createStandardTonAccountByMnemonic = async (
appContext: CreateWalletContext,
storage: IStorage,
mnemonic: string[],
mnemonicType: MnemonicType,
options: {
versions?: WalletVersion[];
auth: AuthPassword | Omit<AuthKeychain, 'keychainStoreKey'>;
}
) => {
const { name, emoji, publicKey, walletAuth, walletIdToActivate, wallets } =
await createPayloadOfStandardTonAccount(
appContext,
storage,
mnemonic,
mnemonicType,
options,
Network.MAINNET
);

return new AccountTonMnemonic(
publicKey,
name,
Expand All @@ -184,38 +207,15 @@ export const createStandardTestnetAccountByMnemonic = async (
auth: AuthPassword | Omit<AuthKeychain, 'keychainStoreKey'>;
}
) => {
const keyPair = await mnemonicToKeypair(mnemonic, mnemonicType);

const publicKey = keyPair.publicKey.toString('hex');

let tonWallets: { rawAddress: string; version: WalletVersion }[] = [];
if (options.versions) {
tonWallets = options.versions
.map(v => getWalletAddress(publicKey, v, Network.TESTNET))
.map(i => ({
rawAddress: i.address.toRawString(),
version: i.version
}));
} else {
tonWallets = [await findWalletAddress(appContext, Network.TESTNET, publicKey)];
}

let walletAuth: AuthPassword | AuthKeychain;
if (options.auth.kind === 'keychain') {
walletAuth = {
kind: 'keychain',
keychainStoreKey: publicKey
};
} else {
walletAuth = options.auth;
}

const { name, emoji } = await accountsStorage(storage).getNewAccountNameAndEmoji(publicKey);

const wallets = tonWallets
.slice()
.map(item => getTonWalletStandard(item, publicKey, Network.TESTNET));
const walletIdToActivate = wallets[0].id;
const { name, emoji, publicKey, walletAuth, walletIdToActivate, wallets } =
await createPayloadOfStandardTonAccount(
appContext,
storage,
mnemonic,
mnemonicType,
options,
Network.TESTNET
);

return new AccountTonTestnet(
`testnet-${publicKey}`,
Expand Down

0 comments on commit a0b1909

Please sign in to comment.