Skip to content

Commit

Permalink
feat: upgrade to blocto v2 SDK (#10309)
Browse files Browse the repository at this point in the history
* chore: update blocto SDK

* refactor: remove deprecated field

* refactor: remove server side configuration fields

* fix: Flow Balance
  • Loading branch information
guanbinrui committed Aug 9, 2023
1 parent 028a784 commit 1a6ac93
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 151 deletions.
2 changes: 1 addition & 1 deletion packages/plugins/Flow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
},
"dependencies": {
"@blocto/fcl": "^0.0.78-alpha.10",
"@blocto/fcl": "^1.4.0",
"@masknet/icons": "workspace:^",
"@masknet/injected-script": "workspace:^",
"@masknet/plugin-infra": "workspace:^",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ export function WalletStatusBox(props: WalletStatusBox) {
const { data: nativeToken, isLoading: loadingNativeToken } = useNativeToken()
const networkDescriptor = useNetworkDescriptor()
const { data: domain } = useReverseAddress(undefined, account)

const { summary: pendingSummary, transactionList } = usePendingTransactions()

if (!Others.isValidAddress(account)) {
Expand Down
14 changes: 7 additions & 7 deletions packages/web3-constants/flow/auth.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"ACCESS_NODE_API": {
"Mainnet": "https://flow-access-mainnet.portto.io",
"Testnet": "https://access-testnet.onflow.org"
"Mainnet": "https://rest-mainnet.onflow.org",
"Testnet": "https://rest-testnet.onflow.org"
},
"DISCOVERY_WALLET": {
"Mainnet": "https://flow-wallet.blocto.app/authn",
"Testnet": "https://flow-wallet-testnet.blocto.app/authn"
"Mainnet": "https://wallet-v2.blocto.app/5b2f59b4-3f87-471a-a784-0023725bc535/flow/authn",
"Testnet": "https://wallet-v2.blocto.app/5b2f59b4-3f87-471a-a784-0023725bc535/flow/authn"
},
"CHALLENGE_HANDSHAKE": {
"Mainnet": "https://flow-wallet.blocto.app/api/flow/authn",
"Testnet": "https://flow-wallet-testnet.blocto.app/api/flow/authn"
"MASK_APP_ID": {
"Mainnet": "5b2f59b4-3f87-471a-a784-0023725bc535",
"Testnet": "5b2f59b4-3f87-471a-a784-0023725bc535"
},
"MASK_APP_TITLE": {
"Mainnet": "Mask Network",
Expand Down
6 changes: 3 additions & 3 deletions packages/web3-hooks/base/src/useBalance.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useEffect } from 'react'
import { noop } from 'lodash-es'
import { useEffect } from 'react'
import { useQuery } from '@tanstack/react-query'
import { isSameAddress } from '@masknet/web3-shared-base'
import type { NetworkPluginID } from '@masknet/shared-base'
import type { ConnectionOptions } from '@masknet/web3-providers/types'
import { useChainContext } from './useContext.js'
import { useWeb3State } from './useWeb3State.js'
import { useWeb3Connection } from './useWeb3Connection.js'
import { useQuery } from '@tanstack/react-query'

export function useBalance<T extends NetworkPluginID = NetworkPluginID>(pluginID?: T, options?: ConnectionOptions<T>) {
const { account, chainId } = useChainContext({ account: options?.account })
Expand All @@ -19,7 +19,7 @@ export function useBalance<T extends NetworkPluginID = NetworkPluginID>(pluginID

const result = useQuery({
enabled: !!account && !!Web3,
queryKey: ['balance', pluginID, chainId, account, options],
queryKey: ['balance', pluginID, chainId, account],
queryFn: async () => {
if (!account) return 0
return Web3.getBalance(account)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export class FlowConnectionAPI
}

async switchChain(chainId: ChainId, initial?: ConnectionOptions): Promise<void> {
await this.Web3.getWeb3ProviderInstance(initial).switchChain(chainId)
await this.Web3.getProviderInstance(initial).switchChain(chainId)
}

async callTransaction(query: TransactionQuery, initial?: ConnectionOptions): Promise<string> {
Expand Down
6 changes: 6 additions & 0 deletions packages/web3-providers/src/Web3/Flow/apis/HubFungibleAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
TransactionParameter,
} from '@masknet/web3-shared-flow'
import { FlowFungibleAPI } from './FungibleTokenAPI.js'
import { FlowConnectionAPI } from './ConnectionAPI.js'
import { FlowHubOptionsAPI } from './HubOptionsAPI.js'
import { HubFungibleAPI_Base } from '../../Base/apis/HubFungibleAPI.js'
import type { HubOptions_Base } from '../../Base/apis/HubOptionsAPI.js'
Expand All @@ -25,6 +26,7 @@ export class FlowHubFungibleAPI extends HubFungibleAPI_Base<
Transaction,
TransactionParameter
> {
private FlowWeb3 = new FlowConnectionAPI()
private FlowFungible = new FlowFungibleAPI()

protected override HubOptions = new FlowHubOptionsAPI(this.options)
Expand All @@ -38,4 +40,8 @@ export class FlowHubFungibleAPI extends HubFungibleAPI_Base<
initial,
)
}

public override getFungibleToken(address: string, initial?: HubOptions_Base<ChainId>) {
return this.FlowWeb3.getFungibleToken(address, initial)
}
}
2 changes: 1 addition & 1 deletion packages/web3-providers/src/Web3/Flow/apis/Web3API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class FlowWeb3API {
throw new Error('Method not implemented.')
}

getWeb3ProviderInstance(initial?: ConnectionOptions) {
getProviderInstance(initial?: ConnectionOptions) {
const options = this.ConnectionOptions.fill(initial)
return FlowProviders[options.providerType]
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-shared/flow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"types": "./dist/index.d.js",
"dependencies": {
"@blocto/fcl": "^0.0.78-alpha.10",
"@blocto/fcl": "^1.4.0",
"@masknet/shared-base": "workspace:^",
"@masknet/web3-constants": "workspace:^",
"@masknet/web3-shared-base": "workspace:^",
Expand Down
16 changes: 11 additions & 5 deletions packages/web3-shared/flow/src/blocto-fcl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ declare module '@blocto/fcl' {
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

// CONFIGURATION
export type Environment = 'local' | 'canarynet' | 'testnet' | 'mainnet'
export type Network = 'local' | 'canarynet' | 'testnet' | 'mainnet'

/**
* @see {@link https://docs.onflow.org/fcl/reference/api/#common-configuration-keys}
* @see {@link https://docs.onflow.org/fcl/reference/configure-fcl/}
*/
export interface ConfigurationOptions {
/**
* Used in conjunction with stored interactions.
*/
'flow.network': Network
/**
* API URL for the Flow Blockchain Access Node you want to be communicating
* with. See all available access node endpoints
* [here]{@link https://docs.onflow.org/access-api/#flow-access-node-endpoints}.
*/
'accessNode.api': string
/**
* Used in conjunction with stored interactions.
*/
env?: Environment
/**
* Points FCL at the Wallet or Wallet Discovery mechanism.
*/
Expand All @@ -36,6 +36,12 @@ declare module '@blocto/fcl' {
* [discovery]{@link https://docs.onflow.org/fcl/reference/api/#discovery}.
*/
'discovery.authn.endpoint'?: string

'discovery.wallet.method'?: string
/**
* Your applications id, can be requested by wallets and other services.
*/
'app.detail.id'?: string
/**
* Your applications title, can be requested by wallets and other services.
*/
Expand Down
7 changes: 3 additions & 4 deletions packages/web3-shared/flow/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ export function createClient(chainId: ChainId) {
const authConstants = getAuthConstants(chainId)

fcl.config({
'accessNode.api': authConstants.ACCESS_NODE_API ?? '',
'flow.network': 'mainnet',
'accessNode.api': authConstants.ACCESS_NODE_API!,
'discovery.wallet': authConstants.DISCOVERY_WALLET!,
'app.detail.title': authConstants.MASK_APP_TITLE,
'app.detail.icon': authConstants.MASK_APP_ICON,
// @ts-expect-error untyped api?
'challenge.handshake': authConstants.CHALLENGE_HANDSHAKE ?? '',
'discovery.wallet.method': 'HTTP/POST',
})
return fcl
}
4 changes: 2 additions & 2 deletions packages/web3-shared/flow/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import type { MutateOptions, BlockObject, TransactionObject, QueryOptions, Block
import type { Web3State as Web3StateShared, Web3UI as Web3UIShared } from '@masknet/web3-shared-base'

export enum ChainId {
Mainnet = 1,
Testnet = 2,
// For any chains not supported yet.
Invalid = 0,
Mainnet = 1,
Testnet = 2,
}

export enum AddressType {
Expand Down

0 comments on commit 1a6ac93

Please sign in to comment.