-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add disabled options config and function
- Loading branch information
Showing
7 changed files
with
110 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2023 Parity Technologies (UK) Ltd. | ||
|
||
import { Format, TransferArgsOpts } from '../types'; | ||
|
||
interface DisabledOptionsInfo { | ||
disabled: boolean; | ||
chains: string[]; | ||
} | ||
|
||
type MappedOpts = Extract<keyof TransferArgsOpts<Format>, string>; | ||
|
||
type DisabledOptions = { | ||
[key in MappedOpts]: DisabledOptionsInfo; | ||
}; | ||
|
||
export const disabledOpts: DisabledOptions = { | ||
format: { | ||
disabled: false, | ||
chains: [], | ||
}, | ||
paysWithFeeOrigin: { | ||
disabled: true, | ||
chains: ['westend', 'westmint'], | ||
}, | ||
paysWithFeeDest: { | ||
disabled: false, | ||
chains: [], | ||
}, | ||
sendersAddr: { | ||
disabled: false, | ||
chains: [], | ||
}, | ||
isLimited: { | ||
disabled: false, | ||
chains: [], | ||
}, | ||
weightLimit: { | ||
disabled: false, | ||
chains: [], | ||
}, | ||
xcmVersion: { | ||
disabled: false, | ||
chains: [], | ||
}, | ||
keepAlive: { | ||
disabled: false, | ||
chains: [], | ||
}, | ||
transferLiquidToken: { | ||
disabled: false, | ||
chains: [], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2023 Parity Technologies (UK) Ltd. | ||
|
||
import { disableOpts } from './disableOpts'; | ||
|
||
describe('disableOpts', () => { | ||
it('Should error for paysWithFeeOrigin', () => { | ||
const err = () => disableOpts({ paysWithFeeOrigin: 'DOT' }, 'westend'); | ||
expect(err).toThrow('paysWithFeeOrigin is disbaled for westend.'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2023 Parity Technologies (UK) Ltd. | ||
|
||
import { disabledOpts } from '../config/disabledOpts'; | ||
import type { Format, TransferArgsOpts } from '../types'; | ||
import { BaseError, BaseErrorsEnum } from './BaseError'; | ||
|
||
/** | ||
* This checks specific options to ensure they are disabled when met in certain conditions. | ||
* | ||
* @param opts Options for `createTransferTransaction` | ||
* @param specName SpecName of the current chain | ||
*/ | ||
export const disableOpts = <T extends Format>( | ||
opts: TransferArgsOpts<T>, | ||
specName: string | ||
) => { | ||
if (opts.paysWithFeeOrigin) { | ||
const { paysWithFeeOrigin } = disabledOpts; | ||
if (paysWithFeeOrigin.chains.includes(specName.toLowerCase())) { | ||
throw new BaseError( | ||
`paysWithFeeOrigin is disbaled for ${specName.toLowerCase()}.`, | ||
BaseErrorsEnum.DisabledOption | ||
); | ||
} | ||
} | ||
}; |