Skip to content

Commit

Permalink
Change type of amount parameter 🖌️
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldev5 authored and dudo50 committed Nov 19, 2023
1 parent f14d918 commit 178d0f2
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/nodes/ParachainNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ abstract class ParachainNode {
api: ApiPromise,
currencySymbol: string | undefined,
currencyId: string | undefined,
amount: any,
amount: string,
to: string,
destination?: TNode,
serializedApiCallEnabled = false
Expand Down
4 changes: 2 additions & 2 deletions src/pallets/builder/builders/Builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class FromGeneralBuilder {
return new ToGeneralBuilder(this.api, this.from, node)
}

amount(amount: any) {
amount(amount: string | number | bigint) {
return ParaToRelayBuilder.create(this.api, this.from, amount)
}

Expand Down Expand Up @@ -105,5 +105,5 @@ export interface AddressBuilder {
}

export interface AmountBuilder {
amount(amount: any): AddressBuilder
amount(amount: string | number | bigint): AddressBuilder
}
4 changes: 2 additions & 2 deletions src/pallets/builder/builders/ParaToParaBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ParaToParaBuilder implements AmountBuilder, AddressBuilder, FinalBuilder {
private to: TNode
private currency: string | number | bigint

private _amount: any
private _amount: string | number | bigint
private _address: string

private constructor(api: ApiPromise, from: TNode, to: TNode, currency: string | number | bigint) {
Expand All @@ -30,7 +30,7 @@ class ParaToParaBuilder implements AmountBuilder, AddressBuilder, FinalBuilder {
return new ParaToParaBuilder(api, from, to, currency)
}

amount(amount: any) {
amount(amount: string | number | bigint) {
this._amount = amount
return this
}
Expand Down
6 changes: 3 additions & 3 deletions src/pallets/builder/builders/ParaToRelayBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import { AddressBuilder, FinalBuilder } from './Builder'
class ParaToRelayBuilder implements AddressBuilder, FinalBuilder {
private api: ApiPromise
private from: TNode
private amount: any
private amount: string | number | bigint

private _address: string

private constructor(api: ApiPromise, from: TNode, amount: any) {
private constructor(api: ApiPromise, from: TNode, amount: string | number | bigint) {
this.api = api
this.from = from
this.amount = amount
}

static create(api: ApiPromise, from: TNode, amount: any): AddressBuilder {
static create(api: ApiPromise, from: TNode, amount: string | number | bigint): AddressBuilder {
return new ParaToRelayBuilder(api, from, amount)
}

Expand Down
27 changes: 17 additions & 10 deletions src/pallets/xcmPallet/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const sendCommon = (
api: ApiPromise,
origin: TNode,
currencySymbolOrId: string | number | bigint,
amount: any,
amount: string,
to: string,
destination?: TNode,
serializedApiCallEnabled = false
Expand Down Expand Up @@ -68,15 +68,15 @@ export const sendSerializedApiCall = (
api: ApiPromise,
origin: TNode,
currencySymbolOrId: string | number | bigint,
amount: any,
amount: string | number | bigint,
to: string,
destination?: TNode
): TSerializedApiCall => {
return sendCommon(
api,
origin,
currencySymbolOrId,
amount,
amount.toString(),
to,
destination,
true
Expand All @@ -87,18 +87,25 @@ export function send(
api: ApiPromise,
origin: TNode,
currencySymbolOrId: string | number | bigint,
amount: any,
amount: string | number | bigint,
to: string,
destination?: TNode
): Extrinsic {
return sendCommon(api, origin, currencySymbolOrId, amount, to, destination) as Extrinsic
return sendCommon(
api,
origin,
currencySymbolOrId,
amount.toString(),
to,
destination
) as Extrinsic
}

// TODO: Refactor this function
export const transferRelayToParaCommon = (
api: ApiPromise,
destination: TNode,
amount: any,
amount: string,
to: string,
serializedApiCallEnabled = false
): Extrinsic | TSerializedApiCall | never => {
Expand Down Expand Up @@ -177,16 +184,16 @@ export const transferRelayToParaCommon = (
export function transferRelayToPara(
api: ApiPromise,
destination: TNode,
amount: any,
amount: string | number | bigint,
to: string
): Extrinsic | never {
return transferRelayToParaCommon(api, destination, amount, to) as Extrinsic | never
return transferRelayToParaCommon(api, destination, amount.toString(), to) as Extrinsic | never
}

export const transferRelayToParaSerializedApiCall = (
api: ApiPromise,
destination: TNode,
amount: any,
amount: string | number | bigint,
to: string
): TSerializedApiCall =>
transferRelayToParaCommon(api, destination, amount, to, true) as TSerializedApiCall
transferRelayToParaCommon(api, destination, amount.toString(), to, true) as TSerializedApiCall
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type XTokensTransferInput = {
api: ApiPromise
currency: string | undefined
currencyID: string | undefined
amount: any
amount: string
addressSelection: any
fees: number
scenario: TScenario
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const generateAddressPayload = (
}

export const createCurrencySpecification = (
amount: any,
amount: string,
scenario: TScenario,
version: Version,
node?: TNode,
Expand Down

0 comments on commit 178d0f2

Please sign in to comment.