@web3modal/core
Advanced tools
Comparing version 4.0.11-8c88aa26.0 to 4.0.11
@@ -7,3 +7,2 @@ export { ModalController } from './src/controllers/ModalController.js'; | ||
export { ConnectionController } from './src/controllers/ConnectionController.js'; | ||
export { SIWEController } from './src/controllers/SIWEController.js'; | ||
export { ConnectorController } from './src/controllers/ConnectorController.js'; | ||
@@ -24,3 +23,2 @@ export { SnackController } from './src/controllers/SnackController.js'; | ||
export { RouterUtil } from './src/utils/RouterUtil.js'; | ||
export { CryptoUtil } from './src/utils/CryptoUtil.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -28,3 +28,5 @@ import { subscribeKey as subKey } from 'valtio/utils'; | ||
PublicStateController.set({ selectedNetworkId: caipNetwork?.id }); | ||
this.checkIfSupportedNetwork(); | ||
if (!this.state.allowUnsupportedChain) { | ||
this.checkIfSupportedNetwork(); | ||
} | ||
}, | ||
@@ -39,2 +41,5 @@ setDefaultCaipNetwork(caipNetwork) { | ||
}, | ||
setAllowUnsupportedChain(allowUnsupportedChain) { | ||
state.allowUnsupportedChain = allowUnsupportedChain; | ||
}, | ||
getRequestedCaipNetworks() { | ||
@@ -41,0 +46,0 @@ const { approvedCaipNetworkIds, requestedCaipNetworks } = state; |
@@ -6,3 +6,3 @@ import { subscribeKey as subKey } from 'valtio/utils'; | ||
import { ApiController } from './ApiController.js'; | ||
const USDC_CURRENCY_DEFAULT = { | ||
export const USDC_CURRENCY_DEFAULT = { | ||
id: '2b92315d-eab7-5bef-84fa-089a131333f5', | ||
@@ -26,3 +26,3 @@ name: 'USD Coin', | ||
}; | ||
const USD_CURRENCY_DEFAULT = { | ||
export const USD_CURRENCY_DEFAULT = { | ||
id: 'USD', | ||
@@ -42,3 +42,3 @@ payment_method_limits: [ | ||
}; | ||
const state = proxy({ | ||
const defaultState = { | ||
providers: ONRAMP_PROVIDERS, | ||
@@ -52,3 +52,4 @@ selectedProvider: null, | ||
quotesLoading: false | ||
}); | ||
}; | ||
const state = proxy(defaultState); | ||
export const OnRampController = { | ||
@@ -88,13 +89,35 @@ state, | ||
state.quotesLoading = true; | ||
const quote = await BlockchainApiController.getOnrampQuote({ | ||
purchaseCurrency: state.purchaseCurrency, | ||
paymentCurrency: state.paymentCurrency, | ||
amount: state.paymentAmount?.toString() || '0', | ||
network: state.purchaseCurrency?.name | ||
}); | ||
try { | ||
const quote = await BlockchainApiController.getOnrampQuote({ | ||
purchaseCurrency: state.purchaseCurrency, | ||
paymentCurrency: state.paymentCurrency, | ||
amount: state.paymentAmount?.toString() || '0', | ||
network: state.purchaseCurrency?.symbol | ||
}); | ||
state.quotesLoading = false; | ||
state.purchaseAmount = Number(quote.purchaseAmount.amount); | ||
return quote; | ||
} | ||
catch (error) { | ||
state.error = error.message; | ||
state.quotesLoading = false; | ||
return null; | ||
} | ||
finally { | ||
state.quotesLoading = false; | ||
} | ||
}, | ||
resetState() { | ||
state.providers = ONRAMP_PROVIDERS; | ||
state.selectedProvider = null; | ||
state.error = null; | ||
state.purchaseCurrency = USDC_CURRENCY_DEFAULT; | ||
state.paymentCurrency = USD_CURRENCY_DEFAULT; | ||
state.purchaseCurrencies = [USDC_CURRENCY_DEFAULT]; | ||
state.paymentCurrencies = []; | ||
state.paymentAmount = undefined; | ||
state.purchaseAmount = undefined; | ||
state.quotesLoading = false; | ||
state.purchaseAmount = Number(quote.purchaseAmount.amount); | ||
return quote; | ||
} | ||
}; | ||
//# sourceMappingURL=OnRampController.js.map |
@@ -40,2 +40,5 @@ import { subscribeKey as subKey } from 'valtio/utils'; | ||
}, | ||
setIsSiweEnabled(isSiweEnabled) { | ||
state.isSiweEnabled = isSiweEnabled; | ||
}, | ||
setEnableAnalytics(enableAnalytics) { | ||
@@ -42,0 +45,0 @@ state.enableAnalytics = enableAnalytics; |
@@ -1,15 +0,183 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { TransactionsController } from '../../index.js'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import { BlockchainApiController, OptionsController, TransactionsController } from '../../index.js'; | ||
import { ONRAMP_TRANSACTIONS_RESPONSES_FEB, ONRAMP_TRANSACTIONS_RESPONSES_JAN } from '../constants/OnrampTransactions.js'; | ||
const projectId = '123'; | ||
OptionsController.state.projectId = projectId; | ||
const defaultState = { | ||
transactions: [], | ||
transactionsByYear: {}, | ||
loading: false, | ||
empty: false, | ||
next: undefined, | ||
coinbaseTransactions: {} | ||
}; | ||
describe('TransactionsController', () => { | ||
it('should have valid default state', () => { | ||
expect(TransactionsController.state).toEqual({ | ||
transactions: [], | ||
transactionsByYear: {}, | ||
loading: false, | ||
empty: false, | ||
next: undefined, | ||
coinbaseTransactions: {} | ||
expect(TransactionsController.state).toEqual(defaultState); | ||
}); | ||
it('should fetch onramp transactions and group them appropiately', async () => { | ||
const accountAddress = ONRAMP_TRANSACTIONS_RESPONSES_JAN.SUCCESS.metadata.sentTo; | ||
const response = { | ||
data: [ | ||
ONRAMP_TRANSACTIONS_RESPONSES_JAN.SUCCESS, | ||
ONRAMP_TRANSACTIONS_RESPONSES_FEB.FAILED | ||
], | ||
next: '' | ||
}; | ||
const fetchTransactions = vi | ||
.spyOn(BlockchainApiController, 'fetchTransactions') | ||
.mockResolvedValue(response); | ||
await TransactionsController.fetchTransactions(accountAddress, 'coinbase'); | ||
expect(fetchTransactions).toHaveBeenCalledWith({ | ||
account: accountAddress, | ||
projectId, | ||
onramp: 'coinbase', | ||
cursor: undefined | ||
}); | ||
expect(TransactionsController.state.transactions).toEqual([]); | ||
expect(TransactionsController.state.transactionsByYear).toEqual({}); | ||
expect(TransactionsController.state.coinbaseTransactions).toEqual({ | ||
2024: { | ||
0: [ONRAMP_TRANSACTIONS_RESPONSES_JAN.SUCCESS], | ||
1: [ONRAMP_TRANSACTIONS_RESPONSES_FEB.FAILED] | ||
} | ||
}); | ||
}); | ||
it('should update onramp transaction from pending to success', async () => { | ||
const { SUCCESS, IN_PROGRESS } = ONRAMP_TRANSACTIONS_RESPONSES_FEB; | ||
const accountAddress = SUCCESS.metadata.sentTo; | ||
TransactionsController.state.coinbaseTransactions = {}; | ||
const pendingResponse = { | ||
data: [IN_PROGRESS], | ||
next: '' | ||
}; | ||
const fetchTransactions = vi | ||
.spyOn(BlockchainApiController, 'fetchTransactions') | ||
.mockResolvedValue(pendingResponse); | ||
await TransactionsController.fetchTransactions(accountAddress, 'coinbase'); | ||
expect(fetchTransactions).toHaveBeenCalledWith({ | ||
account: accountAddress, | ||
projectId, | ||
onramp: 'coinbase', | ||
cursor: undefined | ||
}); | ||
expect(TransactionsController.state.transactions).toEqual([]); | ||
expect(TransactionsController.state.transactionsByYear).toEqual({}); | ||
expect(TransactionsController.state.coinbaseTransactions).toEqual({ | ||
2024: { | ||
1: [IN_PROGRESS] | ||
} | ||
}); | ||
const successResponse = { | ||
data: [SUCCESS], | ||
next: '' | ||
}; | ||
fetchTransactions.mockResolvedValue(successResponse); | ||
await TransactionsController.fetchTransactions(accountAddress, 'coinbase'); | ||
expect(fetchTransactions).toHaveBeenCalledWith({ | ||
account: accountAddress, | ||
projectId, | ||
onramp: 'coinbase', | ||
cursor: undefined | ||
}); | ||
expect(TransactionsController.state.transactions).toEqual([]); | ||
expect(TransactionsController.state.transactionsByYear).toEqual({}); | ||
expect(TransactionsController.state.coinbaseTransactions).toEqual({ | ||
2024: { | ||
1: [SUCCESS] | ||
} | ||
}); | ||
}); | ||
it('should update onramp transaction from pending to failed', async () => { | ||
const { FAILED, IN_PROGRESS } = ONRAMP_TRANSACTIONS_RESPONSES_FEB; | ||
const accountAddress = FAILED.metadata.sentTo; | ||
TransactionsController.state.coinbaseTransactions = {}; | ||
const pendingResponse = { | ||
data: [IN_PROGRESS], | ||
next: '' | ||
}; | ||
const fetchTransactions = vi | ||
.spyOn(BlockchainApiController, 'fetchTransactions') | ||
.mockResolvedValue(pendingResponse); | ||
await TransactionsController.fetchTransactions(accountAddress, 'coinbase'); | ||
expect(fetchTransactions).toHaveBeenCalledWith({ | ||
account: accountAddress, | ||
projectId, | ||
onramp: 'coinbase', | ||
cursor: undefined | ||
}); | ||
expect(TransactionsController.state.transactions).toEqual([]); | ||
expect(TransactionsController.state.transactionsByYear).toEqual({}); | ||
expect(TransactionsController.state.coinbaseTransactions).toEqual({ | ||
2024: { | ||
1: [IN_PROGRESS] | ||
} | ||
}); | ||
const successResponse = { | ||
data: [FAILED], | ||
next: '' | ||
}; | ||
fetchTransactions.mockResolvedValue(successResponse); | ||
await TransactionsController.fetchTransactions(accountAddress, 'coinbase'); | ||
expect(fetchTransactions).toHaveBeenCalledWith({ | ||
account: accountAddress, | ||
projectId, | ||
onramp: 'coinbase', | ||
cursor: undefined | ||
}); | ||
expect(TransactionsController.state.transactions).toEqual([]); | ||
expect(TransactionsController.state.transactionsByYear).toEqual({}); | ||
expect(TransactionsController.state.coinbaseTransactions).toEqual({ | ||
2024: { | ||
1: [FAILED] | ||
} | ||
}); | ||
}); | ||
it('should push new onramp transactions while updating old ones', async () => { | ||
const { SUCCESS, IN_PROGRESS } = ONRAMP_TRANSACTIONS_RESPONSES_JAN; | ||
const accountAddress = SUCCESS.metadata.sentTo; | ||
TransactionsController.state.coinbaseTransactions = {}; | ||
const pendingResponse = { | ||
data: [IN_PROGRESS], | ||
next: '' | ||
}; | ||
const fetchTransactions = vi | ||
.spyOn(BlockchainApiController, 'fetchTransactions') | ||
.mockResolvedValue(pendingResponse); | ||
await TransactionsController.fetchTransactions(accountAddress, 'coinbase'); | ||
expect(fetchTransactions).toHaveBeenCalledWith({ | ||
account: accountAddress, | ||
projectId, | ||
onramp: 'coinbase', | ||
cursor: undefined | ||
}); | ||
expect(TransactionsController.state.transactions).toEqual([]); | ||
expect(TransactionsController.state.transactionsByYear).toEqual({}); | ||
expect(TransactionsController.state.coinbaseTransactions).toEqual({ | ||
2024: { | ||
0: [IN_PROGRESS] | ||
} | ||
}); | ||
const successResponse = { | ||
data: [SUCCESS, ONRAMP_TRANSACTIONS_RESPONSES_FEB.IN_PROGRESS], | ||
next: '' | ||
}; | ||
fetchTransactions.mockResolvedValue(successResponse); | ||
await TransactionsController.fetchTransactions(accountAddress, 'coinbase'); | ||
expect(fetchTransactions).toHaveBeenCalledWith({ | ||
account: accountAddress, | ||
projectId, | ||
onramp: 'coinbase', | ||
cursor: undefined | ||
}); | ||
expect(TransactionsController.state.transactions).toEqual([]); | ||
expect(TransactionsController.state.transactionsByYear).toEqual({}); | ||
expect(TransactionsController.state.coinbaseTransactions).toEqual({ | ||
2024: { | ||
0: [SUCCESS], | ||
1: [ONRAMP_TRANSACTIONS_RESPONSES_FEB.IN_PROGRESS] | ||
} | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=TransactionsController.test.js.map |
@@ -13,4 +13,2 @@ export { ModalController } from './src/controllers/ModalController.js'; | ||
export type { ConnectionControllerClient, ConnectionControllerState } from './src/controllers/ConnectionController.js'; | ||
export { SIWEController } from './src/controllers/SIWEController.js'; | ||
export type { SIWEControllerClient, SIWEControllerClientState } from './src/controllers/SIWEController.js'; | ||
export { ConnectorController } from './src/controllers/ConnectorController.js'; | ||
@@ -40,3 +38,2 @@ export type { ConnectorControllerState } from './src/controllers/ConnectorController.js'; | ||
export { RouterUtil } from './src/utils/RouterUtil.js'; | ||
export { CryptoUtil } from './src/utils/CryptoUtil.js'; | ||
export type * from './src/utils/TypeUtil.js'; |
@@ -17,2 +17,3 @@ import type { CaipNetwork, CaipNetworkId } from '../utils/TypeUtil.js'; | ||
approvedCaipNetworkIds?: CaipNetworkId[]; | ||
allowUnsupportedChain?: boolean; | ||
} | ||
@@ -27,2 +28,3 @@ export declare const NetworkController: { | ||
setRequestedCaipNetworks(requestedNetworks: NetworkControllerState['requestedCaipNetworks']): void; | ||
setAllowUnsupportedChain(allowUnsupportedChain: NetworkControllerState['allowUnsupportedChain']): void; | ||
getRequestedCaipNetworks(): CaipNetwork[]; | ||
@@ -29,0 +31,0 @@ getApprovedCaipNetworksData(): Promise<void>; |
@@ -21,2 +21,21 @@ import type { PurchaseCurrency, PaymentCurrency } from '../utils/TypeUtil.js'; | ||
} | ||
export declare const USDC_CURRENCY_DEFAULT: { | ||
id: string; | ||
name: string; | ||
symbol: string; | ||
networks: { | ||
name: string; | ||
display_name: string; | ||
chain_id: string; | ||
contract_address: string; | ||
}[]; | ||
}; | ||
export declare const USD_CURRENCY_DEFAULT: { | ||
id: string; | ||
payment_method_limits: { | ||
id: string; | ||
min: string; | ||
max: string; | ||
}[]; | ||
}; | ||
export declare const OnRampController: { | ||
@@ -32,3 +51,4 @@ state: OnRampControllerState; | ||
getAvailableCurrencies(): Promise<void>; | ||
getQuote(): Promise<import("../utils/TypeUtil.js").OnrampQuote>; | ||
getQuote(): Promise<import("../utils/TypeUtil.js").OnrampQuote | null>; | ||
resetState(): void; | ||
}; |
@@ -14,2 +14,3 @@ import type { CustomWallet, Metadata, ProjectId, SdkVersion, Tokens } from '../utils/TypeUtil.js'; | ||
privacyPolicyUrl?: string; | ||
isSiweEnabled?: boolean; | ||
enableAnalytics?: boolean; | ||
@@ -31,2 +32,3 @@ metadata?: Metadata; | ||
setCustomWallets(customWallets: OptionsControllerState['customWallets']): void; | ||
setIsSiweEnabled(isSiweEnabled: OptionsControllerState['isSiweEnabled']): void; | ||
setEnableAnalytics(enableAnalytics: OptionsControllerState['enableAnalytics']): void; | ||
@@ -33,0 +35,0 @@ setSdkVersion(sdkVersion: OptionsControllerState['sdkVersion']): void; |
@@ -17,3 +17,3 @@ import type { W3mFrameProvider } from '@web3modal/wallet'; | ||
export type ProjectId = string; | ||
export type Platform = 'mobile' | 'desktop' | 'browser' | 'web' | 'qrcode' | 'unsupported' | 'external'; | ||
export type Platform = 'mobile' | 'desktop' | 'browser' | 'web' | 'qrcode' | 'unsupported'; | ||
export type ConnectorType = 'EXTERNAL' | 'WALLET_CONNECT' | 'INJECTED' | 'ANNOUNCED' | 'EMAIL'; | ||
@@ -150,3 +150,4 @@ export type Connector = { | ||
properties: { | ||
method: 'qrcode' | 'mobile' | 'external' | 'browser' | 'email'; | ||
method: 'qrcode' | 'mobile' | 'browser' | 'email'; | ||
name: string; | ||
}; | ||
@@ -239,32 +240,2 @@ } | { | ||
}; | ||
export interface SIWESession { | ||
address: string; | ||
chainId: number; | ||
} | ||
export interface SIWECreateMessageArgs { | ||
nonce: string; | ||
address: string; | ||
chainId: number; | ||
} | ||
export interface SIWEVerifyMessageArgs { | ||
message: string; | ||
signature: string; | ||
} | ||
export interface SIWEClientMethods { | ||
getNonce: () => Promise<string>; | ||
createMessage: (args: SIWECreateMessageArgs) => string; | ||
verifyMessage: (args: SIWEVerifyMessageArgs) => Promise<boolean>; | ||
getSession: () => Promise<SIWESession | null>; | ||
signOut: () => Promise<boolean>; | ||
onSignIn?: (session?: SIWESession) => void; | ||
onSignOut?: () => void; | ||
} | ||
export interface SIWEConfig extends SIWEClientMethods { | ||
enabled?: boolean; | ||
nonceRefetchIntervalMs?: number; | ||
sessionRefetchIntervalMs?: number; | ||
signOutOnDisconnect?: boolean; | ||
signOutOnAccountChange?: boolean; | ||
signOutOnNetworkChange?: boolean; | ||
} | ||
export type DestinationWallet = { | ||
@@ -271,0 +242,0 @@ address: string; |
{ | ||
"name": "@web3modal/core", | ||
"version": "4.0.11-8c88aa26.0", | ||
"version": "4.0.11", | ||
"type": "module", | ||
@@ -20,6 +20,4 @@ "main": "./dist/esm/index.js", | ||
"dependencies": { | ||
"@web3modal/common": "4.0.11-8c88aa26.0", | ||
"@web3modal/wallet": "4.0.11-8c88aa26.0", | ||
"idb": "8.0.0", | ||
"nanoid": "5.0.6", | ||
"@web3modal/common": "4.0.11", | ||
"@web3modal/wallet": "4.0.11", | ||
"valtio": "1.11.2" | ||
@@ -26,0 +24,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
237939
3
3775
0
122
+ Added@web3modal/common@4.0.11(transitive)
+ Added@web3modal/wallet@4.0.11(transitive)
- Removedidb@8.0.0
- Removednanoid@5.0.6
- Removed@web3modal/common@4.0.11-8c88aa26.0(transitive)
- Removed@web3modal/wallet@4.0.11-8c88aa26.0(transitive)
- Removedidb@8.0.0(transitive)
- Removednanoid@5.0.6(transitive)
Updated@web3modal/common@4.0.11
Updated@web3modal/wallet@4.0.11