Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration with ADAMANT Notification Service #658

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,686 changes: 1,778 additions & 908 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"ed2curve": "^0.3.0",
"emoji-mart": "^5.5.2",
"file-saver": "^2.0.5",
"firebase": "^10.12.5",
"hdkey": "^2.1.0",
"https-browserify": "^1.0.0",
"i": "^0.3.7",
Expand Down Expand Up @@ -110,7 +111,8 @@
"web3-eth-accounts": "^4.1.1",
"web3-eth-contract": "^4.2.0",
"web3-providers-http": "^4.1.0",
"web3-utils": "^4.2.1"
"web3-utils": "^4.2.1",
"workbox-precaching": "^7.1.0"
},
"devDependencies": {
"@capacitor/assets": "^3.0.5",
Expand Down Expand Up @@ -162,7 +164,7 @@
"uuid": "^9.0.1",
"vite": "^5.1.6",
"vite-plugin-electron": "^0.28.4",
"vite-plugin-pwa": "^0.19.8",
"vite-plugin-pwa": "^0.20.1",
"vite-plugin-top-level-await": "^1.4.1",
"vite-plugin-wasm": "^3.3.0",
"vitest": "^1.4.0",
Expand Down
102 changes: 102 additions & 0 deletions public/adamant-api/asset.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adamant-api files should not be in /public dir. Did you accidentally copy them while resolving the conflicts? @NikIvv

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, the conflicts are still not resolved. Please fix it.

* AIP 12: Non-ADM crypto transfer messages
* @see https://aips.adamant.im/AIPS/aip-12
*/
export interface CryptoTransferAsset {
/**
* Represents token's network and looks like `tickerSymbol_transaction`,
* e.g. `eth_transaction`. Ticker symbol must be in lower case, but apps
* must process it in any case for backwards compatibility.
*/
type: string
/**
* Transferred value in tokens of its network. Decimal separator is `.`
*/
amount: string
/**
* Transaction id in token's network. Used to check transaction status
*/
hash: string
/**
* May include comment for this transfer, shown to both recipient and sender
*/
comments?: string
/**
* Can be added to show explanation text messages on client apps that doesn't
* support specified `type`
*/
text_fallback?: string
}

/**
* Reply to a message
*
* @see https://aips.adamant.im/AIPS/aip-16
*/
export interface ReplyMessageAsset {
/**
* ADM transaction ID of a message which a user replies to
*/
replyto_id: string
/**
* Text of a reply
*/
reply_message: string
}

/**
* Reply to a message with a crypto transfer
*
* @see https://aips.adamant.im/AIPS/aip-16
*/
export interface ReplyWithCryptoTransferAsset {
/**
* ADM transaction ID of a message which a user replies to
*/
replyto_id: string
/**
* Text of a reply
*/
reply_message: CryptoTransferAsset
}

interface CryptoTransferPayload {
cryptoSymbol: string
amount: string
hash: string
comments: string
}

export function cryptoTransferAsset(payload: CryptoTransferPayload): CryptoTransferAsset

interface ReplyMessagePayload {
replyToId: string
replyMessage: string
}

export function replyMessageAsset(payload: ReplyMessagePayload): ReplyMessageAsset

export function replyWithCryptoTransferAsset(
replyToId: string,
transferPayload: CryptoTransferPayload
): ReplyWithCryptoTransferAsset

export interface ReactionAsset {
/**
* ADM transaction ID of the message to which the user is reacting
*/
reactto_id: string
/**
* Represents the emoji-based reaction
*/
react_message: string
}

export function reactionAsset(reactToId: string, reactMessage: string): ReactionAsset

export function signalAsset(
deviceId: string,
token: string,
provider: 'APNS' | 'FCM',
action: 'add' | 'remove'
): SignalMessagePayload
46 changes: 46 additions & 0 deletions public/adamant-api/asset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { MessageType } from '@/lib/constants'

export function cryptoTransferAsset({ cryptoSymbol, amount, hash, comments, text_fallback }) {
const asset = {
type: MessageType.cryptoTransferMessage(cryptoSymbol),
amount,
hash,
comments
}

if (text_fallback) {
asset.text_fallback = text_fallback
}

return asset
}

export function replyMessageAsset({ replyToId, replyMessage }) {
return {
replyto_id: replyToId,
reply_message: replyMessage
}
}

export function replyWithCryptoTransferAsset(replyToId, transferPayload) {
return {
replyto_id: replyToId,
reply_message: cryptoTransferAsset(transferPayload)
}
}

export function reactionAsset(reactToId, reactMessage) {
return {
reactto_id: reactToId,
react_message: reactMessage
}
}

export function signalAsset(deviceId, token, provider, action) {
return {
deviceId,
token,
provider,
action
}
}
186 changes: 186 additions & 0 deletions public/adamant-api/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import { Store } from 'vuex'

import { Transactions } from '@/lib/constants'
import { CryptoSymbol } from '@/lib/constants/cryptos'
import {
AccountDto,
AnyTransaction,
BaseTransaction,
ChatMessageTransaction,
ChatsApiGetChatroomMessagesRequest,
ChatsApiGetChatRoomsRequest,
CreateNewChatMessageResponseDto,
GetAccountVotesResponseDto,
GetBlocksResponseDto,
GetDelegatesCountResponseDto,
GetDelegatesResponseDto,
GetDelegateStatsResponseDto,
GetNextForgersResponseDto,
GetTransactionsResponseDto,
GetUnconfirmedTransactionsResponseDto,
QueuedTransaction,
RegisterAnyTransaction,
RegisterChatMessageTransaction,
RegisterKVSTransaction,
RegisterNewDelegateTransaction,
RegisterTokenTransferTransaction,
RegisterVoteForDelegateTransaction,
SetKVSResponseDto,
TransactionsApiGetTransactionsRequest,
TransferTokenResponseDto
} from '@/lib/schema/client/api'
import { RootState } from '@/store/types'

export declare const TX_CHUNK_SIZE: number

export type UnsignedNewTransaction = Pick<
BaseTransaction,
'type' | 'amount' | 'senderId' | 'senderPublicKey'
>

export type RegisterChatMessageTransactionUnsigned = Omit<
RegisterChatMessageTransaction,
'signature' | 'timestamp'
>
export type RegisterTokenTransferTransactionUnsigned = Omit<
RegisterTokenTransferTransaction,
'signature' | 'timestamp'
>
export type RegisterKVSTransactionUnsigned = Omit<RegisterKVSTransaction, 'signature' | 'timestamp'>
export type RegisterVoteForDelegateTransactionUnsigned = Omit<
RegisterVoteForDelegateTransaction,
'signature' | 'timestamp'
>
export type RegisterNewDelegateTransactionUnsigned = Omit<
RegisterNewDelegateTransaction,
'signature' | 'timestamp'
>

export type RegisterAnyTransactionUnsigned =
| RegisterChatMessageTransactionUnsigned
| RegisterTokenTransferTransactionUnsigned
| RegisterKVSTransactionUnsigned
| RegisterVoteForDelegateTransactionUnsigned
| RegisterNewDelegateTransactionUnsigned

export function newTransaction(type: number): UnsignedNewTransaction

export function signTransaction(
transaction: RegisterAnyTransactionUnsigned,
timeDelta: number
): RegisterAnyTransaction

export function unlock(passphrase: string): string

export type CurrentAccount = Omit<AccountDto, 'balance' | 'unconfirmedBalance'> & {
balance: number // string balance was normalized into ADM units
unconfirmedBalance: number // string balance was normalized into ADM units
}
export function getCurrentAccount(): Promise<CurrentAccount>

export function isReady(): boolean

export function getPublicKey(address: string): Promise<string>

export type SendMessageParams = {
to: string // address
message?: string | object
type?: typeof Transactions.SEND | typeof Transactions.CHAT_MESSAGE
amount?: number
}
export function sendMessage(params: SendMessageParams): Promise<CreateNewChatMessageResponseDto>

export function sendSpecialMessage(
to: string,
message: SendMessageParams['message']
): ReturnType<typeof sendMessage>

export function storeValue(
key: string,
value: string | object,
encode?: boolean
): Promise<SetKVSResponseDto>

export function getStored(key: string, ownerAddress: string, records?: number): Promise<unknown>

export function sendTokens(to: string, amount: number): Promise<TransferTokenResponseDto>
export function getDelegates(limit: number, offset: number): Promise<GetDelegatesResponseDto>
export function getDelegatesWithVotes(address: string): Promise<GetAccountVotesResponseDto>
export function getDelegatesCount(): Promise<GetDelegatesCountResponseDto>
export function checkUnconfirmedTransactions(): Promise<GetUnconfirmedTransactionsResponseDto>

export function voteForDelegates(votes: string[]): Promise<RegisterVoteForDelegateTransaction>
export function getNextForgers(): Promise<GetNextForgersResponseDto>
export function getBlocks(): Promise<GetBlocksResponseDto>
export function getForgedByAccount(): Promise<GetDelegateStatsResponseDto>

export function storeCryptoAddress(crypto: CryptoSymbol, address: string): Promise<boolean>

type GetTransactionsOptions = Pick<
TransactionsApiGetTransactionsRequest,
'minAmount' | 'toHeight' | 'fromHeight' | 'type' | 'orderBy'
>
export function getTransactions(
options: GetTransactionsOptions
): Promise<GetTransactionsResponseDto>

export function getTransaction(
id: string,
returnAsset?: 0 | 1
): Promise<AnyTransaction | QueuedTransaction | null>

export function getChats(
from?: number,
offset?: number,
orderBy?: 'asc' | 'desc'
): Promise<{
count: number
transactions: Array<DecodedChatMessageTransaction>
}>

type DecodedChatMessageTransaction = ChatMessageTransaction & {
message: string | object
i18n: boolean
}

export function decodeChat(
transaction: ChatMessageTransaction,
key: string
): DecodedChatMessageTransaction

export function decodeTransaction(
transaction: AnyTransaction | QueuedTransaction,
address: string
): DecodedChatMessageTransaction

export function getI18nMessage(message: string, senderId: string): string

export function loginOrRegister(): Promise<ReturnType<typeof getCurrentAccount>>

export type CurrentAccountWithPassphrase = CurrentAccount & {
passphrase: string
}

export function loginViaPassword(
password: string,
store: Store<RootState>
): Promise<CurrentAccountWithPassphrase>

type GetChatRoomsParams = Pick<ChatsApiGetChatRoomsRequest, 'offset' | 'limit' | 'orderBy'>

export function getChatRooms(
address: string,
params: GetChatRoomsParams
): Promise<Array<ReturnType<typeof decodeChat>>>

type GetChatRoomMessagesParams = Pick<
ChatsApiGetChatroomMessagesRequest,
'offset' | 'limit' | 'orderBy'
>

export function getChatRoomMessages(
address1: string,
address2: string,
params: GetChatRoomMessagesParams,
recursive: boolean = false
): Promise<Array<ReturnType<typeof decodeChat>>>
Loading