diff --git a/packages/blockchain-sdk-solana/examples/exmple-actions.ts b/packages/blockchain-sdk-solana/examples/exmple-actions.ts new file mode 100644 index 00000000..379dd99f --- /dev/null +++ b/packages/blockchain-sdk-solana/examples/exmple-actions.ts @@ -0,0 +1,115 @@ +// Considerations +// 1. Smart message should encapsulate all possible actions, including link and sign transaction - this is needed to be interoperable in different clients +// 2. Multiple actions should be later supported (e.g. both link and sign transaction), based on mockups e.g. https://www.figma.com/file/YMrtyevM6MlWYDZBO2fLb4/Use-Case-Examples?type=design&node-id=1-820&mode=dev +// 3. Single smart message should be produced if multiple actions exist, we should forbid using multiple tx-services in a context of single actionable notif +import { DappMessageActionType, type SmartMessageAction } from '@dialectlabs/sdk/src'; +import type { DappMessages } from '../../sdk/src/'; +// @ts-ignore + +const dappMessages = (1 as DappMessages); +const buyNftSmartMessage: SmartMessageAction = { + type: DappMessageActionType.SMART_MESSAGE, + smartMessage: { + transactionServiceId: 'tensor-nft-buy', + transactionParams: { + collectionId: 'foo', + mintAddress: 'bar', + owner: 'foo', + price: 'foo', + priceWithFeeAndRoyalty: 'foo', + }, + }, + +}; +const tokenTransferSmartMessage: SmartMessageAction = { + type: DappMessageActionType.SMART_MESSAGE, + smartMessage: { + transactionServiceId: 'tensor-nft-buy', + transactionParams: { + collectionId: 'foo', + mintAddress: 'bar', + owner: 'foo', + price: 'foo', + priceWithFeeAndRoyalty: 'foo', + }, + }, +}; +// Examples: +// 1. SENDING SIGN_TRANSACTION ACTIONS, including possible multiple actions +// a) W/O TX_SERVICE_ID NOT ALLOWED +dappMessages.send({ + actionsV3: { + type: DappMessageActionType.SMART_MESSAGE, + smartMessage: { + transactionParams: { + payer: 'foo', + payee: 'bar', + amount: 'foo', + links: [{ + label: 'foo', + url: 'foo', + }], + }, + }, + }, + message: 'foo', +}); +// b) multiple tx services not allowed +dappMessages.send({ + actionsV3: { + serviceId: 'foo', + actions: [ + buyNftSmartMessage, + ], + }, + message: 'foo', +}); +// d) SINGLE TX_SERVICE ID ALLOWED +dappMessages.send({ + actionsV3: buyNftSmartMessage, + message: 'foo', +});dappMessages.send({ + actionsV3: tokenTransferSmartMessage, + message: 'foo', +}); + + +// 2. SENDING LINK ACTIONS +// a) MULTIPLE W/O TX_SERVICE_ID ARE NOT ALLOWED +dappMessages.send({ + actionsV3: { + actions: [{ + type: DappMessageActionType.LINK, + label: '', + url: 'd', + }, { + type: DappMessageActionType.LINK, + label: '', + url: 'd', + }], + }, + message: 'foo', +});// b) SINGLE link ALLOWED +dappMessages.send({ + actionsV3: { + actions: [{ + type: DappMessageActionType.LINK, + label: 'foo', + url: 'foo', + }], + }, + message: 'foo', +}); + + +// 3. SENDING MIXED ACTIONS +dappMessages.send({ + actionsV3: { + actions: [{ + type: DappMessageActionType.LINK, + label: 'foo', + url: 'foo', + }], + }, + message: 'foo', +}); diff --git a/packages/sdk-actions-spec/src/index.ts b/packages/sdk-actions-spec/src/index.ts index a52fff99..c15ddd76 100644 --- a/packages/sdk-actions-spec/src/index.ts +++ b/packages/sdk-actions-spec/src/index.ts @@ -1,2 +1,2 @@ export * from './transactions/tensor/tensor-transactions-spec'; -export * from './transactions/transaction-action-spec'; +export * from './transactions/tensor/token-transfer'; diff --git a/packages/sdk-actions-spec/src/transactions/tensor/tensor-transactions-spec.ts b/packages/sdk-actions-spec/src/transactions/tensor/tensor-transactions-spec.ts index 2446bd68..bd672171 100644 --- a/packages/sdk-actions-spec/src/transactions/tensor/tensor-transactions-spec.ts +++ b/packages/sdk-actions-spec/src/transactions/tensor/tensor-transactions-spec.ts @@ -1,6 +1,12 @@ -import type { TransactionParams } from '../transaction-action-spec'; +import type { SmartMessage, SmartMessageAction, SmartMessageParams } from '@dialectlabs/sdk/src'; //TODO: upd import -export interface NftBuyTransaction extends TransactionParams { + +export interface TensorNftBuySmartMessage extends SmartMessage { + transactionServiceId: 'tensor-nft-buy'; + transactionParams: NftBuyTransactionParams; +} + +export interface NftBuyTransactionParams extends SmartMessageParams{ mintAddress: string; collectionId: string; price: string; @@ -9,4 +15,4 @@ export interface NftBuyTransaction extends TransactionParams { imageUrl?: string; collectionName?: string; nftName?: string; -} \ No newline at end of file +} diff --git a/packages/sdk-actions-spec/src/transactions/tensor/token-transfer.ts b/packages/sdk-actions-spec/src/transactions/tensor/token-transfer.ts new file mode 100644 index 00000000..dafe832d --- /dev/null +++ b/packages/sdk-actions-spec/src/transactions/tensor/token-transfer.ts @@ -0,0 +1,17 @@ +import type { SmartMessage, SmartMessageParams } from '@dialectlabs/sdk/src'; //TODO: upd import + + +export interface TokenTransferSmartMessage extends SmartMessage { + transactionServiceId: 'tensor-nft-buy'; + transactionParams: TokenTransferSmartMessageParams; +} + +export interface TokenTransferSmartMessageParams extends SmartMessageParams { + payer: string; + payee: string; + amount: string; + links: { + label: string, + url: string + }[] +} diff --git a/packages/sdk-actions-spec/src/transactions/transaction-action-spec.ts b/packages/sdk-actions-spec/src/transactions/transaction-action-spec.ts deleted file mode 100644 index 7329a8c2..00000000 --- a/packages/sdk-actions-spec/src/transactions/transaction-action-spec.ts +++ /dev/null @@ -1 +0,0 @@ -export interface TransactionParams {} diff --git a/packages/sdk/src/dapp/dapp.interface.ts b/packages/sdk/src/dapp/dapp.interface.ts index 46fc022a..e6fe0ddd 100644 --- a/packages/sdk/src/dapp/dapp.interface.ts +++ b/packages/sdk/src/dapp/dapp.interface.ts @@ -1,9 +1,5 @@ import type { AddressType, DappAddress } from '../address/addresses.interface'; -import type { - NotificationConfig, - NotificationSubscription, - NotificationType, -} from '../wallet/wallet.interface'; +import type { NotificationConfig, NotificationSubscription, NotificationType } from '../wallet/wallet.interface'; import type { AccountAddress } from '../auth/auth.interface'; export interface Dapps { @@ -72,9 +68,9 @@ export interface FindDappQuery { blockchainType?: BlockchainType; } -export interface DappMessageTransaction { - transactionServiceId: string; - transactionParams: Record; + +export interface SmartMessageParams { // TODO: Just a marker interface for now?? + } export interface DappMessageAction { @@ -84,38 +80,53 @@ export interface DappMessageAction { export enum DappMessageActionType { LINK = 'Link', - SIGN_TRANSACTION = 'SignTransaction', + SMART_MESSAGE = 'SignTransaction', } -export interface DappMessageActionV2 { +interface DappMessageActionV2Base { type: DappMessageActionType; } -export interface DappMessageLinkAction extends DappMessageActionV2 { + +export interface DappMessageLinkAction extends DappMessageActionV2Base { type: DappMessageActionType.LINK; label: string; url: string; } -export interface DappMessageSignTransactionAction extends DappMessageActionV2 { - type: DappMessageActionType.SIGN_TRANSACTION; - transaction: DappMessageTransaction; +export interface SmartMessageAction extends DappMessageActionV2Base { + type: DappMessageActionType.SMART_MESSAGE; + smartMessage: SmartMessage; +} +export interface SmartMessage { + transactionServiceId: string; + transactionParams: SmartMessageParams; } + export interface SendDappMessageCommandBase { message: string; title?: string; notificationTypeId?: string; addressTypes?: AddressType[]; // tags?: string[]; - actions?: DappMessageAction[]; + actions?: DappMessageAction[]; // TODO: deprecate it, I think it's ok to intro breaking change since only tensor and our dashboard uses it atm } export type BroadcastDappMessageCommand = SendDappMessageCommandBase; +export type ActionsV3 = LinkOnlyActions | SmartMessageAction; + +export interface LinkOnlyActions { + actions: [DappMessageLinkAction]; + // actions: [DappMessageLinkAction]; // TODO: we can allow single action in compile time using this notation +} + + export interface UnicastDappMessageCommand extends SendDappMessageCommandBase { recipient: AccountAddress; - actionsV2: DappMessageActionV2[]; + // actionsV2: DappMessageActionV2[]; + actionsV3: ActionsV3; } export interface MulticastDappMessageCommand @@ -169,3 +180,4 @@ export class DappNotificationSubscription { notificationType!: NotificationType; subscriptions!: NotificationSubscription[]; } +