@subwallet/extension-base 1.2.31-0 → 1.2.33-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/background/KoniTypes.d.ts +78 -227
- package/background/KoniTypes.js +3 -40
- package/background/errors/SWError.d.ts +4 -7
- package/background/errors/SWError.js +4 -0
- package/background/errors/TransactionError.d.ts +2 -2
- package/background/errors/TransactionError.js +2 -4
- package/background/handlers/State.d.ts +0 -12
- package/background/types.d.ts +9 -134
- package/background/warnings/TransactionWarning.d.ts +1 -1
- package/background/warnings/TransactionWarning.js +5 -1
- package/cjs/background/KoniTypes.js +4 -44
- package/cjs/background/errors/SWError.js +4 -0
- package/cjs/background/errors/TransactionError.js +13 -15
- package/cjs/background/warnings/TransactionWarning.js +6 -2
- package/cjs/constants/environment.js +13 -0
- package/cjs/constants/index.js +40 -13
- package/cjs/constants/signing.js +23 -0
- package/cjs/constants/storage.js +4 -2
- package/cjs/core/consts.js +20 -0
- package/cjs/core/logic-validation/recipientAddress.js +106 -0
- package/cjs/core/logic-validation/request.js +11 -19
- package/cjs/core/logic-validation/swap.js +5 -5
- package/cjs/core/logic-validation/transfer.js +83 -42
- package/cjs/core/types.js +26 -0
- package/cjs/core/utils.js +113 -0
- package/cjs/koni/api/dotsama/crowdloan.js +1 -1
- package/cjs/koni/api/nft/index.js +14 -5
- package/cjs/koni/api/staking/bonding/paraChain.js +8 -8
- package/cjs/koni/api/staking/bonding/relayChain.js +9 -9
- package/cjs/koni/api/staking/index.js +4 -1
- package/cjs/koni/background/cron.js +7 -7
- package/cjs/koni/background/handlers/Extension.js +510 -1446
- package/cjs/koni/background/handlers/State.js +61 -238
- package/cjs/koni/background/handlers/Tabs.js +143 -107
- package/cjs/koni/background/subscription.js +5 -5
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/Accounts.js +2 -5
- package/cjs/page/SubWalleEvmProvider.js +1 -1
- package/cjs/page/index.js +2 -1
- package/cjs/services/balance-service/BalanceMapImpl.js +48 -20
- package/cjs/services/balance-service/helpers/subscribe/index.js +27 -15
- package/cjs/services/balance-service/helpers/subscribe/ton/consts.js +40 -0
- package/cjs/services/balance-service/helpers/subscribe/ton/ton.js +120 -0
- package/cjs/services/balance-service/helpers/subscribe/ton/utils.js +181 -0
- package/cjs/services/balance-service/index.js +25 -13
- package/cjs/services/balance-service/transfer/token.js +41 -24
- package/cjs/services/balance-service/transfer/ton-transfer.js +136 -0
- package/cjs/services/buy-service/index.js +5 -1
- package/cjs/services/chain-service/constants.js +1 -1
- package/cjs/services/chain-service/handler/SubstrateApi.js +1 -0
- package/cjs/services/chain-service/handler/TonApi.js +213 -0
- package/cjs/services/chain-service/handler/TonChainHandler.js +81 -0
- package/cjs/services/chain-service/index.js +32 -8
- package/cjs/services/chain-service/utils/index.js +78 -22
- package/cjs/services/earning-service/constants/chains.js +3 -1
- package/cjs/services/earning-service/handlers/base.js +2 -1
- package/cjs/services/earning-service/handlers/lending/base.js +8 -9
- package/cjs/services/earning-service/handlers/lending/interlay.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +9 -10
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +1 -1
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +1 -1
- package/cjs/services/earning-service/handlers/native-staking/astar.js +2 -2
- package/cjs/services/earning-service/handlers/native-staking/base-para.js +13 -13
- package/cjs/services/earning-service/handlers/native-staking/base.js +2 -2
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +2 -2
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +15 -15
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +14 -14
- package/cjs/services/earning-service/handlers/special.js +10 -10
- package/cjs/services/earning-service/service.js +26 -17
- package/cjs/services/history-service/helpers/subscan-extrinsic-parser-helper.js +1 -1
- package/cjs/services/history-service/index.js +29 -11
- package/cjs/services/history-service/subscan-history.js +9 -21
- package/cjs/services/keyring-service/context/account-context.js +259 -0
- package/cjs/services/keyring-service/context/handlers/Base.js +20 -0
- package/cjs/services/keyring-service/context/handlers/Derive.js +377 -0
- package/cjs/services/keyring-service/context/handlers/Inject.js +75 -0
- package/cjs/services/keyring-service/context/handlers/Json.js +348 -0
- package/cjs/services/keyring-service/context/handlers/Ledger.js +165 -0
- package/cjs/services/keyring-service/context/handlers/Mnemonic.js +218 -0
- package/cjs/services/keyring-service/context/handlers/Modify.js +258 -0
- package/cjs/services/keyring-service/context/handlers/Secret.js +310 -0
- package/cjs/services/keyring-service/context/handlers/index.js +82 -0
- package/cjs/services/keyring-service/context/state.js +649 -0
- package/cjs/services/keyring-service/context/stores/AccountProxy.js +32 -0
- package/cjs/services/keyring-service/context/stores/Base.js +37 -0
- package/cjs/services/keyring-service/context/stores/CurrentAccount.js +28 -0
- package/cjs/services/keyring-service/context/stores/ModifyPair.js +19 -0
- package/cjs/services/keyring-service/context/stores/index.js +38 -0
- package/cjs/services/keyring-service/index.js +20 -164
- package/cjs/services/migration-service/scripts/index.js +6 -4
- package/cjs/services/migration-service/scripts/{MigrateLedgerAccountV2.js → keyring/MigrateLedgerAccountV2.js} +1 -1
- package/cjs/services/migration-service/scripts/keyring/MigratePairData.js +28 -0
- package/cjs/services/migration-service/scripts/{MigrateRemoveGenesisHash.js → keyring/MigrateRemoveGenesisHash.js} +1 -1
- package/cjs/services/request-service/constants.js +5 -3
- package/cjs/services/request-service/handler/AuthRequestHandler.js +104 -57
- package/cjs/services/request-service/handler/EvmRequestHandler.js +3 -4
- package/cjs/services/request-service/handler/SubstrateRequestHandler.js +5 -11
- package/cjs/services/request-service/handler/TonRequestHandler.js +175 -0
- package/cjs/services/request-service/index.js +24 -5
- package/cjs/services/swap-service/handler/asset-hub/handler.js +6 -5
- package/cjs/services/swap-service/handler/base-handler.js +8 -8
- package/cjs/services/swap-service/handler/chainflip-handler.js +5 -4
- package/cjs/services/swap-service/handler/hydradx-handler.js +4 -3
- package/cjs/services/swap-service/index.js +4 -4
- package/cjs/services/transaction-service/helpers/index.js +6 -1
- package/cjs/services/transaction-service/index.js +184 -84
- package/cjs/services/wallet-connect-service/handler/PolkadotRequestHandler.js +2 -10
- package/cjs/stores/AccountProxyStore.js +18 -0
- package/cjs/stores/ModifyPairStore.js +18 -0
- package/cjs/stores/index.js +23 -2
- package/cjs/types/account/action/add/index.js +38 -0
- package/cjs/types/account/action/add/json.js +1 -0
- package/cjs/types/account/action/add/mnemonic.js +1 -0
- package/cjs/types/account/action/add/secret.js +1 -0
- package/cjs/types/account/action/derive.js +1 -0
- package/cjs/types/account/action/edit.js +1 -0
- package/cjs/types/account/action/export.js +1 -0
- package/cjs/types/account/action/index.js +71 -0
- package/cjs/types/account/action/subscribe.js +16 -0
- package/cjs/types/account/action/validate.js +1 -0
- package/cjs/types/account/error/common.js +40 -0
- package/cjs/types/account/error/derive.js +55 -0
- package/cjs/types/account/error/index.js +27 -0
- package/cjs/types/account/index.js +38 -0
- package/cjs/types/account/info/current.js +1 -0
- package/cjs/types/account/info/index.js +38 -0
- package/cjs/types/account/info/keyring.js +90 -0
- package/cjs/types/account/info/proxy.js +49 -0
- package/cjs/types/error.js +1 -0
- package/cjs/types/index.js +44 -0
- package/cjs/types/transaction/data.js +1 -0
- package/cjs/types/transaction/error.js +53 -0
- package/cjs/types/transaction/index.js +49 -0
- package/cjs/types/transaction/request.js +1 -0
- package/cjs/types/transaction/warning.js +14 -0
- package/cjs/types/yield/actions/join/validate.js +1 -16
- package/cjs/utils/account/analyze.js +166 -0
- package/cjs/utils/account/common.js +121 -0
- package/cjs/utils/account/derive/index.js +27 -0
- package/cjs/utils/account/derive/info/index.js +27 -0
- package/cjs/utils/account/derive/info/solo.js +246 -0
- package/cjs/utils/account/derive/info/unified.js +112 -0
- package/cjs/utils/account/derive/validate.js +177 -0
- package/cjs/utils/account/index.js +49 -0
- package/cjs/utils/account/transform.js +566 -0
- package/cjs/utils/auth.js +46 -0
- package/cjs/utils/getId.js +8 -1
- package/cjs/utils/index.js +48 -62
- package/constants/environment.d.ts +1 -0
- package/constants/environment.js +6 -0
- package/constants/index.d.ts +5 -1
- package/constants/index.js +5 -2
- package/constants/signing.d.ts +4 -0
- package/constants/signing.js +15 -0
- package/constants/storage.d.ts +1 -0
- package/constants/storage.js +2 -1
- package/core/consts.d.ts +1 -0
- package/core/consts.js +13 -0
- package/core/logic-validation/recipientAddress.d.ts +2 -0
- package/core/logic-validation/recipientAddress.js +100 -0
- package/core/logic-validation/request.js +10 -18
- package/core/logic-validation/swap.js +1 -1
- package/core/logic-validation/transfer.d.ts +3 -2
- package/core/logic-validation/transfer.js +50 -10
- package/core/types.d.ts +26 -0
- package/core/types.js +19 -0
- package/core/utils.d.ts +10 -0
- package/core/utils.js +105 -0
- package/koni/api/dotsama/crowdloan.js +1 -1
- package/koni/api/nft/index.js +14 -5
- package/koni/api/staking/bonding/paraChain.js +2 -2
- package/koni/api/staking/bonding/relayChain.js +2 -2
- package/koni/api/staking/index.js +4 -1
- package/koni/background/cron.js +7 -7
- package/koni/background/handlers/Extension.d.ts +26 -35
- package/koni/background/handlers/Extension.js +337 -1242
- package/koni/background/handlers/State.d.ts +12 -19
- package/koni/background/handlers/State.js +57 -231
- package/koni/background/handlers/Tabs.d.ts +2 -3
- package/koni/background/handlers/Tabs.js +105 -61
- package/koni/background/subscription.js +5 -5
- package/package.json +352 -53
- package/packageInfo.js +1 -1
- package/page/Accounts.js +2 -5
- package/page/SubWalleEvmProvider.js +1 -1
- package/page/index.js +2 -1
- package/services/balance-service/BalanceMapImpl.d.ts +6 -4
- package/services/balance-service/BalanceMapImpl.js +44 -18
- package/services/balance-service/helpers/subscribe/index.d.ts +3 -4
- package/services/balance-service/helpers/subscribe/index.js +29 -17
- package/services/balance-service/helpers/subscribe/ton/consts.d.ts +18 -0
- package/services/balance-service/helpers/subscribe/ton/consts.js +28 -0
- package/services/balance-service/helpers/subscribe/ton/ton.d.ts +3 -0
- package/services/balance-service/helpers/subscribe/ton/ton.js +111 -0
- package/services/balance-service/helpers/subscribe/ton/types.d.ts +26 -0
- package/services/balance-service/helpers/subscribe/ton/utils.d.ts +32 -0
- package/services/balance-service/helpers/subscribe/ton/utils.js +159 -0
- package/services/balance-service/index.js +25 -13
- package/services/balance-service/transfer/token.d.ts +2 -2
- package/services/balance-service/transfer/token.js +18 -1
- package/services/balance-service/transfer/ton-transfer.d.ts +25 -0
- package/services/balance-service/transfer/ton-transfer.js +127 -0
- package/services/buy-service/index.js +5 -1
- package/services/buy-service/types.d.ts +2 -2
- package/services/chain-service/constants.js +1 -1
- package/services/chain-service/handler/SubstrateApi.js +1 -0
- package/services/chain-service/handler/TonApi.d.ts +52 -0
- package/services/chain-service/handler/TonApi.js +204 -0
- package/services/chain-service/handler/TonChainHandler.d.ts +17 -0
- package/services/chain-service/handler/TonChainHandler.js +73 -0
- package/services/chain-service/index.d.ts +5 -1
- package/services/chain-service/index.js +32 -8
- package/services/chain-service/types.d.ts +24 -0
- package/services/chain-service/utils/index.d.ts +10 -2
- package/services/chain-service/utils/index.js +59 -18
- package/services/earning-service/constants/chains.d.ts +1 -0
- package/services/earning-service/constants/chains.js +1 -0
- package/services/earning-service/handlers/base.js +3 -2
- package/services/earning-service/handlers/lending/base.js +1 -2
- package/services/earning-service/handlers/lending/interlay.js +2 -2
- package/services/earning-service/handlers/liquid-staking/base.js +1 -2
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +2 -2
- package/services/earning-service/handlers/native-staking/amplitude.js +2 -2
- package/services/earning-service/handlers/native-staking/astar.js +2 -2
- package/services/earning-service/handlers/native-staking/base-para.js +2 -2
- package/services/earning-service/handlers/native-staking/base.js +2 -2
- package/services/earning-service/handlers/native-staking/para-chain.js +2 -2
- package/services/earning-service/handlers/native-staking/relay-chain.js +2 -2
- package/services/earning-service/handlers/nomination-pool/index.js +2 -2
- package/services/earning-service/handlers/special.js +2 -2
- package/services/earning-service/service.js +18 -9
- package/services/event-service/types.d.ts +3 -1
- package/services/history-service/helpers/subscan-extrinsic-parser-helper.js +1 -1
- package/services/history-service/index.d.ts +4 -1
- package/services/history-service/index.js +29 -11
- package/services/history-service/subscan-history.js +8 -20
- package/services/keyring-service/context/account-context.d.ts +87 -0
- package/services/keyring-service/context/account-context.js +250 -0
- package/services/keyring-service/context/handlers/Base.d.ts +11 -0
- package/services/keyring-service/context/handlers/Base.js +13 -0
- package/services/keyring-service/context/handlers/Derive.d.ts +29 -0
- package/services/keyring-service/context/handlers/Derive.js +365 -0
- package/services/keyring-service/context/handlers/Inject.d.ts +11 -0
- package/services/keyring-service/context/handlers/Inject.js +69 -0
- package/services/keyring-service/context/handlers/Json.d.ts +18 -0
- package/services/keyring-service/context/handlers/Json.js +328 -0
- package/services/keyring-service/context/handlers/Ledger.d.ts +11 -0
- package/services/keyring-service/context/handlers/Ledger.js +158 -0
- package/services/keyring-service/context/handlers/Mnemonic.d.ts +15 -0
- package/services/keyring-service/context/handlers/Mnemonic.js +206 -0
- package/services/keyring-service/context/handlers/Modify.d.ts +16 -0
- package/services/keyring-service/context/handlers/Modify.js +250 -0
- package/services/keyring-service/context/handlers/Secret.d.ts +16 -0
- package/services/keyring-service/context/handlers/Secret.js +299 -0
- package/services/keyring-service/context/handlers/index.d.ts +7 -0
- package/services/keyring-service/context/handlers/index.js +10 -0
- package/services/keyring-service/context/state.d.ts +92 -0
- package/services/keyring-service/context/state.js +629 -0
- package/services/keyring-service/context/stores/AccountProxy.d.ts +13 -0
- package/services/keyring-service/context/stores/AccountProxy.js +25 -0
- package/services/keyring-service/context/stores/Base.d.ts +22 -0
- package/services/keyring-service/context/stores/Base.js +30 -0
- package/services/keyring-service/context/stores/CurrentAccount.d.ts +15 -0
- package/services/keyring-service/context/stores/CurrentAccount.js +21 -0
- package/services/keyring-service/context/stores/ModifyPair.d.ts +10 -0
- package/services/keyring-service/context/stores/ModifyPair.js +12 -0
- package/services/keyring-service/context/stores/index.d.ts +3 -0
- package/services/keyring-service/context/stores/index.js +6 -0
- package/services/keyring-service/index.d.ts +10 -22
- package/services/keyring-service/index.js +20 -161
- package/services/migration-service/scripts/index.js +6 -4
- package/services/migration-service/scripts/{MigrateLedgerAccountV2.d.ts → keyring/MigrateLedgerAccountV2.d.ts} +1 -1
- package/services/migration-service/scripts/{MigrateLedgerAccountV2.js → keyring/MigrateLedgerAccountV2.js} +1 -1
- package/services/migration-service/scripts/keyring/MigratePairData.d.ts +4 -0
- package/services/migration-service/scripts/keyring/MigratePairData.js +20 -0
- package/services/migration-service/scripts/{MigrateRemoveGenesisHash.js → keyring/MigrateRemoveGenesisHash.js} +1 -1
- package/services/mkt-campaign-service/types.d.ts +4 -0
- package/services/request-service/constants.d.ts +1 -1
- package/services/request-service/constants.js +2 -1
- package/services/request-service/handler/AuthRequestHandler.d.ts +1 -0
- package/services/request-service/handler/AuthRequestHandler.js +93 -45
- package/services/request-service/handler/EvmRequestHandler.js +3 -4
- package/services/request-service/handler/SubstrateRequestHandler.d.ts +2 -2
- package/services/request-service/handler/SubstrateRequestHandler.js +5 -11
- package/services/request-service/handler/TonRequestHandler.d.ts +17 -0
- package/services/request-service/handler/TonRequestHandler.js +168 -0
- package/services/request-service/index.d.ts +8 -3
- package/services/request-service/index.js +23 -5
- package/services/request-service/types.d.ts +6 -3
- package/services/swap-service/handler/asset-hub/handler.d.ts +1 -1
- package/services/swap-service/handler/asset-hub/handler.js +2 -1
- package/services/swap-service/handler/base-handler.js +1 -1
- package/services/swap-service/handler/chainflip-handler.d.ts +1 -1
- package/services/swap-service/handler/chainflip-handler.js +4 -3
- package/services/swap-service/handler/hydradx-handler.d.ts +1 -1
- package/services/swap-service/handler/hydradx-handler.js +2 -1
- package/services/swap-service/index.js +1 -1
- package/services/transaction-service/helpers/index.d.ts +2 -0
- package/services/transaction-service/helpers/index.js +4 -0
- package/services/transaction-service/index.d.ts +1 -0
- package/services/transaction-service/index.js +114 -17
- package/services/transaction-service/types.d.ts +4 -2
- package/services/wallet-connect-service/handler/PolkadotRequestHandler.js +2 -10
- package/stores/AccountProxyStore.d.ts +5 -0
- package/stores/AccountProxyStore.js +10 -0
- package/stores/Authorize.d.ts +1 -1
- package/stores/CurrentAccountStore.d.ts +1 -1
- package/stores/ModifyPairStore.d.ts +5 -0
- package/stores/ModifyPairStore.js +10 -0
- package/stores/index.d.ts +4 -1
- package/stores/index.js +5 -2
- package/types/account/action/add/index.d.ts +3 -0
- package/types/account/action/add/index.js +6 -0
- package/types/account/action/add/json.d.ts +29 -0
- package/types/account/action/add/json.js +1 -0
- package/types/account/action/add/mnemonic.d.ts +77 -0
- package/types/account/action/add/mnemonic.js +1 -0
- package/types/account/action/add/secret.d.ts +55 -0
- package/types/account/action/add/secret.js +1 -0
- package/types/account/action/derive.d.ts +77 -0
- package/types/account/action/derive.js +1 -0
- package/types/account/action/edit.d.ts +31 -0
- package/types/account/action/edit.js +1 -0
- package/types/account/action/export.d.ts +15 -0
- package/types/account/action/export.js +1 -0
- package/types/account/action/index.d.ts +6 -0
- package/types/account/action/index.js +9 -0
- package/types/account/action/subscribe.d.ts +22 -0
- package/types/account/action/subscribe.js +10 -0
- package/types/account/action/validate.d.ts +17 -0
- package/types/account/action/validate.js +1 -0
- package/types/account/error/common.d.ts +10 -0
- package/types/account/error/common.js +33 -0
- package/types/account/error/derive.d.ts +13 -0
- package/types/account/error/derive.js +48 -0
- package/types/account/error/index.d.ts +2 -0
- package/types/account/error/index.js +5 -0
- package/types/account/index.d.ts +3 -0
- package/types/account/index.js +6 -0
- package/types/account/info/current.d.ts +10 -0
- package/types/account/info/current.js +1 -0
- package/types/account/info/index.d.ts +3 -0
- package/types/account/info/index.js +6 -0
- package/types/account/info/keyring.d.ts +161 -0
- package/types/account/info/keyring.js +88 -0
- package/types/account/info/proxy.d.ts +73 -0
- package/types/account/info/proxy.js +46 -0
- package/types/balance/index.d.ts +4 -1
- package/types/buy.d.ts +3 -1
- package/types/error.d.ts +8 -0
- package/types/error.js +1 -0
- package/types/index.d.ts +4 -0
- package/types/index.js +5 -1
- package/types/transaction/data.d.ts +17 -0
- package/types/transaction/data.js +1 -0
- package/types/transaction/error.d.ts +39 -0
- package/types/transaction/error.js +44 -0
- package/types/transaction/index.d.ts +4 -0
- package/types/transaction/index.js +7 -0
- package/types/transaction/request.d.ts +24 -0
- package/types/transaction/request.js +1 -0
- package/types/transaction/warning.d.ts +5 -0
- package/types/transaction/warning.js +8 -0
- package/types/yield/actions/join/submit.d.ts +2 -2
- package/types/yield/actions/join/validate.d.ts +1 -6
- package/types/yield/actions/join/validate.js +1 -10
- package/types/yield/actions/others.d.ts +1 -1
- package/utils/account/analyze.d.ts +4 -0
- package/utils/account/analyze.js +159 -0
- package/utils/account/common.d.ts +16 -0
- package/utils/account/common.js +104 -0
- package/utils/account/derive/index.d.ts +2 -0
- package/utils/account/derive/index.js +5 -0
- package/utils/account/derive/info/index.d.ts +2 -0
- package/utils/account/derive/info/index.js +5 -0
- package/utils/account/derive/info/solo.d.ts +11 -0
- package/utils/account/derive/info/solo.js +230 -0
- package/utils/account/derive/info/unified.d.ts +7 -0
- package/utils/account/derive/info/unified.js +102 -0
- package/utils/account/derive/validate.d.ts +8 -0
- package/utils/account/derive/validate.js +165 -0
- package/utils/account/index.d.ts +4 -0
- package/utils/account/index.js +7 -0
- package/utils/account/transform.d.ts +41 -0
- package/utils/account/transform.js +533 -0
- package/utils/auth.d.ts +2 -0
- package/utils/auth.js +39 -0
- package/utils/canDerive.d.ts +1 -1
- package/utils/eth/mergeTransactionAndSignature.d.ts +1 -1
- package/utils/getId.d.ts +1 -0
- package/utils/getId.js +3 -1
- package/utils/index.d.ts +12 -5
- package/utils/index.js +28 -47
- package/cjs/signers/substrates/KeyringSigner.js +0 -35
- package/cjs/signers/substrates/LedgerSigner.js +0 -44
- package/cjs/signers/substrates/QrSigner.js +0 -63
- package/cjs/signers/types.js +0 -15
- package/cjs/signers/web3/QrSigner.js +0 -67
- package/cjs/utils/account.js +0 -34
- package/signers/substrates/KeyringSigner.d.ts +0 -13
- package/signers/substrates/KeyringSigner.js +0 -27
- package/signers/substrates/LedgerSigner.d.ts +0 -13
- package/signers/substrates/LedgerSigner.js +0 -37
- package/signers/substrates/QrSigner.d.ts +0 -20
- package/signers/substrates/QrSigner.js +0 -55
- package/signers/types.d.ts +0 -34
- package/signers/types.js +0 -9
- package/signers/web3/QrSigner.d.ts +0 -18
- package/signers/web3/QrSigner.js +0 -59
- package/types/transaction.d.ts +0 -3
- package/utils/account.d.ts +0 -5
- package/utils/account.js +0 -24
- /package/cjs/{types/transaction.js → services/balance-service/helpers/subscribe/ton/types.js} +0 -0
- /package/cjs/services/migration-service/scripts/{MigrateLedgerAccount.js → keyring/MigrateLedgerAccount.js} +0 -0
- /package/{types/transaction.js → services/balance-service/helpers/subscribe/ton/types.js} +0 -0
- /package/services/migration-service/scripts/{MigrateLedgerAccount.d.ts → keyring/MigrateLedgerAccount.d.ts} +0 -0
- /package/services/migration-service/scripts/{MigrateLedgerAccount.js → keyring/MigrateLedgerAccount.js} +0 -0
- /package/services/migration-service/scripts/{MigrateRemoveGenesisHash.d.ts → keyring/MigrateRemoveGenesisHash.d.ts} +0 -0
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.BalanceMapImpl = void 0;
|
|
7
7
|
var _constants = require("@subwallet/extension-base/constants");
|
|
8
|
+
var _types = require("@subwallet/extension-base/types");
|
|
8
9
|
var _utils = require("@subwallet/extension-base/utils");
|
|
9
10
|
var _rxjs = require("rxjs");
|
|
10
11
|
var _helpers = require("./helpers");
|
|
@@ -12,8 +13,9 @@ var _helpers = require("./helpers");
|
|
|
12
13
|
// SPDX-License-Identifier: Apache-2.0
|
|
13
14
|
|
|
14
15
|
class BalanceMapImpl {
|
|
15
|
-
constructor() {
|
|
16
|
-
let _map = arguments.length >
|
|
16
|
+
constructor(state) {
|
|
17
|
+
let _map = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
18
|
+
this.state = state;
|
|
17
19
|
this._map = _map;
|
|
18
20
|
this._mapSubject = new _rxjs.BehaviorSubject(_map);
|
|
19
21
|
}
|
|
@@ -31,9 +33,9 @@ class BalanceMapImpl {
|
|
|
31
33
|
this._map[address] = data;
|
|
32
34
|
this.triggerChange();
|
|
33
35
|
}
|
|
34
|
-
triggerChange(
|
|
35
|
-
if (
|
|
36
|
-
this.
|
|
36
|
+
triggerChange(proxyId) {
|
|
37
|
+
if (proxyId) {
|
|
38
|
+
this.computeBalance(proxyId);
|
|
37
39
|
}
|
|
38
40
|
this._mapSubject.next(this._map);
|
|
39
41
|
}
|
|
@@ -49,11 +51,11 @@ class BalanceMapImpl {
|
|
|
49
51
|
this._map[address][tokenSlug] = balanceItem;
|
|
50
52
|
trigger && this.triggerChange();
|
|
51
53
|
}
|
|
52
|
-
updateBalanceItems(balanceItems,
|
|
54
|
+
updateBalanceItems(balanceItems, proxyId) {
|
|
53
55
|
balanceItems.forEach(balanceItem => {
|
|
54
56
|
this.updateBalanceItem(balanceItem);
|
|
55
57
|
});
|
|
56
|
-
this.triggerChange(
|
|
58
|
+
this.triggerChange(proxyId);
|
|
57
59
|
}
|
|
58
60
|
removeBalanceItemByFilter(filter) {
|
|
59
61
|
Object.keys(this._map).forEach(address => {
|
|
@@ -65,22 +67,48 @@ class BalanceMapImpl {
|
|
|
65
67
|
});
|
|
66
68
|
this.triggerChange();
|
|
67
69
|
}
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
computeBalance(_proxyId) {
|
|
71
|
+
const isAll = (0, _utils.isAccountAll)(_proxyId);
|
|
72
|
+
const compoundMap = {};
|
|
73
|
+
const accountProxies = this.state.keyringService.context.accounts;
|
|
74
|
+
const unifiedAccountsMap = Object.values(accountProxies).filter(value => value.accountType === _types.AccountProxyType.UNIFIED).reduce((rs, value) => {
|
|
75
|
+
rs[value.id] = value.accounts.map(account => account.address);
|
|
76
|
+
return rs;
|
|
77
|
+
}, {});
|
|
78
|
+
const revertUnifiedAccountsMap = Object.entries(unifiedAccountsMap).reduce((rs, _ref) => {
|
|
79
|
+
let [proxyId, accounts] = _ref;
|
|
80
|
+
if (isAll || proxyId === _proxyId) {
|
|
81
|
+
for (const account of accounts) {
|
|
82
|
+
rs[account] = proxyId;
|
|
75
83
|
}
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
}
|
|
85
|
+
return rs;
|
|
86
|
+
}, {});
|
|
87
|
+
const proxyIds = Object.keys(unifiedAccountsMap);
|
|
88
|
+
Object.keys(this._map).filter(a => !(0, _utils.isAccountAll)(a) && !proxyIds.includes(a)).forEach(address => {
|
|
89
|
+
const addItemToMap = key => {
|
|
90
|
+
const unifiedAccountBalance = compoundMap[key] || {};
|
|
91
|
+
Object.keys(this._map[address]).forEach(tokenSlug => {
|
|
92
|
+
if (!unifiedAccountBalance[tokenSlug]) {
|
|
93
|
+
unifiedAccountBalance[tokenSlug] = [];
|
|
94
|
+
}
|
|
95
|
+
unifiedAccountBalance[tokenSlug].push(this._map[address][tokenSlug]);
|
|
96
|
+
});
|
|
97
|
+
compoundMap[key] = unifiedAccountBalance;
|
|
98
|
+
};
|
|
99
|
+
const proxyId = revertUnifiedAccountsMap[address];
|
|
100
|
+
isAll && addItemToMap(_constants.ALL_ACCOUNT_KEY);
|
|
101
|
+
proxyId && addItemToMap(proxyId);
|
|
78
102
|
});
|
|
79
|
-
Object.entries(
|
|
80
|
-
let [
|
|
81
|
-
|
|
103
|
+
Object.entries(compoundMap).forEach(_ref2 => {
|
|
104
|
+
let [compoundKey, balanceMap] = _ref2;
|
|
105
|
+
const rs = {};
|
|
106
|
+
Object.entries(balanceMap).forEach(_ref3 => {
|
|
107
|
+
let [tokenSlug, balanceItems] = _ref3;
|
|
108
|
+
rs[tokenSlug] = (0, _helpers.groupBalance)(balanceItems, compoundKey, tokenSlug);
|
|
109
|
+
});
|
|
110
|
+
this._map[compoundKey] = rs;
|
|
82
111
|
});
|
|
83
|
-
this._map[_constants.ALL_ACCOUNT_KEY] = allAccountBalanceInfo;
|
|
84
112
|
}
|
|
85
113
|
|
|
86
114
|
// Remove balance items buy address or tokenSlug
|
|
@@ -11,6 +11,7 @@ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
|
11
11
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
12
12
|
var _utils2 = require("@subwallet/extension-base/utils");
|
|
13
13
|
var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
|
|
14
|
+
var _ton = require("./ton/ton");
|
|
14
15
|
var _evm = require("./evm");
|
|
15
16
|
var _substrate = require("./substrate");
|
|
16
17
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
@@ -29,11 +30,7 @@ const getAccountJsonByAddress = address => {
|
|
|
29
30
|
try {
|
|
30
31
|
const pair = _uiKeyring.default.getPair(address);
|
|
31
32
|
if (pair) {
|
|
32
|
-
return
|
|
33
|
-
address: pair.address,
|
|
34
|
-
type: pair.type,
|
|
35
|
-
...pair.meta
|
|
36
|
-
};
|
|
33
|
+
return (0, _utils2.pairToAccount)(pair);
|
|
37
34
|
} else {
|
|
38
35
|
return null;
|
|
39
36
|
}
|
|
@@ -46,14 +43,22 @@ const getAccountJsonByAddress = address => {
|
|
|
46
43
|
/** Filter addresses to subscribe by chain info */
|
|
47
44
|
exports.getAccountJsonByAddress = getAccountJsonByAddress;
|
|
48
45
|
const filterAddress = (addresses, chainInfo) => {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
const {
|
|
47
|
+
bitcoin,
|
|
48
|
+
evm,
|
|
49
|
+
substrate,
|
|
50
|
+
ton
|
|
51
|
+
} = (0, _utils2.categoryAddresses)(addresses);
|
|
52
|
+
if ((0, _utils._isChainEvmCompatible)(chainInfo)) {
|
|
53
|
+
return [evm, [...bitcoin, ...substrate, ...ton]];
|
|
54
|
+
} else if ((0, _utils._isChainBitcoinCompatible)(chainInfo)) {
|
|
55
|
+
return [bitcoin, [...evm, ...substrate, ...ton]];
|
|
56
|
+
} else if ((0, _utils._isChainTonCompatible)(chainInfo)) {
|
|
57
|
+
return [ton, [...bitcoin, ...evm, ...substrate]];
|
|
53
58
|
} else {
|
|
54
59
|
const fetchList = [];
|
|
55
60
|
const unfetchList = [];
|
|
56
|
-
|
|
61
|
+
substrate.forEach(address => {
|
|
57
62
|
const account = getAccountJsonByAddress(address);
|
|
58
63
|
if (account) {
|
|
59
64
|
if (account.isHardware) {
|
|
@@ -75,7 +80,7 @@ const filterAddress = (addresses, chainInfo) => {
|
|
|
75
80
|
fetchList.push(address);
|
|
76
81
|
}
|
|
77
82
|
});
|
|
78
|
-
return [fetchList, [...unfetchList, ...
|
|
83
|
+
return [fetchList, [...unfetchList, ...bitcoin, ...evm, ...ton]];
|
|
79
84
|
}
|
|
80
85
|
};
|
|
81
86
|
const handleUnsupportedOrPendingAddresses = (addresses, chainSlug, chainAssetMap, state, callback) => {
|
|
@@ -95,7 +100,7 @@ const handleUnsupportedOrPendingAddresses = (addresses, chainSlug, chainAssetMap
|
|
|
95
100
|
};
|
|
96
101
|
|
|
97
102
|
// main subscription, use for multiple chains, multiple addresses and multiple tokens
|
|
98
|
-
function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _chainInfoMap, substrateApiMap, evmApiMap, callback, extrinsicType) {
|
|
103
|
+
function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _chainInfoMap, substrateApiMap, evmApiMap, tonApiMap, callback, extrinsicType) {
|
|
99
104
|
// Filter chain and token
|
|
100
105
|
const chainAssetMap = Object.fromEntries(Object.entries(_chainAssetMap).filter(_ref => {
|
|
101
106
|
let [token] = _ref;
|
|
@@ -123,10 +128,17 @@ function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _chainInfoM
|
|
|
123
128
|
evmApi
|
|
124
129
|
});
|
|
125
130
|
}
|
|
126
|
-
const
|
|
127
|
-
if (
|
|
128
|
-
|
|
131
|
+
const tonApi = tonApiMap[chainSlug];
|
|
132
|
+
if ((0, _utils._isPureTonChain)(chainInfo)) {
|
|
133
|
+
return (0, _ton.subscribeTonBalance)({
|
|
134
|
+
addresses: useAddresses,
|
|
135
|
+
assetMap: chainAssetMap,
|
|
136
|
+
callback,
|
|
137
|
+
chainInfo,
|
|
138
|
+
tonApi
|
|
139
|
+
});
|
|
129
140
|
}
|
|
141
|
+
const substrateApi = await substrateApiMap[chainSlug].isReady;
|
|
130
142
|
return (0, _substrate.subscribeSubstrateBalance)(useAddresses, chainInfo, chainAssetMap, substrateApi, evmApi, callback, extrinsicType);
|
|
131
143
|
});
|
|
132
144
|
return () => {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.WORKCHAIN = exports.TON_OPCODES = exports.TON_CENTER_API_KEY = exports.SendMode = exports.SW_QUERYID_HEX = exports.INIT_FEE_JETTON_TRANSFER = exports.EXTRA_TON_ESTIMATE_FEE = void 0;
|
|
7
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
8
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
10
|
+
const WORKCHAIN = 0;
|
|
11
|
+
exports.WORKCHAIN = WORKCHAIN;
|
|
12
|
+
const INIT_FEE_JETTON_TRANSFER = '0.1';
|
|
13
|
+
exports.INIT_FEE_JETTON_TRANSFER = INIT_FEE_JETTON_TRANSFER;
|
|
14
|
+
let TON_OPCODES;
|
|
15
|
+
exports.TON_OPCODES = TON_OPCODES;
|
|
16
|
+
(function (TON_OPCODES) {
|
|
17
|
+
TON_OPCODES[TON_OPCODES["JETTON_TRANSFER"] = 260734629] = "JETTON_TRANSFER";
|
|
18
|
+
TON_OPCODES[TON_OPCODES["NFT_TRANSFER"] = 1607220500] = "NFT_TRANSFER";
|
|
19
|
+
TON_OPCODES[TON_OPCODES["STONFI_SWAP"] = 630424929] = "STONFI_SWAP";
|
|
20
|
+
})(TON_OPCODES || (exports.TON_OPCODES = TON_OPCODES = {}));
|
|
21
|
+
const SW_QUERYID_HEX = 0x20010503;
|
|
22
|
+
exports.SW_QUERYID_HEX = SW_QUERYID_HEX;
|
|
23
|
+
const EXTRA_TON_ESTIMATE_FEE = BigInt(500);
|
|
24
|
+
|
|
25
|
+
// todo: This is just free API for dev, remove this and set better RPC later
|
|
26
|
+
// export const TON_CENTER_API_KEY = '98b3eaf42da2981d265bfa6aea2c8d390befb6f677f675fefd3b12201bdf1bc3';
|
|
27
|
+
// export const TON_CENTER_API_KEY = '870ff97c30ad16dc4297bcac8bcf2243a4daffeba6c6d6c31553e342811e673a';
|
|
28
|
+
exports.EXTRA_TON_ESTIMATE_FEE = EXTRA_TON_ESTIMATE_FEE;
|
|
29
|
+
const TON_CENTER_API_KEY = '078f715c911784eb4c8d2d545da3ce5db5d07996452bb2246e0a0071c66b87e9'; // alibaba
|
|
30
|
+
exports.TON_CENTER_API_KEY = TON_CENTER_API_KEY;
|
|
31
|
+
let SendMode;
|
|
32
|
+
exports.SendMode = SendMode;
|
|
33
|
+
(function (SendMode) {
|
|
34
|
+
SendMode[SendMode["CARRY_ALL_REMAINING_BALANCE"] = 128] = "CARRY_ALL_REMAINING_BALANCE";
|
|
35
|
+
SendMode[SendMode["CARRY_ALL_REMAINING_INCOMING_VALUE"] = 64] = "CARRY_ALL_REMAINING_INCOMING_VALUE";
|
|
36
|
+
SendMode[SendMode["DESTROY_ACCOUNT_IF_ZERO"] = 32] = "DESTROY_ACCOUNT_IF_ZERO";
|
|
37
|
+
SendMode[SendMode["PAY_GAS_SEPARATELY"] = 1] = "PAY_GAS_SEPARATELY";
|
|
38
|
+
SendMode[SendMode["IGNORE_ERRORS"] = 2] = "IGNORE_ERRORS";
|
|
39
|
+
SendMode[SendMode["NONE"] = 0] = "NONE";
|
|
40
|
+
})(SendMode || (exports.SendMode = SendMode = {}));
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.subscribeJettonBalanceInterval = subscribeJettonBalanceInterval;
|
|
7
|
+
exports.subscribeTonBalance = subscribeTonBalance;
|
|
8
|
+
var _types = require("@subwallet/chain-list/types");
|
|
9
|
+
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
10
|
+
var _constants = require("@subwallet/extension-base/constants");
|
|
11
|
+
var _utils = require("@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/utils");
|
|
12
|
+
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
13
|
+
var _utils3 = require("@subwallet/extension-base/utils");
|
|
14
|
+
var _core = require("@ton/core");
|
|
15
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
16
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
|
|
18
|
+
function subscribeJettonBalanceInterval(_ref) {
|
|
19
|
+
let {
|
|
20
|
+
addresses,
|
|
21
|
+
assetMap,
|
|
22
|
+
callback,
|
|
23
|
+
chainInfo,
|
|
24
|
+
tonApi
|
|
25
|
+
} = _ref;
|
|
26
|
+
const chain = chainInfo.slug;
|
|
27
|
+
const tokenList = (0, _utils3.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.TEP74]);
|
|
28
|
+
const jettonMasterContractMap = {};
|
|
29
|
+
Object.entries(tokenList).forEach(_ref2 => {
|
|
30
|
+
let [slug, tokenInfo] = _ref2;
|
|
31
|
+
jettonMasterContractMap[slug] = (0, _utils.getJettonMasterContract)(tonApi, (0, _utils2._getContractAddressOfToken)(tokenInfo));
|
|
32
|
+
});
|
|
33
|
+
const getJettonBalances = () => {
|
|
34
|
+
Object.values(tokenList).map(async tokenInfo => {
|
|
35
|
+
try {
|
|
36
|
+
const masterContract = jettonMasterContractMap[tokenInfo.slug];
|
|
37
|
+
const balances = await Promise.all(addresses.map(async address => {
|
|
38
|
+
try {
|
|
39
|
+
const jettonWalletContract = await (0, _utils.getJettonWalletContract)(masterContract, tonApi, address);
|
|
40
|
+
return await jettonWalletContract.getBalance();
|
|
41
|
+
} catch (e) {
|
|
42
|
+
console.error(`Error on get balance of account ${address} for token ${tokenInfo.slug}`, e);
|
|
43
|
+
return BigInt(0);
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
const items = balances.map((balance, index) => {
|
|
47
|
+
return {
|
|
48
|
+
address: addresses[index],
|
|
49
|
+
tokenSlug: tokenInfo.slug,
|
|
50
|
+
free: balance.toString(),
|
|
51
|
+
locked: '0',
|
|
52
|
+
state: _KoniTypes.APIItemState.READY
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
callback(items);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
console.log(tokenInfo.slug, err);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
getJettonBalances();
|
|
62
|
+
const interval = setInterval(getJettonBalances, _constants.SUB_TOKEN_REFRESH_BALANCE_INTERVAL);
|
|
63
|
+
return () => {
|
|
64
|
+
clearInterval(interval);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async function getTonBalance(addresses, tonApi) {
|
|
68
|
+
return await Promise.all(addresses.map(async address => {
|
|
69
|
+
try {
|
|
70
|
+
const tonAddress = _core.Address.parse(address);
|
|
71
|
+
return await tonApi.getBalance(tonAddress);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
return BigInt(0);
|
|
74
|
+
}
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
function subscribeTonBalance(params) {
|
|
78
|
+
var _Object$values$;
|
|
79
|
+
const {
|
|
80
|
+
addresses,
|
|
81
|
+
assetMap,
|
|
82
|
+
callback,
|
|
83
|
+
chainInfo,
|
|
84
|
+
tonApi
|
|
85
|
+
} = params;
|
|
86
|
+
const chain = chainInfo.slug;
|
|
87
|
+
const nativeTokenInfo = (0, _utils3.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.NATIVE]);
|
|
88
|
+
const nativeTokenSlug = ((_Object$values$ = Object.values(nativeTokenInfo)[0]) === null || _Object$values$ === void 0 ? void 0 : _Object$values$.slug) || '';
|
|
89
|
+
function getBalance() {
|
|
90
|
+
getTonBalance(addresses, tonApi).then(balances => {
|
|
91
|
+
return balances.map((balance, index) => {
|
|
92
|
+
return {
|
|
93
|
+
address: addresses[index],
|
|
94
|
+
tokenSlug: nativeTokenSlug,
|
|
95
|
+
state: _KoniTypes.APIItemState.READY,
|
|
96
|
+
free: balance.toString(),
|
|
97
|
+
locked: '0'
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
}).catch(e => {
|
|
101
|
+
console.error(`Error on get native balance with token ${nativeTokenSlug}`, e);
|
|
102
|
+
return addresses.map(address => {
|
|
103
|
+
return {
|
|
104
|
+
address: address,
|
|
105
|
+
tokenSlug: nativeTokenSlug,
|
|
106
|
+
state: _KoniTypes.APIItemState.READY,
|
|
107
|
+
free: '0',
|
|
108
|
+
locked: '0'
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
}).then(items => callback(items)).catch(console.error);
|
|
112
|
+
}
|
|
113
|
+
getBalance();
|
|
114
|
+
const interval = setInterval(getBalance, _constants.ASTAR_REFRESH_BALANCE_INTERVAL);
|
|
115
|
+
const unsub2 = subscribeJettonBalanceInterval(params);
|
|
116
|
+
return () => {
|
|
117
|
+
clearInterval(interval);
|
|
118
|
+
unsub2 && unsub2();
|
|
119
|
+
};
|
|
120
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.cellToBase64Str = cellToBase64Str;
|
|
8
|
+
exports.estimateTonTxFee = estimateTonTxFee;
|
|
9
|
+
exports.externalMessage = externalMessage;
|
|
10
|
+
exports.getJettonMasterContract = getJettonMasterContract;
|
|
11
|
+
exports.getJettonTxStatus = getJettonTxStatus;
|
|
12
|
+
exports.getJettonWalletContract = getJettonWalletContract;
|
|
13
|
+
exports.getMessageTxStatus = getMessageTxStatus;
|
|
14
|
+
exports.getNativeTonTxStatus = getNativeTonTxStatus;
|
|
15
|
+
exports.getTonSendMode = getTonSendMode;
|
|
16
|
+
exports.getTransferCell = getTransferCell;
|
|
17
|
+
exports.getTransferCellPromise = getTransferCellPromise;
|
|
18
|
+
exports.getWalletQueryId = getWalletQueryId;
|
|
19
|
+
exports.isBounceableAddress = isBounceableAddress;
|
|
20
|
+
exports.messageRelaxedToCell = messageRelaxedToCell;
|
|
21
|
+
exports.retry = retry;
|
|
22
|
+
exports.tonAddressInfo = tonAddressInfo;
|
|
23
|
+
var _consts = require("@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/consts");
|
|
24
|
+
var _core = require("@ton/core");
|
|
25
|
+
var _ton = require("@ton/ton");
|
|
26
|
+
var _buffer = require("buffer");
|
|
27
|
+
var _tweetnacl = _interopRequireDefault(require("tweetnacl"));
|
|
28
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
29
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
30
|
+
|
|
31
|
+
function getJettonMasterContract(tonApi, contractAddress) {
|
|
32
|
+
const masterAddress = _core.Address.parse(contractAddress);
|
|
33
|
+
return tonApi.open(_ton.JettonMaster.create(masterAddress));
|
|
34
|
+
}
|
|
35
|
+
async function getJettonWalletContract(jettonMasterContract, tonApi, ownerAddress) {
|
|
36
|
+
const walletAddress = _core.Address.parse(ownerAddress);
|
|
37
|
+
const jettonWalletAddress = await jettonMasterContract.getWalletAddress(walletAddress);
|
|
38
|
+
return tonApi.open(_ton.JettonWallet.create(jettonWalletAddress));
|
|
39
|
+
}
|
|
40
|
+
function externalMessage(contract, seqno, body) {
|
|
41
|
+
return (0, _core.beginCell)().storeWritable((0, _core.storeMessage)((0, _ton.external)({
|
|
42
|
+
to: contract.address,
|
|
43
|
+
init: seqno === 0 ? contract.init : undefined,
|
|
44
|
+
// contract init for first transaction.
|
|
45
|
+
body: body
|
|
46
|
+
}))).endCell();
|
|
47
|
+
}
|
|
48
|
+
async function retry(fn, options) {
|
|
49
|
+
let lastError;
|
|
50
|
+
for (let i = 0; i < options.retries; i++) {
|
|
51
|
+
try {
|
|
52
|
+
return await fn();
|
|
53
|
+
} catch (e) {
|
|
54
|
+
if (e instanceof Error) {
|
|
55
|
+
lastError = e;
|
|
56
|
+
}
|
|
57
|
+
await new Promise(resolve => setTimeout(resolve, options.delay)); // wait for delay period, then recall the fn()
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
throw lastError; // throw only last error, in case no successful result from fn()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getMessageTxStatus(txByMsgInfo) {
|
|
65
|
+
var _txDetailInfo$descrip, _txDetailInfo$descrip2, _txDetailInfo$descrip3, _txDetailInfo$descrip4, _txDetailInfo$descrip5, _txDetailInfo$descrip6, _txDetailInfo$out_msg, _txDetailInfo$out_msg2;
|
|
66
|
+
const txDetailInfo = txByMsgInfo.transactions[0];
|
|
67
|
+
const isCompute = (_txDetailInfo$descrip = (_txDetailInfo$descrip2 = txDetailInfo.description) === null || _txDetailInfo$descrip2 === void 0 ? void 0 : (_txDetailInfo$descrip3 = _txDetailInfo$descrip2.compute_ph) === null || _txDetailInfo$descrip3 === void 0 ? void 0 : _txDetailInfo$descrip3.success) !== null && _txDetailInfo$descrip !== void 0 ? _txDetailInfo$descrip : false;
|
|
68
|
+
const isAction = (_txDetailInfo$descrip4 = (_txDetailInfo$descrip5 = txDetailInfo.description) === null || _txDetailInfo$descrip5 === void 0 ? void 0 : (_txDetailInfo$descrip6 = _txDetailInfo$descrip5.action) === null || _txDetailInfo$descrip6 === void 0 ? void 0 : _txDetailInfo$descrip6.success) !== null && _txDetailInfo$descrip4 !== void 0 ? _txDetailInfo$descrip4 : false;
|
|
69
|
+
const isBounced = (_txDetailInfo$out_msg = (_txDetailInfo$out_msg2 = txDetailInfo.out_msgs[0]) === null || _txDetailInfo$out_msg2 === void 0 ? void 0 : _txDetailInfo$out_msg2.bounced) !== null && _txDetailInfo$out_msg !== void 0 ? _txDetailInfo$out_msg : false;
|
|
70
|
+
return isCompute && isAction && !isBounced;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
async function getNativeTonTxStatus(tonApi, internalMsgHash) {
|
|
75
|
+
const internalTxInfoRaw = await tonApi.getTxByInMsg(internalMsgHash);
|
|
76
|
+
return getMessageTxStatus(internalTxInfoRaw);
|
|
77
|
+
}
|
|
78
|
+
async function getJettonTxStatus(tonApi, jettonTransferMsgHash) {
|
|
79
|
+
const jettonTransferTxInfoRaw = await tonApi.getTxByInMsg(jettonTransferMsgHash);
|
|
80
|
+
const status = getMessageTxStatus(jettonTransferTxInfoRaw);
|
|
81
|
+
if (status) {
|
|
82
|
+
var _jettonTransferTxInfo;
|
|
83
|
+
// Jetton Transfer success -> Check Jetton Internal Transfer
|
|
84
|
+
const jettonTransferTxInfo = jettonTransferTxInfoRaw.transactions[0];
|
|
85
|
+
const jettonInternalTransferHash = (_jettonTransferTxInfo = jettonTransferTxInfo.out_msgs[0]) === null || _jettonTransferTxInfo === void 0 ? void 0 : _jettonTransferTxInfo.hash;
|
|
86
|
+
const jettonInternalTransferTxInfoRaw = await tonApi.getTxByInMsg(jettonInternalTransferHash);
|
|
87
|
+
return getMessageTxStatus(jettonInternalTransferTxInfoRaw); // Jetton Internal Transfer success -> Receiver successfully receiver fund!
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
async function estimateTonTxFee(tonApi, messages, walletContract, _seqno) {
|
|
93
|
+
const contract = tonApi.open(walletContract);
|
|
94
|
+
const seqno = _seqno !== null && _seqno !== void 0 ? _seqno : await contract.getSeqno();
|
|
95
|
+
const isInit = seqno !== 0;
|
|
96
|
+
const similatedSecretKey = _buffer.Buffer.from(new Array(64));
|
|
97
|
+
const simulatedTxCell = getTransferCell(walletContract, similatedSecretKey, seqno, messages);
|
|
98
|
+
const estimateFeeInfo = await tonApi.estimateExternalMessageFee(walletContract, simulatedTxCell, isInit);
|
|
99
|
+
return BigInt(estimateFeeInfo.source_fees.gas_fee + estimateFeeInfo.source_fees.in_fwd_fee + estimateFeeInfo.source_fees.storage_fee + estimateFeeInfo.source_fees.fwd_fee) + _consts.EXTRA_TON_ESTIMATE_FEE;
|
|
100
|
+
}
|
|
101
|
+
function messageRelaxedToCell(message) {
|
|
102
|
+
return (0, _core.beginCell)().store((0, _core.storeMessageRelaxed)(message)).endCell();
|
|
103
|
+
}
|
|
104
|
+
function cellToBase64Str(cell) {
|
|
105
|
+
return cell.toBoc().toString('base64');
|
|
106
|
+
}
|
|
107
|
+
function getWalletQueryId() {
|
|
108
|
+
const swSignal = _consts.SW_QUERYID_HEX.toString(16);
|
|
109
|
+
const swSignalBuffer = _buffer.Buffer.from(swSignal, 'hex');
|
|
110
|
+
const randomBuffer = _tweetnacl.default.randomBytes(4);
|
|
111
|
+
const buffer = _buffer.Buffer.concat([swSignalBuffer, randomBuffer]);
|
|
112
|
+
return BigInt('0x' + buffer.toString('hex'));
|
|
113
|
+
}
|
|
114
|
+
function isBounceableAddress(address) {
|
|
115
|
+
return _core.Address.isFriendly(address) ? _core.Address.parseFriendly(address).isBounceable : true;
|
|
116
|
+
}
|
|
117
|
+
function tonAddressInfo(address) {
|
|
118
|
+
return _core.Address.isFriendly(address) ? _core.Address.parseFriendly(address) : undefined;
|
|
119
|
+
}
|
|
120
|
+
function getTonSendMode(isTransferAll) {
|
|
121
|
+
return isTransferAll ? _consts.SendMode.CARRY_ALL_REMAINING_BALANCE : _consts.SendMode.PAY_GAS_SEPARATELY + _consts.SendMode.IGNORE_ERRORS;
|
|
122
|
+
}
|
|
123
|
+
const isVersionv3r1 = walletContract => {
|
|
124
|
+
return walletContract instanceof _ton.WalletContractV3R1;
|
|
125
|
+
};
|
|
126
|
+
const isVersionv3r2 = walletContract => {
|
|
127
|
+
return walletContract instanceof _ton.WalletContractV3R2;
|
|
128
|
+
};
|
|
129
|
+
const isVersionv4 = walletContract => {
|
|
130
|
+
return walletContract instanceof _ton.WalletContractV4;
|
|
131
|
+
};
|
|
132
|
+
const isVersionv5r1 = walletContract => {
|
|
133
|
+
return walletContract instanceof _ton.WalletContractV5R1;
|
|
134
|
+
};
|
|
135
|
+
function getTransferCellPromise(walletContract, signer, payload, seqno, messages) {
|
|
136
|
+
let promise;
|
|
137
|
+
const params = {
|
|
138
|
+
signer,
|
|
139
|
+
sendMode: getTonSendMode(payload.transferAll),
|
|
140
|
+
seqno: seqno,
|
|
141
|
+
messages: messages
|
|
142
|
+
};
|
|
143
|
+
if (isVersionv3r1(walletContract)) {
|
|
144
|
+
promise = walletContract.createTransfer(params);
|
|
145
|
+
} else if (isVersionv3r2(walletContract)) {
|
|
146
|
+
promise = walletContract.createTransfer(params);
|
|
147
|
+
} else if (isVersionv4(walletContract)) {
|
|
148
|
+
promise = walletContract.createTransfer(params);
|
|
149
|
+
} else if (isVersionv5r1(walletContract)) {
|
|
150
|
+
promise = walletContract.createTransfer({
|
|
151
|
+
...params,
|
|
152
|
+
sendMode: params.sendMode
|
|
153
|
+
});
|
|
154
|
+
} else {
|
|
155
|
+
throw new Error('Unknown wallet contract address');
|
|
156
|
+
}
|
|
157
|
+
return promise;
|
|
158
|
+
}
|
|
159
|
+
function getTransferCell(walletContract, secretKey, seqno, messages) {
|
|
160
|
+
let cell;
|
|
161
|
+
const params = {
|
|
162
|
+
secretKey,
|
|
163
|
+
seqno,
|
|
164
|
+
messages
|
|
165
|
+
};
|
|
166
|
+
if (isVersionv3r1(walletContract)) {
|
|
167
|
+
cell = walletContract.createTransfer(params);
|
|
168
|
+
} else if (isVersionv3r2(walletContract)) {
|
|
169
|
+
cell = walletContract.createTransfer(params);
|
|
170
|
+
} else if (isVersionv4(walletContract)) {
|
|
171
|
+
cell = walletContract.createTransfer(params);
|
|
172
|
+
} else if (isVersionv5r1(walletContract)) {
|
|
173
|
+
cell = walletContract.createTransfer({
|
|
174
|
+
...params,
|
|
175
|
+
sendMode: params.sendMode
|
|
176
|
+
});
|
|
177
|
+
} else {
|
|
178
|
+
throw new Error('Unknown wallet contract address');
|
|
179
|
+
}
|
|
180
|
+
return cell;
|
|
181
|
+
}
|
|
@@ -14,6 +14,8 @@ var _types = require("@subwallet/extension-base/services/base/types");
|
|
|
14
14
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
15
15
|
var _DetectAccountBalance = _interopRequireDefault(require("@subwallet/extension-base/stores/DetectAccountBalance"));
|
|
16
16
|
var _utils2 = require("@subwallet/extension-base/utils");
|
|
17
|
+
var _keyring = require("@subwallet/keyring");
|
|
18
|
+
var _types2 = require("@subwallet/keyring/types");
|
|
17
19
|
var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
|
|
18
20
|
var _i18next = require("i18next");
|
|
19
21
|
var _rxjs = require("rxjs");
|
|
@@ -44,7 +46,7 @@ class BalanceService {
|
|
|
44
46
|
*/
|
|
45
47
|
constructor(state) {
|
|
46
48
|
this.state = state;
|
|
47
|
-
this.balanceMap = new _BalanceMapImpl.BalanceMapImpl();
|
|
49
|
+
this.balanceMap = new _BalanceMapImpl.BalanceMapImpl(state);
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
/** Init service */
|
|
@@ -67,7 +69,7 @@ class BalanceService {
|
|
|
67
69
|
/** Restore balance map */
|
|
68
70
|
async loadData() {
|
|
69
71
|
const backupBalanceData = await this.state.dbService.getStoredBalance();
|
|
70
|
-
this.balanceMap.updateBalanceItems(backupBalanceData,
|
|
72
|
+
this.balanceMap.updateBalanceItems(backupBalanceData, _constants.ALL_ACCOUNT_KEY);
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
/** Start service */
|
|
@@ -133,7 +135,7 @@ class BalanceService {
|
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
137
|
events.forEach(event => {
|
|
136
|
-
if (event.type === 'account.remove') {
|
|
138
|
+
if (event.type === 'account.remove' || event.type === 'accountProxy.remove') {
|
|
137
139
|
removedAddresses.push(event.data[0]);
|
|
138
140
|
lazyTime = 1000;
|
|
139
141
|
}
|
|
@@ -193,8 +195,9 @@ class BalanceService {
|
|
|
193
195
|
const chainInfoMap = this.state.chainService.getChainInfoMap();
|
|
194
196
|
const evmApiMap = this.state.chainService.getEvmApiMap();
|
|
195
197
|
const substrateApiMap = this.state.chainService.getSubstrateApiMap();
|
|
198
|
+
const tonApiMap = this.state.chainService.getTonApiMap();
|
|
196
199
|
let unsub = _util.noop;
|
|
197
|
-
unsub = (0, _helpers.subscribeBalance)([address], [chain], [tSlug], assetMap, chainInfoMap, substrateApiMap, evmApiMap, result => {
|
|
200
|
+
unsub = (0, _helpers.subscribeBalance)([address], [chain], [tSlug], assetMap, chainInfoMap, substrateApiMap, evmApiMap, tonApiMap, result => {
|
|
198
201
|
const rs = result[0];
|
|
199
202
|
if (rs.tokenSlug === tSlug) {
|
|
200
203
|
hasError = false;
|
|
@@ -287,10 +290,12 @@ class BalanceService {
|
|
|
287
290
|
this.balanceUpdateCache.push(balance);
|
|
288
291
|
}
|
|
289
292
|
(0, _utils2.addLazy)('updateBalanceStore', () => {
|
|
290
|
-
const
|
|
291
|
-
this.
|
|
292
|
-
|
|
293
|
-
|
|
293
|
+
const proxyId = this.state.keyringService.context.currentAccount.proxyId;
|
|
294
|
+
const isUnifiedAccount = this.state.keyringService.context.isUnifiedAccount(proxyId);
|
|
295
|
+
const isAll = (0, _utils2.isAccountAll)(proxyId);
|
|
296
|
+
this.balanceMap.updateBalanceItems(this.balanceUpdateCache, isUnifiedAccount || isAll ? proxyId : undefined);
|
|
297
|
+
if (isUnifiedAccount || isAll) {
|
|
298
|
+
this.balanceUpdateCache = [...this.balanceUpdateCache, ...Object.values(this.balanceMap.map[proxyId])];
|
|
294
299
|
}
|
|
295
300
|
this.updateBalanceStore(this.balanceUpdateCache);
|
|
296
301
|
this.balanceUpdateCache = [];
|
|
@@ -318,7 +323,7 @@ class BalanceService {
|
|
|
318
323
|
async runSubscribeBalances() {
|
|
319
324
|
await Promise.all([this.state.eventService.waitKeyringReady, this.state.eventService.waitChainReady]);
|
|
320
325
|
this.runUnsubscribeBalances();
|
|
321
|
-
const addresses = this.state.getDecodedAddresses();
|
|
326
|
+
const addresses = this.state.keyringService.context.getDecodedAddresses();
|
|
322
327
|
if (!addresses.length) {
|
|
323
328
|
return;
|
|
324
329
|
}
|
|
@@ -330,13 +335,14 @@ class BalanceService {
|
|
|
330
335
|
const chainInfoMap = this.state.chainService.getChainInfoMap();
|
|
331
336
|
const evmApiMap = this.state.chainService.getEvmApiMap();
|
|
332
337
|
const substrateApiMap = this.state.chainService.getSubstrateApiMap();
|
|
338
|
+
const tonApiMap = this.state.chainService.getTonApiMap();
|
|
333
339
|
const activeChainSlugs = Object.keys(this.state.getActiveChainInfoMap());
|
|
334
340
|
const assetState = this.state.chainService.subscribeAssetSettings().value;
|
|
335
341
|
const assets = Object.values(assetMap).filter(asset => {
|
|
336
342
|
var _assetState$asset$slu;
|
|
337
343
|
return activeChainSlugs.includes(asset.originChain) && ((_assetState$asset$slu = assetState[asset.slug]) === null || _assetState$asset$slu === void 0 ? void 0 : _assetState$asset$slu.visible);
|
|
338
344
|
}).map(asset => asset.slug);
|
|
339
|
-
const unsub = (0, _helpers.subscribeBalance)(addresses, activeChainSlugs, assets, assetMap, chainInfoMap, substrateApiMap, evmApiMap, result => {
|
|
345
|
+
const unsub = (0, _helpers.subscribeBalance)(addresses, activeChainSlugs, assets, assetMap, chainInfoMap, substrateApiMap, evmApiMap, tonApiMap, result => {
|
|
340
346
|
!cancel && this.setBalanceItem(result);
|
|
341
347
|
}, _KoniTypes.ExtrinsicType.TRANSFER_BALANCE);
|
|
342
348
|
const unsub2 = this.state.subscribeMantaPayBalance();
|
|
@@ -368,10 +374,16 @@ class BalanceService {
|
|
|
368
374
|
this.setBalanceDetectCache(addresses);
|
|
369
375
|
const assetMap = this.state.chainService.getAssetRegistry();
|
|
370
376
|
const promiseList = addresses.map(address => {
|
|
371
|
-
|
|
372
|
-
|
|
377
|
+
const type = (0, _keyring.getKeypairTypeByAddress)(address);
|
|
378
|
+
const typeValid = [..._types2.SubstrateKeypairTypes, ..._types2.EthereumKeypairTypes].includes(type);
|
|
379
|
+
if (typeValid) {
|
|
380
|
+
return this.state.subscanService.getMultiChainBalance(address).catch(e => {
|
|
381
|
+
console.error(e);
|
|
382
|
+
return null;
|
|
383
|
+
});
|
|
384
|
+
} else {
|
|
373
385
|
return null;
|
|
374
|
-
}
|
|
386
|
+
}
|
|
375
387
|
});
|
|
376
388
|
const needEnableChains = [];
|
|
377
389
|
const needActiveTokens = [];
|