Пример #1
0
def withdraw(user_asset: UserAddressAsset, request):
    """Ask user for the withdraw details."""

    title = "Withdraw"
    wallet = user_asset.wallet
    asset_resource = user_asset
    network_resource = get_network_resource(request, asset_resource.asset.network)
    balance = format_asset_amount(user_asset.balance, user_asset.asset.asset_class)
    address_resource = asset_resource.address
    account = user_asset.account

    schema = WithdrawSchema().bind(request=request, account=account)
    b = deform.Button(name='process', title="Verify with SMS", css_class="btn-block btn-lg")
    form = deform.Form(schema, buttons=(b,))

    # User submitted this form
    if request.method == "POST":
        if 'process' in request.POST:

            try:
                appstruct = form.validate(request.POST.items())

                # Save form data from appstruct
                amount = appstruct["amount"]
                address = eth_address_to_bin(appstruct["address"])
                note = appstruct["note"]
                confirmations = get_required_confirmation_count(request.registry, user_asset.account.asset.network, CryptoOperationType.withdraw)

                user_crypto_address = asset_resource.address.address

                # Create the withdraw
                user_withdraw = user_crypto_address.withdraw(asset_resource.asset, amount, address, note, confirmations)

                # Mark it as pending for confirmation
                UserWithdrawConfirmation.require_confirmation(user_withdraw)

                # Redirect user to the confirmation page
                user_crypto_operation_resource = get_user_crypto_operation_resource(request, user_withdraw)
                return HTTPFound(request.resource_url(user_crypto_operation_resource, "confirm-withdraw"))

            except deform.ValidationFailure as e:
                # Render a form version where errors are visible next to the fields,
                # and the submitted values are posted back
                rendered_form = e.render()
        else:
            # We don't know which control caused form submission
            raise HTTPInternalServerError("Unknown form button pressed")
    else:
        # Render a form with initial values
        rendered_form = form.render()

    return locals()
Пример #2
0
def withdraw(user_asset: UserAddressAsset, request):
    """Ask user for the withdraw details."""

    title = "Withdraw"
    wallet = user_asset.wallet
    asset_resource = user_asset
    network_resource = get_network_resource(request, asset_resource.asset.network)
    balance = format_asset_amount(user_asset.balance, user_asset.asset.asset_class)
    address_resource = asset_resource.address
    account = user_asset.account

    schema = WithdrawSchema().bind(request=request, account=account)
    withdraw = deform.Button(name='process', title="Verify with SMS", css_class="btn-primary btn-block btn-lg")
    cancel = deform.Button(name='cancel', title="Cancel", css_class="btn-primary btn-block btn-lg")
    form = deform.Form(schema, buttons=(withdraw, cancel), resource_registry=ResourceRegistry(request))

    # User submitted this form
    if request.method == "POST":
        if 'process' in request.POST:

            try:
                appstruct = form.validate(request.POST.items())

                # Save form data from appstruct
                amount = appstruct["amount"]
                address = eth_address_to_bin(appstruct["address"])
                note = appstruct["note"]
                confirmations = get_required_confirmation_count(request.registry, user_asset.account.asset.network, CryptoOperationType.withdraw)

                user_crypto_address = asset_resource.address.address

                # Create the withdraw
                user_withdraw = user_crypto_address.withdraw(asset_resource.asset, amount, address, note, confirmations)

                # Ethereum special parameters
                user_withdraw.crypto_operation.other_data["gas"] = appstruct["advanced"]["gas"]
                data = appstruct["advanced"]["data"]
                if data:
                    user_withdraw.crypto_operation.other_data["data"] = data

                # Mark it as pending for confirmation
                UserWithdrawConfirmation.require_confirmation(user_withdraw)

                # Redirect user to the confirmation page
                user_crypto_operation_resource = get_user_crypto_operation_resource(request, user_withdraw)
                return HTTPFound(request.resource_url(user_crypto_operation_resource, "confirm-withdraw"))

            except deform.ValidationFailure as e:
                # Render a form version where errors are visible next to the fields,
                # and the submitted values are posted back
                rendered_form = e.render()
        elif "cancel" in request.POST:
            return HTTPFound(request.resource_url(wallet))
        else:
            # We don't know which control caused form submission
            raise HTTPInternalServerError("Unknown form button pressed")
    else:
        # Render a form with initial values
        rendered_form = form.render()

    # This loads widgets specific CSS/JavaScript in HTML code,
    # if form widgets specify any static assets.
    form.resource_registry.pull_in_resources(request, form)

    return locals()
Пример #3
0
 def manual_confirmation(self):
     return UserWithdrawConfirmation.get_pending_confirmation(self.context.uop)
Пример #4
0
 def manual_confirmation(self):
     return UserWithdrawConfirmation.get_pending_confirmation(self.context.uop)