-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add TM2 wallet provider type to the SDK (#7)
- Loading branch information
Showing
23 changed files
with
1,167 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ConnectionManager } from '../connection'; | ||
import { ConnectOptions, ConnectResponse } from '../types/methods'; | ||
import { isTM2WalletProvider } from '../utils/provider.utils'; | ||
|
||
export const connect = async ( | ||
connectionManager: ConnectionManager, | ||
connectionOptions: ConnectOptions = {} | ||
): Promise<ConnectResponse> => { | ||
try { | ||
await connectionManager.connectWallet(); | ||
} catch (e) { | ||
const openWalletLink = | ||
!isTM2WalletProvider(connectionManager.getWalletProvider()) && !!connectionOptions.walletDownloadUrl; | ||
if (openWalletLink) { | ||
openLink(connectionOptions.walletDownloadUrl!); | ||
} | ||
console.error(e); | ||
} | ||
}; | ||
|
||
const openLink = (url: string): void => { | ||
window?.open(url, '_blank'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ConnectionManager } from '../connection'; | ||
import { DisconnectResponse } from '../types/methods'; | ||
|
||
export const disconnect = (connectionManager: ConnectionManager): DisconnectResponse => { | ||
connectionManager.disconnectWallet(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ConnectionManager } from '../connection'; | ||
import { GetConnectionState } from '../types/methods/get-connection-state.types'; | ||
|
||
export const getConnectionState = (connectionManager: ConnectionManager): GetConnectionState => { | ||
return connectionManager.getConnectionState(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
export * from './add-establish'; | ||
export * from './add-network'; | ||
export * from './broadcast-transaction'; | ||
export * from './connect'; | ||
export * from './disconnect'; | ||
export * from './get-account'; | ||
export * from './get-connection-state'; | ||
export * from './is-connected'; | ||
export * from './off-connection-change'; | ||
export * from './on-change-account'; | ||
export * from './on-change-network'; | ||
export * from './on-connection-change'; | ||
export * from './sign-transaction'; | ||
export * from './switch-network'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ConnectionManager } from '../connection'; | ||
import { OffConnectionChangeOptions, OffConnectionChangeResponse } from '../types/methods/off-connection-change'; | ||
|
||
export const offConnectionChange = ( | ||
connectionManager: ConnectionManager, | ||
options: OffConnectionChangeOptions | ||
): OffConnectionChangeResponse => { | ||
return connectionManager.off(options.callback); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ConnectionManager } from '../connection'; | ||
import { OnConnectionChangeOptions, OnConnectionChangeResponse } from '../types/methods/on-connection-change'; | ||
|
||
export const onConnectionChange = ( | ||
connectionManager: ConnectionManager, | ||
options: OnConnectionChangeOptions | ||
): OnConnectionChangeResponse => { | ||
return connectionManager.on(options.callback); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './tm2-wallet'; | ||
export * from './wallet'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { WalletProvider } from './wallet'; | ||
|
||
export interface TM2WalletProvider extends WalletProvider { | ||
connect(): Promise<boolean>; | ||
|
||
disconnect(): Promise<boolean>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './account.types'; | ||
export * from './config.types'; | ||
export * from './transaction.types'; | ||
export * from './wallet.types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface ConnectOptions { | ||
walletDownloadUrl?: string; | ||
} | ||
|
||
export type ConnectResponse = void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type DisconnectResponse = void; |
3 changes: 3 additions & 0 deletions
3
packages/sdk/src/core/types/methods/get-connection-state.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { ConnectionState } from '../../connection'; | ||
|
||
export type GetConnectionState = ConnectionState; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
export * from './add-establish.types'; | ||
export * from './add-network.types'; | ||
export * from './broadcast-transaction.types'; | ||
export * from './connect.types'; | ||
export * from './disconnect.types'; | ||
export * from './get-account.types'; | ||
export * from './is-connected.types'; | ||
export * from './off-connection-change'; | ||
export * from './on-change-account.types'; | ||
export * from './on-change-network.types'; | ||
export * from './on-connection-change'; | ||
export * from './sign-transaction.types'; | ||
export * from './switch-network.types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.