Skip to content

Commit

Permalink
Add refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ebma committed Jul 22, 2024
1 parent ec960db commit 854d115
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/v2/repositories/implementations/xcm/PendulumXcmRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import { XcmChain } from 'src/v2/models/XcmModels';
import { TokensAccounts } from 'src/v2/repositories/implementations/xcm/AcalaXcmRepository';
import { decodeAddress } from '@polkadot/util-crypto';

/**
* Used to transfer assets from Pendulum
*/

const PEN = 'Native';
const XLM = { Stellar: 'StellarNative' };
// Mapping object for token IDs
const TOKEN_IDS: Record<string, any> = {
PEN: 'Native',
'XLM.s': { Stellar: 'StellarNative' },
};

export class PendulumXcmRepository extends XcmRepository {
constructor() {
Expand All @@ -35,24 +34,28 @@ export class PendulumXcmRepository extends XcmRepository {
if (!to.parachainId) {
throw `Parachain id for ${to.name} is not defined`;
}
var tokenData;
if (token.originAssetId === 'PEN') {
tokenData = PEN;
} else if (token.originAssetId === 'XLM.s') {
tokenData = XLM;

const tokenData = TOKEN_IDS[token.originAssetId];
if (!tokenData) {
throw `Token name for ${token.originAssetId} is not defined`;
}

const version = 'V3';

const AccountId32 = {
id: decodeAddress(recipientAddress),
};

const destination = {
V3: {
[version]: {
parents: '1',
interior: {
X2: [
{
Parachain: to.parachainId,
},
{
AccountId32: {
id: decodeAddress(recipientAddress),
},
AccountId32,
},
],
},
Expand Down Expand Up @@ -84,13 +87,13 @@ export class PendulumXcmRepository extends XcmRepository {

try {
if (isNativeToken) {
return (await this.getNativeBalance(address, chain, endpoint)).toString();
const nativeBalance = await this.getNativeBalance(address, chain, endpoint);
return nativeBalance.toString();
}
let currencyId;
if (token.originAssetId === 'XLM.s') {
currencyId = XLM;
} else {
console.error('Unsupported token: ', token.originAssetId);

const currencyId = TOKEN_IDS[token.originAssetId];
if (!currencyId) {
console.error(`Token name for ${token.originAssetId} is not defined`);
return '0';
}
const bal = await api.query.tokens.accounts<TokensAccounts>(address, currencyId);
Expand Down

0 comments on commit 854d115

Please sign in to comment.