@aurora-is-near/intents-swap-widget 2.8.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -17,19 +17,11 @@ See the `/demo` folder for some examples of how to use these widgets.
|
|
|
17
17
|
|
|
18
18
|
To each of these components we should pass in a `makeTransfer` function. When
|
|
19
19
|
the user clicks the relevant submit button this function is called with an
|
|
20
|
-
`args` object that
|
|
21
|
-
|
|
22
|
-
```ts
|
|
23
|
-
type MakeTransferArgs = {
|
|
24
|
-
amount: string;
|
|
25
|
-
address: string;
|
|
26
|
-
tokenAddress?: string;
|
|
27
|
-
chain: Chains;
|
|
28
|
-
evmChainId: number | null;
|
|
29
|
-
};
|
|
30
|
-
```
|
|
20
|
+
`args` object that contains details about the transfer, such as the `amount`,
|
|
21
|
+
`address` and, if relevant, the `evmChainId`.
|
|
31
22
|
|
|
32
|
-
It is the responsibility of the consuming application to handle this
|
|
23
|
+
It is currently the responsibility of the consuming application to handle this
|
|
24
|
+
transfer.
|
|
33
25
|
|
|
34
26
|
## Custom implementation
|
|
35
27
|
|
|
@@ -35,6 +35,7 @@ const p = ({ makeTransfer: i }) => {
|
|
|
35
35
|
try {
|
|
36
36
|
const e = await i({
|
|
37
37
|
amount: o.quote.amountIn,
|
|
38
|
+
decimals: o.sourceToken.decimals,
|
|
38
39
|
address: o.quote.depositAddress,
|
|
39
40
|
chain: o.sourceToken.blockchain,
|
|
40
41
|
evmChainId: R(o.sourceToken.blockchain) ? u[o.sourceToken.blockchain] : null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMakeQuoteTransfer.js","sources":["../../src/hooks/useMakeQuoteTransfer.ts"],"sourcesContent":["import axios from 'axios';\n\nimport { logger } from '@/logger';\nimport { TransferError } from '@/errors';\nimport { useUnsafeSnapshot } from '@/machine/snap';\nimport { NATIVE_NEAR_DUMB_ASSET_ID } from '@/constants/tokens';\nimport { isUserDeniedSigning } from '@/utils/checkers/isUserDeniedSigning';\nimport type { MakeTransferArgs, TransferResult } from '@/types/transfer';\nimport { EVM_CHAIN_IDS_MAP } from '../constants/chains';\nimport { isEvmChain } from '../utils';\n\ntype Result = {\n hash: string;\n transactionLink: string;\n intent?: string;\n};\n\nexport type QuoteTransferArgs = {\n makeTransfer: (args: MakeTransferArgs) => Promise<Result | undefined | null>;\n};\n\nexport const useMakeQuoteTransfer = ({ makeTransfer }: QuoteTransferArgs) => {\n const { ctx } = useUnsafeSnapshot();\n\n const make = async (): Promise<TransferResult | undefined> => {\n if (!ctx.sourceToken) {\n const msg = 'No token selected to transfer.';\n\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: msg },\n });\n }\n\n if (!ctx.quote) {\n const msg = 'Quote is required for a transfer.';\n\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: msg },\n });\n }\n\n if (!ctx.quote.depositAddress) {\n const msg = 'Quote has no deposit address. Make sure not dry.';\n\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: msg },\n });\n }\n\n try {\n const depositResult = await makeTransfer({\n amount: ctx.quote.amountIn,\n address: ctx.quote.depositAddress,\n chain: ctx.sourceToken.blockchain,\n evmChainId: isEvmChain(ctx.sourceToken.blockchain)\n ? EVM_CHAIN_IDS_MAP[ctx.sourceToken.blockchain]\n : null,\n tokenAddress:\n ctx.sourceToken.assetId === NATIVE_NEAR_DUMB_ASSET_ID\n ? NATIVE_NEAR_DUMB_ASSET_ID\n : ctx.sourceToken.contractAddress,\n });\n\n if (!depositResult) {\n logger.error('[TRANSFER ERROR]', 'No deposit result');\n throw new TransferError({\n code: 'NO_DEPOSIT_RESULT',\n });\n }\n\n return {\n hash: depositResult.hash,\n transactionLink: depositResult.transactionLink,\n intent: undefined,\n };\n } catch (error: unknown) {\n logger.error('[TRANSFER ERROR]', error, { error });\n let errorMessage = 'Failed to make a transfer. Please try again.';\n\n const userCancelledTx =\n error instanceof Error && isUserDeniedSigning(error.message);\n\n if (userCancelledTx) {\n return;\n }\n\n if (axios.isAxiosError<{ detail?: string }>(error)) {\n errorMessage =\n error.response?.data?.detail ??\n error.message ??\n 'Failed to make deposit. Please try again.';\n\n throw new TransferError({\n code: 'QUOTE_ERROR',\n meta: { message: errorMessage },\n });\n } else if (errorMessage === 'No quotes found') {\n throw new TransferError({\n code: 'NO_QUOTE_FOUND',\n });\n } else if (error instanceof Error) {\n if (!userCancelledTx) {\n throw new TransferError({\n code: 'QUOTE_ERROR',\n meta: { message: error.message },\n });\n }\n }\n\n throw new TransferError({\n code: 'QUOTE_ERROR',\n meta: { message: 'Unknown quote transfer error' },\n });\n }\n };\n\n return { make };\n};\n"],"names":["useMakeQuoteTransfer","makeTransfer","ctx","useUnsafeSnapshot","msg","TransferError","depositResult","isEvmChain","EVM_CHAIN_IDS_MAP","NATIVE_NEAR_DUMB_ASSET_ID","logger","error","errorMessage","userCancelledTx","isUserDeniedSigning","axios"],"mappings":";;;;;;;;;;AAqBO,MAAMA,IAAuB,CAAC,EAAE,cAAAC,QAAsC;AAC3E,QAAM,EAAE,KAAAC,EAAA,IAAQC,EAAA;
|
|
1
|
+
{"version":3,"file":"useMakeQuoteTransfer.js","sources":["../../src/hooks/useMakeQuoteTransfer.ts"],"sourcesContent":["import axios from 'axios';\n\nimport { logger } from '@/logger';\nimport { TransferError } from '@/errors';\nimport { useUnsafeSnapshot } from '@/machine/snap';\nimport { NATIVE_NEAR_DUMB_ASSET_ID } from '@/constants/tokens';\nimport { isUserDeniedSigning } from '@/utils/checkers/isUserDeniedSigning';\nimport type { MakeTransferArgs, TransferResult } from '@/types/transfer';\nimport { EVM_CHAIN_IDS_MAP } from '../constants/chains';\nimport { isEvmChain } from '../utils';\n\ntype Result = {\n hash: string;\n transactionLink: string;\n intent?: string;\n};\n\nexport type QuoteTransferArgs = {\n makeTransfer: (args: MakeTransferArgs) => Promise<Result | undefined | null>;\n};\n\nexport const useMakeQuoteTransfer = ({ makeTransfer }: QuoteTransferArgs) => {\n const { ctx } = useUnsafeSnapshot();\n\n const make = async (): Promise<TransferResult | undefined> => {\n if (!ctx.sourceToken) {\n const msg = 'No token selected to transfer.';\n\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: msg },\n });\n }\n\n if (!ctx.quote) {\n const msg = 'Quote is required for a transfer.';\n\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: msg },\n });\n }\n\n if (!ctx.quote.depositAddress) {\n const msg = 'Quote has no deposit address. Make sure not dry.';\n\n throw new TransferError({\n code: 'TRANSFER_INVALID_INITIAL',\n meta: { message: msg },\n });\n }\n\n try {\n const depositResult = await makeTransfer({\n amount: ctx.quote.amountIn,\n decimals: ctx.sourceToken.decimals,\n address: ctx.quote.depositAddress,\n chain: ctx.sourceToken.blockchain,\n evmChainId: isEvmChain(ctx.sourceToken.blockchain)\n ? EVM_CHAIN_IDS_MAP[ctx.sourceToken.blockchain]\n : null,\n tokenAddress:\n ctx.sourceToken.assetId === NATIVE_NEAR_DUMB_ASSET_ID\n ? NATIVE_NEAR_DUMB_ASSET_ID\n : ctx.sourceToken.contractAddress,\n });\n\n if (!depositResult) {\n logger.error('[TRANSFER ERROR]', 'No deposit result');\n throw new TransferError({\n code: 'NO_DEPOSIT_RESULT',\n });\n }\n\n return {\n hash: depositResult.hash,\n transactionLink: depositResult.transactionLink,\n intent: undefined,\n };\n } catch (error: unknown) {\n logger.error('[TRANSFER ERROR]', error, { error });\n let errorMessage = 'Failed to make a transfer. Please try again.';\n\n const userCancelledTx =\n error instanceof Error && isUserDeniedSigning(error.message);\n\n if (userCancelledTx) {\n return;\n }\n\n if (axios.isAxiosError<{ detail?: string }>(error)) {\n errorMessage =\n error.response?.data?.detail ??\n error.message ??\n 'Failed to make deposit. Please try again.';\n\n throw new TransferError({\n code: 'QUOTE_ERROR',\n meta: { message: errorMessage },\n });\n } else if (errorMessage === 'No quotes found') {\n throw new TransferError({\n code: 'NO_QUOTE_FOUND',\n });\n } else if (error instanceof Error) {\n if (!userCancelledTx) {\n throw new TransferError({\n code: 'QUOTE_ERROR',\n meta: { message: error.message },\n });\n }\n }\n\n throw new TransferError({\n code: 'QUOTE_ERROR',\n meta: { message: 'Unknown quote transfer error' },\n });\n }\n };\n\n return { make };\n};\n"],"names":["useMakeQuoteTransfer","makeTransfer","ctx","useUnsafeSnapshot","msg","TransferError","depositResult","isEvmChain","EVM_CHAIN_IDS_MAP","NATIVE_NEAR_DUMB_ASSET_ID","logger","error","errorMessage","userCancelledTx","isUserDeniedSigning","axios"],"mappings":";;;;;;;;;;AAqBO,MAAMA,IAAuB,CAAC,EAAE,cAAAC,QAAsC;AAC3E,QAAM,EAAE,KAAAC,EAAA,IAAQC,EAAA;AAkGhB,SAAO,EAAE,MAhGI,YAAiD;AAC5D,QAAI,CAACD,EAAI,aAAa;AACpB,YAAME,IAAM;AAEZ,YAAM,IAAIC,EAAc;AAAA,QACtB,MAAM;AAAA,QACN,MAAM,EAAE,SAASD,EAAA;AAAA,MAAI,CACtB;AAAA,IACH;AAEA,QAAI,CAACF,EAAI,OAAO;AACd,YAAME,IAAM;AAEZ,YAAM,IAAIC,EAAc;AAAA,QACtB,MAAM;AAAA,QACN,MAAM,EAAE,SAASD,EAAA;AAAA,MAAI,CACtB;AAAA,IACH;AAEA,QAAI,CAACF,EAAI,MAAM,gBAAgB;AAC7B,YAAME,IAAM;AAEZ,YAAM,IAAIC,EAAc;AAAA,QACtB,MAAM;AAAA,QACN,MAAM,EAAE,SAASD,EAAA;AAAA,MAAI,CACtB;AAAA,IACH;AAEA,QAAI;AACF,YAAME,IAAgB,MAAML,EAAa;AAAA,QACvC,QAAQC,EAAI,MAAM;AAAA,QAClB,UAAUA,EAAI,YAAY;AAAA,QAC1B,SAASA,EAAI,MAAM;AAAA,QACnB,OAAOA,EAAI,YAAY;AAAA,QACvB,YAAYK,EAAWL,EAAI,YAAY,UAAU,IAC7CM,EAAkBN,EAAI,YAAY,UAAU,IAC5C;AAAA,QACJ,cACEA,EAAI,YAAY,YAAYO,IACxBA,IACAP,EAAI,YAAY;AAAA,MAAA,CACvB;AAED,UAAI,CAACI;AACH,cAAAI,EAAO,MAAM,oBAAoB,mBAAmB,GAC9C,IAAIL,EAAc;AAAA,UACtB,MAAM;AAAA,QAAA,CACP;AAGH,aAAO;AAAA,QACL,MAAMC,EAAc;AAAA,QACpB,iBAAiBA,EAAc;AAAA,QAC/B,QAAQ;AAAA,MAAA;AAAA,IAEZ,SAASK,GAAgB;AACvB,MAAAD,EAAO,MAAM,oBAAoBC,GAAO,EAAE,OAAAA,GAAO;AACjD,UAAIC,IAAe;AAEnB,YAAMC,IACJF,aAAiB,SAASG,EAAoBH,EAAM,OAAO;AAE7D,UAAIE;AACF;AAGF,YAAIE,EAAM,aAAkCJ,CAAK,KAC/CC,IACED,EAAM,UAAU,MAAM,UACtBA,EAAM,WACN,6CAEI,IAAIN,EAAc;AAAA,QACtB,MAAM;AAAA,QACN,MAAM,EAAE,SAASO,EAAA;AAAA,MAAa,CAC/B,KACQA,MAAiB,oBACpB,IAAIP,EAAc;AAAA,QACtB,MAAM;AAAA,MAAA,CACP,IACQM,aAAiB,SACtB,CAACE,IACG,IAAIR,EAAc;AAAA,QACtB,MAAM;AAAA,QACN,MAAM,EAAE,SAASM,EAAM,QAAA;AAAA,MAAQ,CAChC,IAIC,IAAIN,EAAc;AAAA,QACtB,MAAM;AAAA,QACN,MAAM,EAAE,SAAS,+BAAA;AAAA,MAA+B,CACjD;AAAA,IACH;AAAA,EACF,EAES;AACX;"}
|
package/dist/types/transfer.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -53,6 +53,7 @@ export const useMakeQuoteTransfer = ({ makeTransfer }: QuoteTransferArgs) => {
|
|
|
53
53
|
try {
|
|
54
54
|
const depositResult = await makeTransfer({
|
|
55
55
|
amount: ctx.quote.amountIn,
|
|
56
|
+
decimals: ctx.sourceToken.decimals,
|
|
56
57
|
address: ctx.quote.depositAddress,
|
|
57
58
|
chain: ctx.sourceToken.blockchain,
|
|
58
59
|
evmChainId: isEvmChain(ctx.sourceToken.blockchain)
|