Skip to content

Bunch of updates for new Converter UI #143

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

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c17894c
added token and blockchain logo to the response data
sassless Oct 17, 2024
77c4610
reworked get conversion history methods, added blockchain, token and …
sassless Oct 18, 2024
b55e8f2
added order parameter for get conversion history request
sassless Oct 18, 2024
b15a7ed
Merge pull request #141 from singnet/history-upgrade
sassless Oct 18, 2024
40d56d5
hide UserWarning - MismatchedABI
kiruxaspb Nov 7, 2024
fd83cca
Merge pull request #142 from singnet/hide-logs-warnings
kiruxaspb Nov 7, 2024
49706b1
Merge branch 'master' into development
kiruxaspb Nov 7, 2024
5a1a01a
added new conversion/transaction statuses for bad conversions refund
sassless Jan 16, 2025
04af7db
added trading view entity linked to the token; new db revision: added…
sassless Jan 16, 2025
3403735
workpiece of trading view data on requests for conversion and history
sassless Jan 16, 2025
6b5c8db
sync python version in .circleci with serverless
sassless Jan 16, 2025
28b125c
fixed other places with old python version in .circleci config.yml
sassless Jan 16, 2025
335e4f6
Merge pull request #144 from singnet/new_fe_updates
sassless Jan 17, 2025
287177d
added token name to token pairs response
sassless Jan 17, 2025
f3815e8
Merge pull request #145 from singnet/new_fe_updates
sassless Jan 17, 2025
6cf14f5
added ada amount validation on token received event
sassless Jan 28, 2025
bff467e
added CANCELED status for conversion transaction
sassless Jan 28, 2025
2f56e07
Merge pull request #146 from singnet/ada_check
sassless Jan 29, 2025
091d221
Add token field in response for /token/pair endpoint
mabredin Apr 7, 2025
35511b9
undefined token fix for get token pair endpoint with conversion fee t…
sassless Apr 8, 2025
dad9f3f
Merge pull request #147 from singnet/SB-10
sassless Apr 8, 2025
a0509a2
Update sonar-project.properties
BANGLADESH228 Apr 27, 2025
2205291
Create sonar.yml
BANGLADESH228 Apr 27, 2025
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
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/python:3.7-node
- image: circleci/python:3.8-node
- image: circleci/mysql:8.0.21
command: [--default-authentication-plugin=mysql_native_password]
environment:
Expand All @@ -20,12 +20,12 @@ jobs:
command: |
shasum requirement*.txt > /tmp/checksum_files_list
sudo chown -R circleci:circleci /usr/local/bin
sudo chown circleci:circleci -R /usr/local/lib/python3.7
sudo chown circleci:circleci -R /usr/local/lib/python3.8
- run:
name: Revert the permissions
command: |
sudo chown root:root -R /usr/local/bin
sudo chown root:root -R /usr/local/lib/python3.7
sudo chown root:root -R /usr/local/lib/python3.8
- run:
# Our primary container isn't MYSQL so run a sleep command until it's ready.
name: Waiting for MySQL to be ready
Expand Down Expand Up @@ -68,4 +68,4 @@ jobs:
- save_cache:
key: dependency-cache-{{ checksum "/tmp/checksum_files_list" }}
paths:
- /usr/local/lib/python3.7/site-packages
- /usr/local/lib/python3.8/site-packages
23 changes: 23 additions & 0 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Sonar Analysis Workflow

on:
push:
branches:
- master
- development
pull_request:
types: [opened, synchronize, reopened]

jobs:
build:
name: Build and analyze
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- uses: SonarSource/sonarqube-scan-action@v4
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
41 changes: 41 additions & 0 deletions alembic/versions/e6dfb71c97ce_added_trading_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""added_trading_view

Revision ID: e6dfb71c97ce
Revises: 19c20537fdbb
Create Date: 2025-01-16 20:47:52.983186

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'e6dfb71c97ce'
down_revision = '19c20537fdbb'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('trading_view',
sa.Column('row_id', sa.BIGINT(), autoincrement=True, nullable=False),
sa.Column('id', sa.VARCHAR(length=50), nullable=False),
sa.Column('symbol', sa.VARCHAR(length=250), nullable=True),
sa.Column('alt_text', sa.TEXT(), nullable=True),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.Column('updated_at', sa.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
sa.PrimaryKeyConstraint('row_id'),
sa.UniqueConstraint('id')
)
op.add_column('token', sa.Column('trading_view_id', sa.BIGINT(), nullable=True))
op.create_foreign_key(None, 'token', 'trading_view', ['trading_view_id'], ['row_id'])
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'token', type_='foreignkey')
op.drop_column('token', 'trading_view_id')
op.drop_table('trading_view')
# ### end Alembic commands ###
28 changes: 28 additions & 0 deletions alembic/versions/f75df319b335_added_ada_thershold.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""added_ada_thershold

Revision ID: f75df319b335
Revises: e6dfb71c97ce
Create Date: 2025-01-28 14:44:37.728102

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'f75df319b335'
down_revision = 'e6dfb71c97ce'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('token_pair', sa.Column('ada_threshold', sa.BIGINT(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('token_pair', 'ada_threshold')
# ### end Alembic commands ###
25 changes: 20 additions & 5 deletions application/handler/conversion_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from web3 import Web3
from http import HTTPStatus

from constants.general import MAX_PAGE_SIZE
from constants.general import MAX_PAGE_SIZE, ConversionHistoryOrder
from constants.api_parameters import ApiParameters
from constants.lambdas import HttpRequestParamType, LambdaResponseStatus, PaginationDefaults
from constants.error_details import ErrorCode, ErrorDetails
Expand Down Expand Up @@ -98,7 +98,14 @@ def get_conversion_history(event, context):
schema_key="GetConversionHistoryInput", input_json=event)

query_param = get_valid_value(event, HttpRequestParamType.REQUEST_PARAM_QUERY_STRING.value)
address = query_param.get(ApiParameters.ADDRESS.value, None)
address = query_param.get(ApiParameters.ADDRESS.value)
blockchain_name = query_param.get(ApiParameters.BLOCKCHAIN_NAME.value)
token_symbol = query_param.get(ApiParameters.TOKEN_SYMBOL.value)
conversion_status = query_param.get(ApiParameters.CONVERSION_STATUS.value)
try:
history_order = ConversionHistoryOrder(query_param.get(ApiParameters.ORDER_BY.value).upper())
except (AttributeError, ValueError):
history_order = ConversionHistoryOrder.DEFAULT

if not address:
raise BadRequestException(error_code=ErrorCode.PROPERTY_VALUES_EMPTY.value,
Expand All @@ -115,11 +122,19 @@ def get_conversion_history(event, context):
raise BadRequestException(error_code=ErrorCode.PAGE_SIZE_EXCEEDS_LIMIT.value,
error_details=ErrorDetails[ErrorCode.PAGE_SIZE_EXCEEDS_LIMIT.value].value)

response = conversion_service.get_conversion_history(address=address, page_size=page_size, page_number=page_number)
response = conversion_service.get_conversion_history(address=address,
blockchain_name=blockchain_name,
token_symbol=token_symbol,
conversion_status=conversion_status,
order=history_order,
page_size=page_size,
page_number=page_number)

return generate_lambda_response(HTTPStatus.OK.value,
make_response_body(status=LambdaResponseStatus.SUCCESS.value, data=response,
error=make_error_format()), cors_enabled=True)
make_response_body(status=LambdaResponseStatus.SUCCESS.value,
data=response,
error=make_error_format()),
cors_enabled=True)


@exception_handler(EXCEPTIONS=EXCEPTIONS, SLACK_HOOK=SLACK_HOOK, logger=logger)
Expand Down
19 changes: 16 additions & 3 deletions application/service/consumer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
generate_deposit_address_details_for_cardano_operation, \
validate_conversion_request_amount, validate_consumer_event_type, convert_str_to_decimal, \
get_current_block_confirmation, wait_until_transaction_hash_exists_in_blockchain, \
validate_tx_hash_presence_in_blockchain
validate_tx_hash_presence_in_blockchain, validate_tx_token_received_ada_amount
from utils.exception_handler import bridge_exception_handler
from utils.exceptions import BadRequestException, InternalServerErrorException, BlockConfirmationNotEnoughException

Expand Down Expand Up @@ -134,7 +134,8 @@ def process_event_consumer(self, event_type, tx_hash, network_id, blockchain_eve
elif db_blockchain_name == BlockchainName.CARDANO.value.lower():
if event_type == CardanoEventType.TOKEN_RECEIVED.value:
conversion = self.process_cardano_token_received_event(blockchain_event=blockchain_event,
transaction=transaction)
transaction=transaction,
network_id=network_id)
elif transaction and event_type in CardanoServicesEventTypes:
conversion = self.conversion_service.get_conversion_detail_by_tx_id(
tx_id=transaction.get(TransactionEntities.ID.value))
Expand Down Expand Up @@ -273,7 +274,7 @@ def process_evm_event(self, event_type, tx_hash, tx_amount, conversion_id, trans

return conversion

def process_cardano_token_received_event(self, blockchain_event, transaction):
def process_cardano_token_received_event(self, blockchain_event, transaction, network_id):
created_by = CreatedBy.BACKEND.value
fee_amount = Decimal(0)
tx_hash = blockchain_event.get(CardanoEventConsumer.TX_HASH.value)
Expand Down Expand Up @@ -307,6 +308,12 @@ def process_cardano_token_received_event(self, blockchain_event, transaction):
min_value=token_pair.get(TokenPairEntities.MIN_VALUE.value),
max_value=token_pair.get(TokenPairEntities.MAX_VALUE.value))

target_amount = token_pair.get(TokenPairEntities.ADA_THRESHOLD.value)
validate_tx_token_received_ada_amount(target_amount=target_amount,
address=deposit_address,
tx_hash=tx_hash,
network_id=network_id)

token_address = token_pair.get(TokenPairEntities.FROM_TOKEN.value, {}) \
.get(TokenEntities.TOKEN_ADDRESS.value)
token_symbol = token_pair.get(TokenPairEntities.FROM_TOKEN.value, {}).get(TokenEntities.SYMBOL.value)
Expand Down Expand Up @@ -396,6 +403,12 @@ def process_cardano_token_received_event(self, blockchain_event, transaction):
min_value=token_pair.get(TokenPairEntities.MIN_VALUE.value),
max_value=token_pair.get(TokenPairEntities.MAX_VALUE.value))

target_amount = token_pair.get(TokenPairEntities.ADA_THRESHOLD.value)
validate_tx_token_received_ada_amount(target_amount=target_amount,
address=deposit_address,
tx_hash=tx_hash,
network_id=network_id)

token_address = token_pair.get(TokenPairEntities.FROM_TOKEN.value, {}) \
.get(TokenEntities.TOKEN_ADDRESS.value)
token_symbol = token_pair.get(TokenPairEntities.FROM_TOKEN.value, {}).get(TokenEntities.SYMBOL.value)
Expand Down
33 changes: 33 additions & 0 deletions application/service/conversion_fee_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from application.service.blockchain_response import get_blockchain_for_token_response
from constants.entity import ConversionFeeEntities, TokenEntities


def get_conversion_fee_response(conversion_fee):
if not len(conversion_fee):
return conversion_fee

return {
ConversionFeeEntities.ID.value: conversion_fee[ConversionFeeEntities.ID.value],
ConversionFeeEntities.PERCENTAGE_FROM_SOURCE.value:
conversion_fee[ConversionFeeEntities.PERCENTAGE_FROM_SOURCE.value],
ConversionFeeEntities.TOKEN.value:
get_short_token_response(conversion_fee[ConversionFeeEntities.TOKEN.value]),
ConversionFeeEntities.UPDATED_AT.value: conversion_fee[ConversionFeeEntities.UPDATED_AT.value]
}


def get_short_token_response(token):
if not len(token):
return token

return {
TokenEntities.ID.value: token[TokenEntities.ID.value],
TokenEntities.NAME.value: token[TokenEntities.NAME.value],
TokenEntities.SYMBOL.value: token[TokenEntities.SYMBOL.value],
TokenEntities.LOGO.value: token[TokenEntities.LOGO.value],
TokenEntities.ALLOWED_DECIMAL.value: token[TokenEntities.ALLOWED_DECIMAL.value],
TokenEntities.TOKEN_ADDRESS.value: token[TokenEntities.TOKEN_ADDRESS.value],
TokenEntities.CONTRACT_ADDRESS.value: token[TokenEntities.CONTRACT_ADDRESS.value],
TokenEntities.UPDATED_AT.value: token[TokenEntities.UPDATED_AT.value],
TokenEntities.BLOCKCHAIN.value: get_blockchain_for_token_response(token[TokenEntities.BLOCKCHAIN.value])
}
13 changes: 0 additions & 13 deletions application/service/conversion_fee_respose.py

This file was deleted.

9 changes: 7 additions & 2 deletions application/service/conversion_response.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from constants.entity import ConversionEntities, TokenPairEntities, WalletPairEntities, ConversionDetailEntities, TokenEntities, \
BlockchainEntities, TransactionEntities, TransactionConversionEntities, SignatureMetadataEntities
from application.service.token_response import get_trading_view_response


def conversion_response(conversion):
Expand Down Expand Up @@ -75,6 +76,7 @@ def get_blockchain_response(blockchain):
return {
BlockchainEntities.NAME.value: blockchain[BlockchainEntities.NAME.value],
BlockchainEntities.SYMBOL.value: blockchain[BlockchainEntities.SYMBOL.value],
BlockchainEntities.LOGO.value: blockchain[BlockchainEntities.LOGO.value],
BlockchainEntities.CHAIN_ID.value: blockchain[BlockchainEntities.CHAIN_ID.value]
}

Expand All @@ -83,8 +85,10 @@ def get_token_response(token):
return {
TokenEntities.NAME.value: token[TokenEntities.NAME.value],
TokenEntities.SYMBOL.value: token[TokenEntities.SYMBOL.value],
TokenEntities.LOGO.value: token[TokenEntities.LOGO.value],
TokenEntities.ALLOWED_DECIMAL.value: token[TokenEntities.ALLOWED_DECIMAL.value],
TokenEntities.BLOCKCHAIN.value: get_blockchain_response(token[TokenEntities.BLOCKCHAIN.value])
TokenEntities.BLOCKCHAIN.value: get_blockchain_response(token[TokenEntities.BLOCKCHAIN.value]),
# TokenEntities.TRADING_VIEW.value: get_trading_view_response(token[TokenEntities.TRADING_VIEW.value])
}


Expand All @@ -93,7 +97,8 @@ def get_token_internal_response(token):
TokenEntities.ROW_ID.value: token[TokenEntities.ROW_ID.value],
TokenEntities.NAME.value: token[TokenEntities.NAME.value],
TokenEntities.SYMBOL.value: token[TokenEntities.SYMBOL.value],
TokenEntities.BLOCKCHAIN.value: get_blockchain_response(token[TokenEntities.BLOCKCHAIN.value])
TokenEntities.BLOCKCHAIN.value: get_blockchain_response(token[TokenEntities.BLOCKCHAIN.value]),
# TokenEntities.TRADING_VIEW.value: get_trading_view_response(token[TokenEntities.TRADING_VIEW.value])
}


Expand Down
32 changes: 24 additions & 8 deletions application/service/conversion_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
ConversionEntities, TokenEntities, BlockchainEntities, ConversionDetailEntities, TransactionConversionEntities, \
TransactionEntities, ConversionFeeEntities, ConverterBridgeEntities, EventConsumerEntity, TokenLiquidityEntities
from constants.error_details import ErrorCode, ErrorDetails
from constants.general import BlockchainName, CreatedBy, SignatureTypeEntities, ConversionOn
from constants.general import BlockchainName, CreatedBy, SignatureTypeEntities, ConversionOn, ConversionHistoryOrder
from constants.status import ConversionStatus, TransactionVisibility, TransactionStatus
from constants.lambdas import PaginationDefaults
from infrastructure.repositories.conversion_repository import ConversionRepository
from utils.blockchain import validate_address, validate_conversion_claim_request_signature, \
validate_conversion_request_amount, convert_str_to_decimal, get_next_activity_event_on_conversion, \
Expand Down Expand Up @@ -441,23 +442,38 @@ def get_token_contract_address_for_conversion_id(self, conversion_on, conversion
error_code=ErrorCode.INVALID_CONVERSION_DIRECTION.value,
error_details=ErrorDetails[ErrorCode.INVALID_CONVERSION_DIRECTION.value].value)

def get_conversion_history(self, address, page_size, page_number):
logger.info(f"Getting the conversion history for the given address={address}, page_size={page_size}, "
f"page_number={page_number}")
total_conversion_history = self.conversion_repo.get_conversion_history_count(address=address)
def get_conversion_history(self, address, blockchain_name, token_symbol, conversion_status,
order=ConversionHistoryOrder.DEFAULT,
page_size=PaginationDefaults.PAGE_SIZE.value,
page_number=PaginationDefaults.PAGE_NUMBER.value):
logger.info(f"Getting the conversion history for the given address={address}, "
f"blockchain={blockchain_name}, token={token_symbol}, status={conversion_status}, "
f"order={order.value}, page_size={page_size}, page_number={page_number}")
total_conversion_history = self.conversion_repo.get_conversion_history_count(
address=address,
blockchain_name=blockchain_name,
token_symbol=token_symbol,
conversion_status=conversion_status
)
offset = get_offset(page_number=page_number, page_size=page_size)

if total_conversion_history and total_conversion_history > offset:
conversion_history_obj = self.conversion_repo.get_conversion_history(address=address, conversion_id=None,
offset=offset, limit=page_size)
conversion_history_obj = self.conversion_repo.get_conversion_history(address=address,
blockchain_name=blockchain_name,
token_symbol=token_symbol,
conversion_status=conversion_status,
order=order,
offset=offset,
limit=page_size)
conversion_history = get_response_from_entities(conversion_history_obj)
conversion_detail_history_response = get_conversion_history_response(conversion_history)
else:
conversion_detail_history_response = []

return paginate_items_response_format(items=conversion_detail_history_response,
total_records=total_conversion_history,
page_number=page_number, page_size=page_size)
page_number=page_number,
page_size=page_size)

@staticmethod
def get_conversion_row_ids(conversion_details):
Expand Down
Loading
Loading